Add INITIAL-BINDINGS keyword argument to MAKE-THREAD.
[bordeaux-threads.git] / src / condition-variables.lisp
blobc7ae250c57967445a766b197cf48cc80321219f2
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 ;;; This file provides a portable implementation of condition
12 ;;; variables (given a working WITH-LOCK-HELD and THREAD-YIELD), and
13 ;;; should be used if there is no condition variable implementation in
14 ;;; the host Lisp.
16 (defstruct condition-var
17 lock
18 active)
20 (defun condition-wait (condition-variable lock)
21 (check-type condition-variable condition-var)
22 (setf (condition-var-active condition-variable) nil)
23 (release-lock lock)
24 (do ()
25 ((when (condition-var-active condition-variable)
26 (acquire-lock lock)
27 t))
28 (thread-yield)))
30 (defun condition-notify (condition-variable)
31 (check-type condition-variable condition-var)
32 (with-lock-held ((condition-var-lock condition-variable))
33 (setf (condition-var-active condition-variable) t)))