1 ;;;; -*- indent-tabs-mode: nil -*-
3 (in-package :bordeaux-threads-2
)
9 (deftype native-thread
()
12 (defun %make-thread
(function name
)
13 (mt:make-thread function
:name name
))
15 (defun %current-thread
()
18 (defun %thread-name
(thread)
19 (mt:thread-name thread
))
21 (defun %join-thread
(thread)
22 (mt:thread-join thread
))
24 (defun %thread-yield
()
28 ;;; Introspection/debugging
31 ;;; VTZ: mt:list-threads returns all threads that are not garbage collected.
32 (defun %all-threads
()
33 (delete-if-not #'mt
:thread-active-p
(mt:list-threads
)))
35 (defun %interrupt-thread
(thread function
)
36 (mt:thread-interrupt thread
:function function
))
38 (defun %destroy-thread
(thread)
39 (mt:thread-interrupt thread
:function t
))
41 (defun %thread-alive-p
(thread)
42 (mt:thread-active-p thread
))
46 ;;; Non-recursive locks
49 (deftype native-lock
()
52 (defun %make-lock
(name)
53 (mt:make-mutex
:name name
))
55 (mark-not-implemented 'acquire-lock
:timeout
)
56 (defun %acquire-lock
(lock waitp timeout
)
58 (signal-not-implemented 'acquire-lock
:timeout
))
59 (mt:mutex-lock lock
:timeout
(if waitp nil
0)))
61 (defun %release-lock
(lock)
62 (mt:mutex-unlock 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 `(mt:with-mutex-lock
(,place
) ,@body
)))
74 (deftype native-recursive-lock
()
75 '(and mt
:mutex
(satisfies mt
:mutex-recursive-p
)))
77 (defun %make-recursive-lock
(name)
78 (mt:make-mutex
:name name
:recursive-p t
))
80 (mark-not-implemented 'acquire-recursive-lock
:timeout
)
81 (defun %acquire-recursive-lock
(lock waitp timeout
)
83 (signal-not-implemented 'acquire-recursive-lock
:timeout
))
84 (%acquire-lock lock waitp nil
))
86 (defun %release-recursive-lock
(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 `(mt:with-mutex-lock
(,place
) ,@body
)))
97 ;;; Condition variables
100 (deftype condition-variable
()
103 (defun %make-condition-variable
(name)
104 (mt:make-exemption
:name name
))
106 (defun %condition-wait
(cv lock timeout
)
107 (mt:exemption-wait cv lock
:timeout timeout
))
109 (defun %condition-notify
(cv)
110 (mt:exemption-signal cv
))
112 (defun %condition-broadcast
(cv)
113 (mt:exemption-broadcast cv
))
120 (defmacro with-timeout
((timeout) &body body
)
122 `(mt:with-timeout
(,timeout
(error 'timeout
:length
,timeout
))