Allegro: force minimum timeout for WAIT-ON-SEMAPHORE
[bordeaux-threads.git] / apiv2 / impl-clasp.lisp
blob602276b32d1dd9563451669a142bc4f15712e73c
1 ;;;; -*- indent-tabs-mode: nil -*-
3 (in-package :bordeaux-threads-2)
5 ;;;
6 ;;; Threads
7 ;;;
9 (deftype native-thread ()
10 'mp:process)
12 (defun %make-thread (function name)
13 (mp:process-run-function name function))
15 (defun current-thread ()
16 mp:*current-process*)
18 (defun %thread-name (thread)
19 (mp:process-name thread))
21 (defun %join-thread (thread)
22 (mp:process-join thread))
24 (defun %thread-yield ()
25 (mp:process-yield))
27 ;;;
28 ;;; Introspection/debugging
29 ;;;
31 (defun %all-threads ()
32 (mp:all-processes))
34 (defun %interrupt-thread (thread function)
35 (mp:interrupt-process thread function))
37 (defun %destroy-thread (thread)
38 (mp:process-kill thread))
40 (defun %thread-alive-p (thread)
41 (mp:process-active-p thread))
44 ;;;
45 ;;; Non-recursive locks
46 ;;;
48 (deftype native-lock () 'mp:mutex)
50 (defun %make-lock (name)
51 (mp:make-lock :name name))
53 (mark-not-implemented 'acquire-lock :timeout)
54 (defun %acquire-lock (lock waitp timeout)
55 (when timeout
56 (signal-not-implemented 'acquire-lock :timeout))
57 (mp:get-lock lock waitp))
59 (defun %release-lock (lock)
60 (mp:giveup-lock lock))
62 (mark-not-implemented 'with-lock-held :timeout)
63 (defmacro %with-lock ((place timeout) &body body)
64 (if timeout
65 `(signal-not-implemented 'with-lock-held :timeout)
66 `(mp:with-lock (,place) ,@body)))
68 ;;;
69 ;;; Recursive locks
70 ;;;
72 (deftype native-recursive-lock ()
73 '(and mp:mutex (satisfies mp:recursive-lock-p)))
75 (defun %make-recursive-lock (name)
76 (mp:make-recursive-mutex name))
78 (mark-not-implemented 'acquire-recursive-lock :timeout)
79 (defun %acquire-recursive-lock (lock waitp timeout)
80 (when timeout
81 (signal-not-implemented 'acquire-recursive-lock :timeout))
82 (mp:get-lock lock waitp))
84 (defun %release-recursive-lock (lock)
85 (mp:giveup-lock lock))
87 (mark-not-implemented 'with-recursive-lock-held :timeout)
88 (defmacro %with-recursive-lock ((place timeout) &body body)
89 (if timeout
90 `(signal-not-implemented 'with-recursive-lock-held :timeout)
91 `(mp:with-lock (,place) ,@body)))
94 ;;;
95 ;;; Condition variables
96 ;;;
98 (deftype condition-variable ()
99 'mp:condition-variable)
101 (defun %make-condition-variable (name)
102 (declare (ignore name))
103 (mp:make-condition-variable))
105 (defun %condition-wait (cv lock timeout)
106 (if timeout
107 (mp:condition-variable-timedwait cv lock timeout)
108 (mp:condition-variable-wait cv lock)))
110 (defun %condition-notify (cv)
111 (mp:condition-variable-signal cv))
113 (defun %condition-broadcast (cv)
114 (mp:condition-variable-broadcast cv))