[noctool-cvs] CVS source

imattsson imattsson at common-lisp.net
Mon Nov 10 18:59:53 UTC 2008


Update of /project/noctool/cvsroot/source
In directory cl-net:/tmp/cvs-serv14228

Modified Files:
	scheduler.lisp 
Log Message:
IM

Checked in what SHOULD be a better way of guarding the number of
simultaneous processes, using SBCL semaphores to do the counting.

This way there should be next-to-no risk losing what we're trying to do,
with a slight downside of not having proper return values from the macro
(not, I believe, that they're actually used).

To change number of processes run-time, er... dunno (maybe
SB-THREAD:SIGNAL-SEMAPHORE with a "high" number?).


--- /project/noctool/cvsroot/source/scheduler.lisp	2008/11/10 14:29:45	1.8
+++ /project/noctool/cvsroot/source/scheduler.lisp	2008/11/10 18:59:53	1.9
@@ -153,6 +153,9 @@
   #+darwin 1
   #-darwin 32)
 
+(defvar *process-semaphore* (sb-thread:make-semaphore :name "Simultaneous processes" :count *total-processes*))
+
+
 (defvar *available-processes*
   (loop for i from 1 to *total-processes*
        collect
@@ -161,6 +164,8 @@
 (defvar *mini-sleep* 0.05)
 
 ;; XXX is this right? XXX
+;; Looks needlessly complex, to me.
+#-(and)
 (defmacro noc-thread (&body body)
   (let ((my-mutex (gensym))
         (first-mutex (gensym))
@@ -183,6 +188,17 @@
          (setf *available-processes* (cons ,my-mutex *available-processes*)))
        ,return-val)))
 
+(defmacro with-semaphore (semaphore &body body)
+  `(progn
+    (sb-thread:wait-on-semaphore ,semaphore)
+    (unwind-protect
+	 (progn , at body)
+      (sb-thread:signal-semaphore ,semaphore))))
+
+(defmacro noc-thread (&body body)
+  `(with-semaphore *process-semaphore*
+    , at body))
+
 (defmethod process ((event event))
   #-no-noctool-threads
   (noc-thread 





More information about the noctool-cvs mailing list