condition-variables.lisp - clic - Clic is an command line interactive client for gopher written in Common LISP (HTM) git clone git://bitreich.org/clic/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/clic/ (DIR) Log (DIR) Files (DIR) Refs (DIR) Tags (DIR) README (DIR) LICENSE --- condition-variables.lisp (1053B) --- 1 ;;;; -*- indent-tabs-mode: nil -*- 2 3 #| 4 Copyright 2006, 2007 Greg Pfeil 5 6 Distributed under the MIT license (see LICENSE file) 7 |# 8 9 (in-package #:bordeaux-threads) 10 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. 15 16 (defstruct condition-var 17 name 18 lock 19 active) 20 21 (defun condition-wait (condition-variable lock &key timeout) 22 (signal-error-if-condition-wait-timeout timeout) 23 (check-type condition-variable condition-var) 24 (setf (condition-var-active condition-variable) nil) 25 (release-lock lock) 26 (do () 27 ((when (condition-var-active condition-variable) 28 (acquire-lock lock) 29 t)) 30 (thread-yield)) 31 t) 32 33 (define-condition-wait-compiler-macro) 34 35 (defun condition-notify (condition-variable) 36 (check-type condition-variable condition-var) 37 (with-lock-held ((condition-var-lock condition-variable)) 38 (setf (condition-var-active condition-variable) t)))