Finished conversion from methods to functions with defaults (Stelian Ionescu <sionesc...
[bordeaux-threads.git] / src / lispworks.lisp
blobefb8be6227a7dda3172266b3906698526754b7fa
1 #|
2 Copyright 2006, 2007 Greg Pfeil
4 Distributed under the MIT license (see LICENSE file)
5 |#
7 (in-package #:bordeaux-threads)
9 ;;; documentation on the LispWorks Multiprocessing interface can be found at
10 ;;; http://www.lispworks.com/documentation/lw445/LWUG/html/lwuser-156.htm
12 (mp:initialize-multiprocessing)
14 ;;; Thread Creation
16 (defun make-thread (function &key name)
17 (mp:process-run-function name nil function))
19 (defun current-thread ()
20 mp:*current-process*)
22 (defun threadp (object)
23 (typep object 'mp:process))
25 (defun thread-name (thread)
26 (mp:process-name thread))
28 ;;; Resource contention: locks and recursive locks
30 (defun make-lock (&optional name)
31 (mp:make-lock :name name))
33 (defun acquire-lock (lock &optional (wait-p t))
34 (mp:process-lock lock nil (if wait-p
35 (if (typep wait-p 'number) wait-p nil)
36 0)))
38 (defun release-lock (lock)
39 (mp:process-unlock lock))
41 ;;; Apparently this EVAL-WHEN is needed so that the macro is available
42 ;;; when compiling condition-variables.lisp
43 (eval-when (:compile-toplevel :load-toplevel :execute)
44 (defmacro with-lock-held ((place) &body body)
45 `(mp:with-lock (,place) ,@body)))
47 ;;; Resource contention: condition variables
49 (defun thread-yield ()
50 (mp:process-allow-scheduling))
52 ;;; Introspection/debugging
54 (defun all-threads ()
55 (mp:list-all-processes))
57 (defun interrupt-thread (thread function)
58 (mp:process-interrupt thread function))
60 (defun destroy-thread (thread)
61 (signal-error-if-current-thread thread)
62 (mp:process-kill thread))
64 (defun thread-alive-p (thread)
65 (mp:process-alive-p thread))
67 (mark-supported)