Untabify bordeaux-threads-test.lisp
[bordeaux-threads.git] / src / condition-variables.lisp
blob26cb9e31e970c8702c3274d29a767356dbe260f8
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 name
18 lock
19 active)
21 (defun condition-wait (condition-variable lock)
22 (check-type condition-variable condition-var)
23 (setf (condition-var-active condition-variable) nil)
24 (release-lock lock)
25 (do ()
26 ((when (condition-var-active condition-variable)
27 (acquire-lock lock)
28 t))
29 (thread-yield)))
31 (defun condition-notify (condition-variable)
32 (check-type condition-variable condition-var)
33 (with-lock-held ((condition-var-lock condition-variable))
34 (setf (condition-var-active condition-variable) t)))