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