1 ;;;; -*- indent-tabs-mode: nil -*-
3 (in-package :bordeaux-threads-2
)
9 (deftype native-thread
()
12 (defun %make-thread
(function name
)
13 (thread:thread-create function
:name name
))
15 (defun %current-thread
()
18 (defun %thread-name
(thread)
19 (thread:thread-name thread
))
21 (defun %join-thread
(thread)
22 (mp:process-wait
(format nil
"Waiting for thread ~A to complete" thread
)
23 (named-lambda %thread-completed-p
()
24 (not (mp:process-alive-p thread
)))))
26 (defun %thread-yield
()
30 ;;; Introspection/debugging
33 (defun %all-threads
()
36 (defun %interrupt-thread
(thread function
)
37 (thread:thread-interrupt thread function
))
39 (defun %destroy-thread
(thread)
40 (thread:destroy-thread thread
))
42 (defun %thread-alive-p
(thread)
43 (mp:process-alive-p thread
))
47 ;;; Non-recursive locks
50 (deftype native-lock
() 'thread
:lock
)
52 (defun %make-lock
(name)
53 (thread:make-lock name
))
55 (mark-not-implemented 'acquire-lock
:timeout
)
56 (defun %acquire-lock
(lock waitp timeout
)
58 (signal-not-implemented 'acquire-lock
:timeout
))
59 (thread::acquire-lock lock nil wait-p
))
61 (defun %release-lock
(lock)
62 (thread::release-lock lock
))
64 (mark-not-implemented 'with-lock-held
:timeout
)
65 (defmacro %with-lock
((place timeout
) &body body
)
67 `(signal-not-implemented 'with-lock-held
:timeout
)
68 `(thread:with-lock-held
(,place
) ,@body
)))
74 (deftype native-recursive-lock
() 'thread
:recursive-lock
)
76 (defun %make-recursive-lock
(name)
77 (thread:make-lock name
:type
:recursive
))
79 (mark-not-implemented 'acquire-recursive-lock
)
80 (defun %acquire-recursive-lock
(lock waitp timeout
)
81 (declare (ignore lock waitp timeout
))
82 (signal-not-implemented 'acquire-recursive-lock
))
84 (mark-not-implemented 'release-recursive-lock
)
85 (defun %release-recursive-lock
(lock)
86 (declare (ignore lock
))
87 (signal-not-implemented 'release-recursive-lock
))
89 (mark-not-implemented 'with-recursive-lock-held
:timeout
)
90 (defmacro %with-recursive-lock
((place timeout
) &body body
)
92 `(signal-not-implemented 'with-recursive-lock-held
:timeout
)
93 `(thread:with-lock-held
(,place
)
98 ;;; Condition variables
101 (deftype condition-variable
()
104 (defun %make-condition-variable
(name)
105 (thread:make-cond-var name
))
107 (defun %condition-wait
(cv lock timeout
)
109 (thread:cond-var-timedwait cv lock timeout
)
110 (thread:cond-var-wait cv lock
)))
112 (defun %condition-notify
(cv)
113 (thread:cond-var-signal cv
))
115 (defun %condition-broadcast
(cv)
116 (thread:cond-var-broadcast v
))