-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclos.lisp
39 lines (31 loc) · 1.18 KB
/
clos.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(defclass lock ()
((name :initarg :name :reader lock-name))
(:documentation "The foundation of all locks."))
(defclass simple-lock (lock)
((owner :initform nil :accessor lock-owner))
(:documentation "A lock that is either free or busy."))
(defclass null-lock (lock)
()
(:documentation "A lock that is always free."))
(defun make-null-lock (name)
(make-instance 'null-lock :name name))
(defun make-simple-lock (name)
(make-instance 'simple-lock :name name))
(defgeneric seize (lock)
(:documentation
"Seizes the lock.
Returns the lock when the operation succeeds.
Some locks simply wait until they can succeed, while
other locks return NIL if they fail."))
(defgeneric release (lock &optional failure-mode)
(:documentation
"Releases the lock if it is currently owned y this process.
Retunrs T if the operation succeeds.
If unsuccessful and failure-mode is :no-error, returns NIL.
If unsuccessful and failure-mode is :error, signals an error.
The default for failure-mode is :no-error."))
(defmethod seize ((l null-lock))
l) ; return lock, no waiting
(defmethod release ((l null-lock) &optional failure-mode)
(declare (ignore failure-mode)) ; never fails for null
t)