1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
10 (in-package "SB!THREAD")
12 (eval-when (:compile-toplevel
:load-toplevel
:execute
)
13 (defvar *current-thread
* nil
))
15 (def!type thread-name
() 'simple-string
)
17 ;;; THREAD and MUTEX are mutually referential types, and the compiler isn't
18 ;;; generally intelligent enough to compile out-of-line setters efficiently
19 ;;; when it has to type-check an unknown, such as MUTEX-%OWNER which is
20 ;;; (OR NULL THREAD). But this is not a problem for the constructor,
21 ;;; because %OWNER's default is NIL which statically passes the test.
22 ;;; #'(SETF %OWNER) is suboptimally compiled, which is irrelevant,
23 ;;; because it is never called. But you can't use CAS on the slot unless it
24 ;;; is read/write, which necessarily defines a writer (that we don't want).
26 (declaim (inline make-mutex
)) ;; for possible DX-allocating
28 (:constructor make-mutex
(&key name
)))
31 (name nil
:type
(or null thread-name
))
32 (%owner nil
:type
(or null thread
))
33 #!+(and sb-thread sb-futex
)
34 (state 0 :type fixnum
))
35 (declaim (notinline make-mutex
))
37 (defstruct (thread (:constructor %make-thread
))
39 "Thread type. Do not rely on threads being structs as it may change
41 (name nil
:type
(or thread-name null
))
42 (%alive-p nil
:type boolean
)
43 (%ephemeral-p nil
:type boolean
)
45 (os-thread 0 :type sb
!vm
:word
)
46 (interruptions nil
:type list
)
47 ;; On succesful execution of the thread's lambda a list of values.
50 (make-mutex :name
"thread interruptions lock")
53 (make-mutex :name
"thread result lock")