Finished conversion from methods to functions with defaults (Stelian Ionescu <sionesc...
[bordeaux-threads.git] / src / armedbear.lisp
blobb4770433ed19483f97ad339433dee94565831204
1 #|
2 Copyright 2006, 2007 Greg Pfeil
4 Distributed under the MIT license (see LICENSE file)
5 |#
7 (in-package #:bordeaux-threads)
9 ;;; the implementation of the Armed Bear thread interface can be found in
10 ;;; src/org/armedbearlisp/LispThread.java
12 ;;; Thread Creation
14 (defun make-thread (function &key name)
15 (ext:make-thread function :name name))
17 (defun current-thread ()
18 (ext:current-thread))
20 (defun thread-name (thread)
21 (ext:thread-name thread))
23 ;;; Yes, this is nasty
24 (defun threadp (object)
25 (handler-case (progn (thread-name object) t)
26 (type-error () nil)))
28 ;;; Resource contention: locks and recursive locks
30 ;;; Don't know what the arguments to MAKE-THREAD-LOCK are, but it
31 ;;; doesn't mind being a thunk
32 (defun make-lock (&optional name)
33 (declare (ignore name))
34 (ext:make-thread-lock))
36 (defun acquire-lock (lock &optional (wait-p t))
37 (declare (ignore wait-p))
38 (ext:thread-lock lock))
40 (defun release-lock (lock)
41 (ext:thread-unlock lock))
43 (defmacro with-lock-held ((place) &body body)
44 `(ext:with-thread-lock (,place) ,@body))
46 ;;; Resource contention: condition variables
48 (defun thread-yield ()
49 (sleep 0))
51 ;;; Introspection/debugging
53 (defun interrupt-thread (thread function)
54 (ext:interrupt-thread thread function))
56 (defun destroy-thread (thread)
57 (signal-error-if-current-thread thread)
58 (ext:destroy-thread thread))
60 (defun thread-alive-p (thread)
61 (ext:thread-alive-p thread))
63 (mark-supported)