Added threads check for ECL (Stelian Ionescu <sionescu@common-lisp.net>)
[bordeaux-threads:bordeaux-threads.git] / src / ecl.lisp
1 #|
2 Copyright 2006, 2007 Greg Pfeil
3
4 Distributed under the MIT license (see LICENSE file)
5 |#
6
7 (in-package #:bordeaux-threads)
8
9 ;;; documentation on the ECL Multiprocessing interface can be found at
10 ;;; http://ecls.sourceforge.net/cgi-bin/view/Main/MultiProcessing
11
12 ;;; Thread Creation
13
14 (defun make-thread (function &key name)
15   (mp:process-run-function (or name "") function))
16
17 (defmethod current-thread ()
18   mp::*current-process*)
19
20 (defmethod threadp ((object mp:process))
21   t)
22
23 (defmethod thread-name ((thread mp:process))
24   (mp:process-name thread))
25
26 ;;; Resource contention: locks and recursive locks
27
28 (defun make-lock (&optional name)
29   (mp:make-lock :name name))
30
31 (defmethod acquire-lock ((lock mp:lock) &optional (wait-p t))
32   (mp:get-lock lock wait-p))
33
34 (defmethod release-lock ((lock mp:lock))
35   (mp:giveup-lock lock))
36
37 (defmacro with-lock-held ((place) &body body)
38   `(mp:with-lock (,place) ,@body))
39
40 ;; make-recursive-lock
41 ;; acquire-recursive-lock
42 ;; release-recursive-lock
43
44 ;;; Resource contention: condition variables
45
46 (defun thread-yield ()
47   ;; (mp:yield)
48   (sleep 0))
49
50 ;;; Introspection/debugging
51
52 (defmethod all-threads ()
53   (mp:all-processes))
54
55 (defmethod interrupt-thread ((thread mp:process) function)
56   (mp:interrupt-process thread function))
57
58 (defmethod destroy-thread ((thread mp:process))
59   (mp:process-kill thread))
60
61 (defmethod thread-alive-p ((thread mp:process))
62   (mp:process-active-p thread))
63
64 (mark-supported)