Finished conversion from methods to functions with defaults (Stelian Ionescu <sionesc...
[bordeaux-threads.git] / src / allegro.lisp
blob33899e9d1eb47314d41693d3a9cca50926206434
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 Allegro Multiprocessing interface can be found at
10 ;;; http://www.franz.com/support/documentation/8.1/doc/multiprocessing.htm
12 ;;; Thread Creation
14 (defun make-thread (function &key name)
15 (mp:process-run-function name function))
17 (defun current-thread ()
18 mp:*current-process*)
20 (defun threadp (object)
21 (typep object 'mp:process))
23 (defun thread-name (thread)
24 (mp:process-name thread))
26 ;;; Resource contention: locks and recursive locks
28 (defun make-lock (&optional name)
29 (mp:make-process-lock :name name))
31 (defun acquire-lock (lock &optional (wait-p t))
32 (mp:process-lock lock mp:*current-process* "Lock" (if wait-p nil 0)))
34 (defun release-lock (lock)
35 (mp:process-unlock lock))
37 (defmacro with-lock-held ((place) &body body)
38 `(mp:with-process-lock (,place :norecursive t)
39 ,@body))
41 (defmacro with-recursive-lock-held ((place &key timeout) &body body)
42 `(mp:with-process-lock (,place :timeout ,timeout)
43 ,@body))
45 ;;; Resource contention: condition variables
47 (defun make-condition-variable ()
48 (mp:make-gate nil))
50 (defun condition-wait (condition-variable lock)
51 (release-lock lock)
52 (mp:process-wait "wait for message" #'mp:gate-open-p condition-variable)
53 (acquire-lock lock)
54 (mp:close-gate condition-variable))
56 (defun condition-notify (condition-variable)
57 (mp:open-gate condition-variable))
59 (defun thread-yield ()
60 (mp:process-allow-schedule))
62 ;;; Introspection/debugging
64 (defun all-threads ()
65 mp:*all-processes*)
67 (defun interrupt-thread (thread function)
68 (mp:process-interrupt thread function))
70 (defun destroy-thread (thread)
71 (signal-error-if-current-thread thread)
72 (mp:process-kill thread))
74 (defun thread-alive-p (thread)
75 (mp:process-alive-p thread))
77 (mark-supported)