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 (sb-thread:join-thread thread
))
24 (defun %thread-yield
()
25 (sb-thread:thread-yield
))
28 ;;; Introspection/debugging
31 (defun %all-threads
()
32 (sb-thread:list-all-threads
))
34 (defun %interrupt-thread
(thread function
)
35 (sb-thread:interrupt-thread thread function
))
37 (defun %destroy-thread
(thread)
38 (sb-thread:terminate-thread thread
))
40 (defun %thread-alive-p
(thread)
41 (sb-thread:thread-alive-p thread
))
45 ;;; Non-recursive locks
48 (deftype native-lock
()
51 (defun %make-lock
(name)
52 (sb-thread:make-mutex
:name name
))
54 (defun %acquire-lock
(lock waitp timeout
)
55 (sb-thread:grab-mutex lock
:waitp waitp
:timeout timeout
))
57 (defun %release-lock
(lock)
58 (sb-thread:release-mutex lock
))
60 (defmacro %with-lock
((place timeout
) &body body
)
61 `(sb-thread:with-mutex
(,place
:timeout
,timeout
) ,@body
))
67 (deftype native-recursive-lock
() 'sb-thread
:mutex
)
69 (defun %make-recursive-lock
(name)
70 (sb-thread:make-mutex
:name name
))
72 (mark-not-implemented 'acquire-recursive-lock
)
73 (defun %acquire-recursive-lock
(lock waitp timeout
)
74 (declare (ignore lock waitp timeout
))
75 (signal-not-implemented 'acquire-recursive-lock
))
77 (mark-not-implemented 'release-recursive-lock
)
78 (defun %release-recursive-lock
(lock)
79 (declare (ignore lock
))
80 (signal-not-implemented 'release-recursive-lock
))
82 (defmacro %with-recursive-lock
((place timeout
) &body body
)
83 `(sb-thread:with-recursive-lock
(,place
:timeout
,timeout
)
94 (defun %make-semaphore
(name count
)
95 (sb-thread:make-semaphore
:name name
:count count
))
97 (defun %signal-semaphore
(semaphore count
)
98 (sb-thread:signal-semaphore semaphore count
))
100 (defun %wait-on-semaphore
(semaphore timeout
)
102 ((and timeout
(zerop timeout
))
103 (sb-thread:try-semaphore semaphore
))
105 (if (sb-thread:wait-on-semaphore semaphore
:timeout timeout
)
110 ;;; Condition variables
113 (defun %make-condition-variable
(name)
114 (sb-thread:make-waitqueue
:name name
))
116 (defun %condition-wait
(cv lock timeout
)
118 (sb-thread:condition-wait cv lock
:timeout timeout
)))
120 (%acquire-lock lock t nil
))
123 (defun %condition-notify
(cv)
124 (sb-thread:condition-notify cv
))
126 (defun %condition-broadcast
(cv)
127 (sb-thread:condition-broadcast cv
))
134 (defmacro with-timeout
((timeout) &body body
)
135 `(sb-ext:with-timeout
,timeout
138 (bt2::mark-supported
)