Untabify bordeaux-threads-test.lisp
[bordeaux-threads.git] / src / impl-clozure.lisp
blob9955b706023f60e35c2a21acc197981fb9faa2a2
1 ;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 #|
4 Copyright 2006, 2007 Greg Pfeil
6 Distributed under the MIT license (see LICENSE file)
7 |#
9 (in-package #:bordeaux-threads)
11 ;;; documentation on the OpenMCL Threads interface can be found at
12 ;;; http://openmcl.clozure.com/Doc/Programming-with-Threads.html
14 ;;; Thread Creation
16 (defun %make-thread (function name)
17 (ccl:process-run-function name function))
19 (defun current-thread ()
20 ccl:*current-process*)
22 (defun threadp (object)
23 (typep object 'ccl:process))
25 (defun thread-name (thread)
26 (ccl:process-name thread))
28 ;;; Resource contention: locks and recursive locks
30 (defun make-lock (&optional name)
31 (ccl:make-lock (or name "Anonymous lock")))
33 (defun acquire-lock (lock &optional (wait-p t))
34 (if wait-p
35 (ccl:grab-lock lock)
36 (ccl:try-lock lock)))
38 (defun release-lock (lock)
39 (ccl:release-lock lock))
41 (defmacro with-lock-held ((place) &body body)
42 `(ccl:with-lock-grabbed (,place)
43 ,@body))
45 (defun make-recursive-lock (&optional name)
46 (ccl:make-lock (or name "Anonymous recursive lock")))
48 (defun acquire-recursive-lock (lock)
49 (ccl:grab-lock lock))
51 (defun release-recursive-lock (lock)
52 (ccl:release-lock lock))
54 (defmacro with-recursive-lock-held ((place) &body body)
55 `(ccl:with-lock-grabbed (,place)
56 ,@body))
58 ;;; Resource contention: condition variables
60 (defun make-condition-variable (&key name)
61 (declare (ignore name))
62 (ccl:make-semaphore))
64 (defun condition-wait (condition-variable lock)
65 (unwind-protect
66 (progn
67 (release-lock lock)
68 (ccl:wait-on-semaphore condition-variable))
69 (acquire-lock lock t)))
71 (defun condition-notify (condition-variable)
72 (ccl:signal-semaphore condition-variable))
74 (defun thread-yield ()
75 (ccl:process-allow-schedule))
77 ;;; Introspection/debugging
79 (defun all-threads ()
80 (ccl:all-processes))
82 (defun interrupt-thread (thread function)
83 (ccl:process-interrupt thread function))
85 (defun destroy-thread (thread)
86 (signal-error-if-current-thread thread)
87 (ccl:process-kill thread))
89 (defun thread-alive-p (thread)
90 (ccl::process-active-p thread))
92 (defun join-thread (thread)
93 (ccl:join-process thread))
95 (mark-supported)