-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmp-compat-clozure.lisp
More file actions
168 lines (122 loc) · 5.53 KB
/
mp-compat-clozure.lisp
File metadata and controls
168 lines (122 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
;; mp-compatibility-clozure.lisp
;; --------------------------------------------------------------------------------------
;; Compatibility layer for Lispworks, Allegro, OS X, and Win32, Mulit-Processing Primitives
;;
;; Copyright (C) 2008 by SpectroDynamics, LLC. All rights reserved.
;;
;; DM/SD 08/08
;; --------------------------------------------------------------------------------------
;; --------------------------------------------------
(in-package #:mp-compatibility)
;; --------------------------------------------------
;; Compatibility Layer
(defun current-process ()
"Get the current Lisp process."
mp:*current-process*)
;; --------------------------------------------------------------------------
(defun process-name (proc)
(mp:process-name proc))
(defun set-process-name (proc name)
(setf (mp:process-name proc) name))
;; --------------------------------------------------------------------------
#|
;; NOT NEEDED FOR SUITABLY MODIFIED CCL SOURCE ADDING A PROCESS-PLIST SLOT
(defvar *process-plists* (make-hash-table :weak :key :test 'eq))
(defun process-plist (proc)
"Return the property list for the indicated Lisp process."
(gethash proc *process-plists*))
(defun set-process-plist-entry (proc key val)
(um:if-let (lst (process-plist proc))
(setf (getf lst key) val)
(setf (gethash proc *process-plists*) (list key val))))
|#
;; FOR SUITABLY MODIFIED CCL SOURCE ADDING A PROCESS-PLIST SLOT
(defun process-plist (proc)
"Return the property list for the indicated Lisp process."
(ccl:process-plist proc))
(defun set-process-plist-entry (proc key val)
(setf (getf (ccl:process-plist proc) key) val))
;; --------------------------------------------------------------------------
(defun process-run-function (name flags proc &rest args)
"Spawn a new Lisp thread and run the indicated function with inital args."
(declare (ignore flags))
(apply #'mp:process-run-function name proc args))
;; --------------------------------------------------------------------------
(defun process-kill (proc)
"Kill the indicated Lisp process."
(mp:process-kill proc))
;; --------------------------------------------------------------------------
(defun process-interrupt (proc fn &rest args)
"Interrupt the indicated Lisp process to have it perform a function."
(apply #'mp:process-interrupt proc fn args))
;; --------------------------------------------------------------------------
(defmacro without-preemption (&body body)
"Perform the body forms without preemption."
`(mp:without-interrupts ,@body)) ;; not quite, but as close as we can get...
;; --------------------------------------------------------------------------
;; --------------------------------------------------------------------------
(defun make-lock (&key name important-p (safep t))
"Make a Lisp lock."
(declare (ignorable important-p safep))
(mp:make-lock name))
;; --------------------------------------------------------------------------
(defmacro with-spin-lock ((lock) &body body)
`(with-lock (,lock) ,@body))
(defmacro with-lock ((lock &optional whostate timeout) &body body)
"Wait for lock available, then execute the body while holding the lock."
`(do-with-lock ,lock ,whostate ,timeout (lambda () ,@body)))
(defun do-with-lock (lock whostate timeout fn)
(if timeout
(and
(do-grab-lock-with-timeout lock whostate timeout)
(unwind-protect
(funcall fn)
(mp:release-lock lock)))
(mp:with-lock-grabbed (lock) (funcall fn))
))
;; --------------------------------------------------------------------------
(defun lock-owner (lock)
(declare (ignorable lock))
#|(error "lock-owner unimplemented")|#
"YourGuessIsAsGoodAsMine")
;; --------------------------------------------------------------------------
(defun process-lock (lock &optional whostate timeout)
(do-grab-lock-with-timeout lock whostate timeout))
(defun do-grab-lock-with-timeout (lock whostate timeout)
(if timeout
(or (mp:try-lock lock)
(mp:process-wait-with-timeout whostate
(round
(* timeout mp:*ticks-per-second*))
#'mp:try-lock (list lock)))
(mp:grab-lock lock)))
;; --------------------------------------------------------------------------
(defun process-unlock (lock)
(mp:release-lock lock))
;; --------------------------------------------------------------------------
(defun make-mailbox (&key size)
"Make a Lisp mailbox."
(declare (ignorable size))
(mrmb:create))
;; --------------------------------------------------------------------------
(defun mailbox-send (mbox msg)
"Send a message to a Lisp mailbox."
(mrmb:send msg mbox))
;; --------------------------------------------------------------------------
(defun mailbox-read (mbox &optional timeout)
(mrmb:receive mbox timeout))
;; --------------------------------------------------------------------------
(defun mailbox-empty? (mbox)
"Check if the Lisp mailbox is empty. Return generalized T/F."
(mrmb:is-empty mbox))
;; --------------------------------------------------------------------------
(defun process-wait (wait-reason wait-fn &rest wait-args)
(apply #'mp:process-wait wait-reason wait-fn wait-args))
;; --------------------------------------------------------------------------
(defun process-wait-with-timeout (wait-reason timeout wait-fn &rest wait-args)
(apply #'mp:process-wait-with-timeout wait-reason
(and timeout (round (* timeout mp:*ticks-per-second*)))
wait-fn wait-args))
;; --------------------------------------------------------------------------
(defun generate-uuid ()
(uuid:make-v4-uuid))