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 ;;; documentation on the LispWorks Multiprocessing interface can be found at
12 ;;; http://www.lispworks.com/documentation/lw445/LWUG/html/lwuser-156.htm
14 (mp:initialize-multiprocessing
)
18 (defun %make-thread
(function name
)
19 (mp:process-run-function name nil function
))
21 (defun current-thread ()
24 (defun threadp (object)
25 (typep object
'mp
:process
))
27 (defun thread-name (thread)
28 (mp:process-name thread
))
30 ;;; Resource contention: locks and recursive locks
32 (defun make-lock (&optional name
)
33 (mp:make-lock
:name name
))
35 (defun acquire-lock (lock &optional
(wait-p t
))
36 (mp:process-lock lock nil
(if wait-p
37 (if (typep wait-p
'number
) wait-p nil
)
40 (defun release-lock (lock)
41 (mp:process-unlock lock
))
43 ;;; Apparently this EVAL-WHEN is needed so that the macro is available
44 ;;; when compiling condition-variables.lisp
45 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
46 (defmacro with-lock-held
((place) &body body
)
47 `(mp:with-lock
(,place
) ,@body
)))
49 ;;; Resource contention: condition variables
51 (defun thread-yield ()
52 (mp:process-allow-scheduling
))
54 ;;; Introspection/debugging
57 (mp:list-all-processes
))
59 (defun interrupt-thread (thread function
)
60 (mp:process-interrupt thread function
))
62 (defun destroy-thread (thread)
63 (signal-error-if-current-thread thread
)
64 (mp:process-kill thread
))
66 (defun thread-alive-p (thread)
67 (mp:process-alive-p thread
))