1 ;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
4 Copyright
2006, 2007 Greg Pfeil
6 Distributed under the MIT license
(see LICENSE file
)
9 (in-package #:bordeaux-threads
)
11 ;;; the implementation of the Armed Bear thread interface can be found in
12 ;;; src/org/armedbear/lisp/LispThread.java
16 (defun %make-thread
(function name
)
17 (ext:make-thread function
:name name
))
19 (defun current-thread ()
22 (defun thread-name (thread)
23 (ext:thread-name thread
))
25 ;;; Yes, this is nasty
26 (defun threadp (object)
27 (handler-case (progn (thread-name object
) t
)
30 ;;; Resource contention: locks and recursive locks
32 ;;; Don't know what the arguments to MAKE-THREAD-LOCK are, but it
33 ;;; doesn't mind being a thunk
34 (defun make-lock (&optional name
)
35 (declare (ignore name
))
36 (ext:make-thread-lock
))
38 (defun acquire-lock (lock &optional
(wait-p t
))
39 (declare (ignore wait-p
))
40 (ext:thread-lock lock
))
42 (defun release-lock (lock)
43 (ext:thread-unlock lock
))
45 (defmacro with-lock-held
((place) &body body
)
46 `(ext:with-thread-lock
(,place
) ,@body
))
48 ;;; Resource contention: condition variables
50 (defun thread-yield ()
53 ;;; Introspection/debugging
55 (defun interrupt-thread (thread function
)
56 (ext:interrupt-thread thread function
))
58 (defun destroy-thread (thread)
59 (signal-error-if-current-thread thread
)
60 (ext:destroy-thread thread
))
62 (defun thread-alive-p (thread)
63 (ext:thread-alive-p thread
))