Add INITIAL-BINDINGS keyword argument to MAKE-THREAD.
[bordeaux-threads.git] / src / scl.lisp
blobd9d4d231fdac56b7d77057a73fe2a6096d0e8281
1 ;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 #|
4 Copyright 2008 Scieneer Pty Ltd
6 Distributed under the MIT license (see LICENSE file)
7 |#
9 (in-package #:bordeaux-threads)
11 (defun %make-thread (function name)
12 (thread:thread-create function :name name))
14 (defun current-thread ()
15 thread:*thread*)
17 (defun threadp (object)
18 (typep object 'thread:thread))
20 (defun thread-name (thread)
21 (thread:thread-name thread))
23 (defun make-lock (&optional name)
24 (thread:make-lock name))
26 (defun acquire-lock (lock &optional (wait-p t))
27 (thread::acquire-lock lock nil wait-p))
29 (defun release-lock (lock)
30 (thread::release-lock lock))
32 (defmacro with-lock-held ((place) &body body)
33 `(thread:with-lock-held (,place) ,@body))
35 (defun make-recursive-lock (&optional name)
36 (thread:make-lock name :type :recursive))
38 ;;; XXX acquire-recursive-lock and release-recursive-lock are actually
39 ;;; complicated because we can't use control stack tricks. We need to
40 ;;; actually count something to check that the acquire/releases are
41 ;;; balanced
43 (defmacro with-recursive-lock-held ((place) &body body)
44 `(thread:with-lock-held (,place)
45 ,@body))
47 ;;; Resource contention: condition variables
49 (defun make-condition-variable ()
50 (thread:make-cond-var))
52 (defun condition-wait (condition-variable lock)
53 (thread:cond-var-wait condition-variable lock))
55 (defun condition-notify (condition-variable)
56 (thread:cond-var-broadcast condition-variable))
58 (defun thread-yield ()
59 (mp:process-yield))
61 ;;; Timeouts
63 (defmacro with-timeout ((timeout) &body body)
64 `(error "with-timeout is not reliable and should not be used."))
66 ;;; Introspection/debugging
68 (defun all-threads ()
69 (mp:all-processes))
71 (defun interrupt-thread (thread function)
72 (thread:thread-interrupt thread function))
74 (defun destroy-thread (thread)
75 (thread:destroy-thread thread))
77 (defun thread-alive-p (thread)
78 (mp:process-alive-p thread))
80 (defun join-thread (thread)
81 (error "Join-thread not implemented."))
83 (mark-supported)