Clarify docs of INTERRUPT-THREAD
[bordeaux-threads.git] / apiv1 / impl-mcl.lisp
blobd8e83cf6659552c413c5a752409f55380460e17e
1 ;;;; -*- 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 (deftype thread ()
12 'ccl::process)
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 (ccl::processp object))
25 (defun thread-name (thread)
26 (ccl:process-name thread))
28 ;;; Resource contention: locks and recursive locks
30 (deftype lock () 'ccl:lock)
32 (defun lock-p (object)
33 (typep object 'ccl:lock))
35 (defun make-lock (&optional name)
36 (ccl:make-lock (or name "Anonymous lock")))
38 (defun acquire-lock (lock &optional (wait-p t))
39 (if wait-p
40 (ccl:process-lock lock ccl:*current-process*)
41 ;; this is broken, but it's better than a no-op
42 (ccl:without-interrupts
43 (when (null (ccl::lock.value lock))
44 (ccl:process-lock lock ccl:*current-process*)))))
46 (defun release-lock (lock)
47 (ccl:process-unlock lock))
49 (defmacro with-lock-held ((place) &body body)
50 `(ccl:with-lock-grabbed (,place) ,@body))
52 (defun thread-yield ()
53 (ccl:process-allow-schedule))
55 ;;; Introspection/debugging
57 (defun all-threads ()
58 ccl:*all-processes*)
60 (defun interrupt-thread (thread function &rest args)
61 (declare (dynamic-extent args))
62 (apply #'ccl:process-interrupt thread function args))
64 (defun destroy-thread (thread)
65 (signal-error-if-current-thread thread)
66 (ccl:process-kill thread))
68 (mark-supported)