1 ;;;; -*- indent-tabs-mode: nil -*-
3 (in-package :bordeaux-threads-2
)
9 (deftype native-thread
()
12 (defun %make-thread
(function name
)
13 (ccl:process-run-function name function
))
15 (defun %current-thread
()
16 ccl
:*current-process
*)
18 (defun %thread-name
(thread)
19 (ccl:process-name thread
))
21 (defun %join-thread
(thread)
22 (ccl:join-process thread
))
24 (defun %thread-yield
()
25 (ccl:process-allow-schedule
))
28 ;;; Introspection/debugging
31 (defun %all-threads
()
34 (defun %interrupt-thread
(thread function
)
35 (ccl:process-interrupt thread function
))
37 (defun %destroy-thread
(thread)
38 (ccl:process-kill thread
))
40 (defun %thread-alive-p
(thread)
41 (not (ccl:process-exhausted-p thread
)))
45 ;;; Non-recursive locks
48 (deftype native-lock
() 'ccl
:lock
)
50 (defun %make-lock
(name)
53 (mark-not-implemented 'acquire-lock
:timeout
)
54 (defun %acquire-lock
(lock waitp timeout
)
56 (signal-not-implemented 'acquire-lock
:timeout
))
57 ;; This is not guaranteed to work all the times, but that's OK.
58 (when (eql (ccl::%%lock-owner lock
) (%current-thread
))
59 (bt-error "Attempted recursive acquisition of lock: ~A" lock
))
64 (defun %release-lock
(lock)
65 (ccl:release-lock lock
))
67 (mark-not-implemented 'with-lock-held
:timeout
)
68 (defmacro %with-lock
((place timeout
) &body body
)
69 (declare (ignorable place timeout
))
71 `(signal-not-implemented 'with-lock-held
:timeout
)
72 `(ccl:with-lock-grabbed
(,place
)
79 (deftype native-recursive-lock
() 'ccl
:lock
)
81 (defun %make-recursive-lock
(name)
84 (mark-not-implemented 'acquire-recursive-lock
:timeout
)
85 (defun %acquire-recursive-lock
(lock waitp timeout
)
87 (signal-not-implemented 'acquire-recursive-lock
:timeout
))
92 (defun %release-recursive-lock
(lock)
93 (ccl:release-lock lock
))
95 (mark-not-implemented 'with-recursive-lock-held
:timeout
)
96 (defmacro %with-recursive-lock
((place timeout
) &body body
)
97 (declare (ignorable place timeout
))
99 `(signal-not-implemented 'with-recursive-lock-held
:timeout
)
100 `(ccl:with-lock-grabbed
(,place
)
108 (deftype semaphore
() 'ccl
:semaphore
)
110 (defun %make-semaphore
(name count
)
111 (declare (ignore name
))
112 (ccl:make-semaphore
:count count
))
114 (defun %signal-semaphore
(semaphore count
)
115 (dotimes (c count
) (ccl:signal-semaphore semaphore
)))
117 (defun %wait-on-semaphore
(semaphore timeout
)
119 (ccl:timed-wait-on-semaphore semaphore timeout
)
120 (ccl:wait-on-semaphore semaphore
)))
124 ;;; Condition variables
127 ;;; Clozure doesn't have native condition variables.
128 ;;; We'll use the implementation in
129 ;;; impl-condition-variables-semaphores.lisp