1 ;;;; -*- indent-tabs-mode: nil -*-
3 (in-package :bordeaux-threads-2
)
9 (deftype native-thread
()
12 (defun %make-thread
(function name
)
13 (sb-thread:make-thread function
:name name
))
15 (defun %current-thread
()
16 sb-thread
:*current-thread
*)
18 (defun %thread-name
(thread)
19 (sb-thread:thread-name thread
))
21 (defun %join-thread
(thread)
22 (ignore-some-conditions (sb-thread:join-thread-error
)
23 (sb-thread:join-thread thread
)))
25 (defun %thread-yield
()
26 (sb-thread:thread-yield
))
29 ;;; Introspection/debugging
32 (defun %all-threads
()
33 (sb-thread:list-all-threads
))
35 (defun %interrupt-thread
(thread function
)
36 (sb-thread:interrupt-thread thread function
))
38 (defun %destroy-thread
(thread)
39 (sb-thread:terminate-thread thread
))
41 (defun %thread-alive-p
(thread)
42 (sb-thread:thread-alive-p thread
))
46 ;;; Non-recursive locks
49 (deftype native-lock
()
52 (defun %make-lock
(name)
53 (sb-thread:make-mutex
:name name
))
55 (defun %acquire-lock
(lock waitp timeout
)
56 (sb-thread:grab-mutex lock
:waitp waitp
:timeout timeout
))
58 (defun %release-lock
(lock)
59 (sb-thread:release-mutex lock
))
61 (defmacro %with-lock
((place timeout
) &body body
)
62 `(sb-thread:with-mutex
(,place
:timeout
,timeout
) ,@body
))
68 (deftype native-recursive-lock
()
71 (defun %make-recursive-lock
(name)
72 (sb-thread:make-mutex
:name name
))
74 (mark-not-implemented 'acquire-recursive-lock
)
75 (defun %acquire-recursive-lock
(lock waitp timeout
)
76 (declare (ignore lock waitp timeout
))
77 (signal-not-implemented 'acquire-recursive-lock
))
79 (mark-not-implemented 'release-recursive-lock
)
80 (defun %release-recursive-lock
(lock)
81 (declare (ignore lock
))
82 (signal-not-implemented 'release-recursive-lock
))
84 (defmacro %with-recursive-lock
((place timeout
) &body body
)
85 `(sb-thread:with-recursive-lock
(,place
:timeout
,timeout
)
96 (defun %make-semaphore
(name count
)
97 (sb-thread:make-semaphore
:name name
:count count
))
99 (defun %signal-semaphore
(semaphore count
)
100 (sb-thread:signal-semaphore semaphore count
))
102 (defun %wait-on-semaphore
(semaphore timeout
)
104 ((and timeout
(zerop timeout
))
105 (sb-thread:try-semaphore semaphore
))
107 (if (sb-thread:wait-on-semaphore semaphore
:timeout timeout
)
112 ;;; Condition variables
115 (deftype condition-variable
()
116 'sb-thread
:waitqueue
)
118 (defun %make-condition-variable
(name)
119 (sb-thread:make-waitqueue
:name name
))
121 (defun %condition-wait
(cv lock timeout
)
123 (sb-thread:condition-wait cv lock
:timeout timeout
)))
125 (%acquire-lock lock t nil
))
128 (defun %condition-notify
(cv)
129 (sb-thread:condition-notify cv
))
131 (defun %condition-broadcast
(cv)
132 (sb-thread:condition-broadcast cv
))
139 (defmacro with-timeout
((timeout) &body body
)
140 `(sb-ext:with-timeout
,timeout