1 ;;;; -*- indent-tabs-mode: nil -*-
3 (in-package :bordeaux-threads-2
)
9 (deftype native-thread
()
12 (defun %make-thread
(function name
)
13 (mp:process-run-function name function
))
15 (defun %current-thread
()
18 (defun %thread-name
(thread)
19 (mp:process-name thread
))
21 (defun %join-thread
(thread)
22 (mp:process-join thread
))
24 (defun %thread-yield
()
28 ;;; Introspection/debugging
31 (defun %all-threads
()
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
))
45 ;;; Non-recursive locks
48 (deftype native-lock
() 'mp
:lock
)
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
)
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
)
65 `(signal-not-implemented 'with-lock-held
:timeout
)
66 `(mp:with-lock
(,place
) ,@body
)))
72 (deftype native-recursive-lock
()
73 '(and mp
:lock
(satisfies mp
:recursive-lock-p
)))
75 (defun %make-recursive-lock
(name)
76 (mp:make-lock
:name name
:recursive t
))
78 (mark-not-implemented 'acquire-recursive-lock
:timeout
)
79 (defun %acquire-recursive-lock
(lock waitp 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
)
90 `(signal-not-implemented 'with-recursive-lock-held
:timeout
)
91 `(mp:with-lock
(,place
) ,@body
)))
98 (deftype semaphore
() 'mp
:semaphore
)
100 (defun %make-semaphore
(name count
)
101 (mp:make-semaphore
:name name
:count count
))
103 (defun %signal-semaphore
(semaphore count
)
104 (mp:signal-semaphore semaphore count
))
106 (defun %wait-on-semaphore
(semaphore timeout
)
109 (mp:wait-on-semaphore semaphore
)
113 (with-timeout (timeout)
114 (mp:wait-on-semaphore semaphore
)
118 (if (mp:try-get-semaphore semaphore
) t nil
))))
122 ;;; Condition variables
125 (defun %make-condition-variable
( name
)
126 (declare (ignore name
))
127 (mp:make-condition-variable
))
129 (defun %condition-wait
(cv lock timeout
)
132 (with-timeout (timeout)
133 (mp:condition-variable-wait cv lock
))
135 (mp:condition-variable-wait cv lock
)))
137 (defun %condition-notify
(cv)
138 (mp:condition-variable-signal cv
))
140 (defun %condition-broadcast
(cv)
141 (mp:condition-variable-broadcast cv
))
143 (bt2::mark-supported
)