1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
7 ;;;; This file is part of CLSQL.
9 ;;;; CLSQL users are granted the rights to distribute and use this software
10 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
11 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
12 ;;;; *************************************************************************
14 (in-package #:clsql-oracle
)
16 (defparameter *foreign-resource-hash
* (make-hash-table :test
#'equal
))
18 (defstruct (foreign-resource)
19 (type (error "Missing TYPE.")
21 (sizeof (error "Missing SIZEOF.")
23 (buffer (error "Missing BUFFER.")
25 (in-use nil
:type boolean
))
28 (defun %get-resource
(type sizeof
)
29 (let ((resources (gethash type
*foreign-resource-hash
*)))
32 (and (= (foreign-resource-sizeof res
) sizeof
)
33 (not (foreign-resource-in-use res
))))
36 (defun %insert-foreign-resource
(type res
)
37 (let ((resource (gethash type
*foreign-resource-hash
*)))
38 (setf (gethash type
*foreign-resource-hash
*)
39 (cons res resource
))))
41 (defmacro acquire-foreign-resource
(type &optional size
)
42 `(let ((res (%get-resource
,type
,size
)))
44 (setf res
(make-foreign-resource
45 :type
,type
:sizeof
,size
46 :buffer
(uffi:allocate-foreign-object
,type
,size
)))
47 (%insert-foreign-resource
',type res
))
48 (claim-foreign-resource res
)))
50 (defun free-foreign-resource (ares)
51 (setf (foreign-resource-in-use ares
) nil
)
54 (defun claim-foreign-resource (ares)
55 (setf (foreign-resource-in-use ares
) t
)