0.8.20.29:
[sbcl.git] / src / code / target-unithread.lisp
index 6eb1df2..5d2505e 100644 (file)
@@ -1,3 +1,14 @@
+;;;; unithread stub support for threads in the target machine
+
+;;;; This software is part of the SBCL system. See the README file for
+;;;; more information.
+;;;;
+;;;; This software is derived from the CMU CL system, which was
+;;;; written at Carnegie Mellon University and released into the
+;;;; public domain. The software is in the public domain and is
+;;;; provided with absolutely no warranty. See the COPYING and CREDITS
+;;;; files for more information.
+
 (in-package "SB!THREAD")
 
 ;;; used bu debug-int.lisp to access interrupt contexts
 (defun sb!vm::current-thread-offset-sap (n) 
   (declare (type (unsigned-byte 27) n))
   (sb!sys:sap-ref-sap (alien-sap (extern-alien "all_threads" (* t))) 
-              (* n 4)))
+              (* n sb!vm:n-word-bytes)))
 
 (defun current-thread-id ()
   (sb!sys:sap-ref-32 (alien-sap (extern-alien "all_threads" (* t))) 
-              (* sb!vm::thread-pid-slot 4)))
+              (* sb!vm::thread-pid-slot sb!vm:n-word-bytes)))
+
+(defun reap-dead-threads ())
 
 ;;;; queues, locks 
 
@@ -24,7 +37,7 @@
 ;;;; the higher-level locking operations are based on waitqueues
 
 (defstruct waitqueue
-  (name nil :type (or null simple-base-string))
+  (name nil :type (or null simple-string))
   (lock 0)
   (data nil))
 
        (return t))
      (setf old-value t1))))
 
-(defmacro with-mutex ((mutex &key value (wait-p t))  &body body)
-  (cond ((not wait-p)
-        `(unless (mutex-value ,mutex)
-          (unwind-protect
-               (progn
-                 (setf (mutex-value ,mutex) (or ,value t))
-                 ,@body)
-            (setf (mutex-value ,mutex) nil))))
-       (t 
-        `(progn ,@body))))
+(defun get-mutex (lock &optional new-value (wait-p t))
+  (declare (type mutex lock))
+  (let ((old-value (mutex-value lock)))
+    (when (and old-value wait-p)
+      (error "In unithread mode, mutex ~S was requested with WAIT-P ~S and ~
+              new-value ~S, but has already been acquired (with value ~S)."
+            lock wait-p new-value old-value))
+    (setf (mutex-value lock) new-value)
+    t))
+
+(defun release-mutex (lock)
+  (declare (type mutex lock))
+  (setf (mutex-value lock) nil))
 
 ;;; what's the best thing to do with these on unithread?  commented
 ;;; functions are the thread versions, just to remind me what they do
@@ -125,8 +141,6 @@ time we reacquire LOCK and return to the caller."
   "Notify one of the processes waiting on QUEUE"
   (signal-queue-head queue))
 
-(defun maybe-install-futex-functions () nil)
-
 ;;;; job control
 
 (defun init-job-control () t)