r7061: initial property settings
[kmrcl.git] / processes.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: modlisp -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          processes.lisp
6 ;;;; Purpose:       Multiprocessing functions
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  June 2003
9 ;;;;
10 ;;;; $Id$
11 ;;;; *************************************************************************
12
13 (in-package #:kmrcl)
14
15
16 (defun make-process (name func)
17   #+allegro (mp:process-run-function name func)
18   #+cmu (mp:make-process func :name name)
19   #+lispworks (mp:process-run-function name nil func)
20   #+sb-thread (sb-thread:make-thread func)
21   #-(or allegro cmu lispworks sb-thread) (funcall func)
22   )
23
24 (defun destroy-process (process)
25   #+cmu (mp:destroy-process process)
26   #+allegro (mp:process-kill process)
27   #+sb-thread (sb-thread:destroy-thread process)
28   #+lispworks (mp:process-kill process)
29   )
30
31 (defun make-lock (name)
32   #+allegro (mp:make-process-lock :name name)
33   #+cmu (mp:make-lock name)
34   #+lispworks (mp:make-lock :name name)
35   #+sbcl-thread (sb-thread:make-mutex :name name)
36   )
37
38 (defmacro with-lock-held ((lock) &body body)
39   #+allegro
40   `(mp:with-process-lock (,lock) ,@body)
41   #+cmu
42   `(mp:with-lock-held (,lock) ,@body)
43   #+lispworks
44   `(mp:with-lock (,lock) ,@body)
45   #+sbcl-thread
46   `(sb-thread:with-recursive-lock (,lock) ,@body)
47   #-(or allegro cmu lispworks sbcl-thread)
48   `(progn ,@body)
49   )
50
51
52 (defmacro with-timeout ((seconds) &body body)
53   #+allegro
54   `(mp:with-timeout (,seconds) ,@body)
55   #+cmu
56   `(mp:with-timeout (,seconds) ,@body)
57   #+sbcl-thread
58   `(sb-ext:with-timeout ,seconds ,@body)
59   #-(or allegro cmu sbcl-thread)
60   `(progn ,@body)
61   )
62   
63 (defun process-sleep (n)
64   #+allegro (mp:process-sleep n)
65   #-allegro (sleep n))
66