Newer
Older
;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
Greg Pfeil
committed
Copyright 2006, 2007 Greg Pfeil
Distributed under the MIT license (see LICENSE file)
|#
(in-package #:bordeaux-threads)
;;; documentation on the OpenMCL Threads interface can be found at
;;; http://openmcl.clozure.com/Doc/Programming-with-Threads.html
(defun %make-thread (function name)
Stelian Ionescu
committed
(ccl:process-run-function name function))
Greg Pfeil
committed
(defun current-thread ()
Greg Pfeil
committed
(defun threadp (object)
(typep object 'ccl:process))
Greg Pfeil
committed
(defun thread-name (thread)
(ccl:process-name thread))
;;; Resource contention: locks and recursive locks
(defun make-lock (&optional name)
Greg Pfeil
committed
(defun acquire-lock (lock &optional (wait-p t))
(if wait-p
(ccl:grab-lock lock)
(ccl:try-lock lock)))
Greg Pfeil
committed
(defun release-lock (lock)
(ccl:release-lock lock))
(defmacro with-lock-held ((place) &body body)
`(ccl:with-lock-grabbed (,place)
,@body))
(defun make-recursive-lock (&optional name)
(ccl:make-lock (or name "Anonymous recursive lock")))
Greg Pfeil
committed
(defun acquire-recursive-lock (lock)
Greg Pfeil
committed
(defun release-recursive-lock (lock)
(ccl:release-lock lock))
(defmacro with-recursive-lock-held ((place) &body body)
`(ccl:with-lock-grabbed (,place)
,@body))
;;; Resource contention: condition variables
(defun make-condition-variable (&key name)
(declare (ignore name))
Greg Pfeil
committed
(defun condition-wait (condition-variable lock)
(ccl:wait-on-semaphore condition-variable)
Greg Pfeil
committed
(defun condition-notify (condition-variable)
(ccl:signal-semaphore condition-variable))
(defun thread-yield ()
(ccl:process-allow-schedule))
;;; Introspection/debugging
Greg Pfeil
committed
(defun all-threads ()
Stelian Ionescu
committed
(defun interrupt-thread (thread function &rest args)
James Anderson
committed
(declare (dynamic-extent args))
Stelian Ionescu
committed
(apply #'ccl:process-interrupt thread function args))
Greg Pfeil
committed
(defun destroy-thread (thread)
(signal-error-if-current-thread thread)
Greg Pfeil
committed
(defun thread-alive-p (thread)
(defun join-thread (thread)
(ccl:join-process thread))