Add deprecation warnings to APIv1
[bordeaux-threads.git] / apiv2 / impl-clisp.lisp
blobd9a9c177982b957d5eaa9183d7243dd71a937bf7
1 ;;;; -*- indent-tabs-mode: nil -*-
3 (in-package :bordeaux-threads-2)
5 ;;;
6 ;;; Threads
7 ;;;
9 (deftype native-thread ()
10 'mt:thread)
12 (defun %make-thread (function name)
13 (mt:make-thread function :name name))
15 (defun %current-thread ()
16 (mt: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 ()
25 (mt:thread-yield))
27 ;;;
28 ;;; Introspection/debugging
29 ;;;
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))
45 ;;;
46 ;;; Non-recursive locks
47 ;;;
49 (deftype native-lock ()
50 'mt:mutex)
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)
57 (when 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)
66 (if timeout
67 `(signal-not-implemented 'with-lock-held :timeout)
68 `(mt:with-mutex-lock (,place) ,@body)))
70 ;;;
71 ;;; Recursive locks
72 ;;;
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)
82 (when timeout
83 (signal-not-implemented 'acquire-recursive-lock :timeout))
84 (%acquire-lock lock waitp nil))
86 (defun %release-recursive-lock (lock)
87 (%release-lock lock))
89 (mark-not-implemented 'with-recursive-lock-held :timeout)
90 (defmacro %with-recursive-lock ((place timeout) &body body)
91 (if timeout
92 `(signal-not-implemented 'with-recursive-lock-held :timeout)
93 `(mt:with-mutex-lock (,place) ,@body)))
96 ;;;
97 ;;; Condition variables
98 ;;;
100 (deftype condition-variable ()
101 'mt:exemption)
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))
117 ;;; Timeouts
120 (defmacro with-timeout ((timeout) &body body)
121 (once-only (timeout)
122 `(mt:with-timeout (,timeout (error 'timeout :length ,timeout))
123 ,@body)))