-
Notifications
You must be signed in to change notification settings - Fork 2
/
thread-ids.lisp
38 lines (32 loc) · 952 Bytes
/
thread-ids.lisp
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
(in-package #:moira)
(declaim (type hash-table *thread-ids*))
(defvar *thread-ids*
(tg:make-weak-hash-table :weakness :key))
#+linux
(macrolet ((with-thread-id-lock ((&key) &body body)
#+ccl `(progn ,@body) ;Lock-free hash tables!
#-ccl `(synchronized ('*thread-ids*)
,@body)))
(defun thread-id (thread)
(with-thread-id-lock ()
(gethash thread *thread-ids*)))
(defun id-thread (id)
(with-thread-id-lock ()
(maphash
(lambda (k v)
(when (eql v id)
(return-from id-thread
k)))
*thread-ids*)))
;; Ensure the later redefinition for linux to be seen.'
(declaim (notinline save-current-thread-id))
(defun save-current-thread-id ()
;; Overwritten in thread-ids-linux.lisp
(values)))
#-linux
(progn
(defun thread-id (thread)
(declare (ignore thread))
0)
(defun save-current-thread-id ()
(values)))