Fix make-array transforms.
[sbcl.git] / src / code / barrier.lisp
1 ;;;; Support for memory barriers required for multithreaded operation
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
11
12 (in-package "SB!THREAD")
13
14
15 ;;;; Interpreter stubs for the various barrier functions
16
17 #!-memory-barrier-vops
18 (declaim (inline sb!vm:%compiler-barrier sb!vm:%memory-barrier
19                  sb!vm:%read-barrier sb!vm:%write-barrier
20                  sb!vm:%data-dependency-barrier))
21 (defun sb!vm:%compiler-barrier ()
22   #!+memory-barrier-vops (sb!vm:%compiler-barrier)
23   (values))
24 (defun sb!vm:%memory-barrier ()
25   #!+memory-barrier-vops (sb!vm:%memory-barrier)
26   (values))
27 (defun sb!vm:%read-barrier ()
28   #!+memory-barrier-vops (sb!vm:%read-barrier)
29   (values))
30 (defun sb!vm:%write-barrier ()
31   #!+memory-barrier-vops (sb!vm:%write-barrier)
32   (values))
33 (defun sb!vm:%data-dependency-barrier ()
34   #!+memory-barrier-vops (sb!vm:%data-dependency-barrier)
35   (values))
36
37
38 ;;;; The actual barrier macro and support
39 (defparameter *barrier-kind-functions*
40   '(:compiler sb!vm:%compiler-barrier :memory sb!vm:%memory-barrier
41     :read sb!vm:%read-barrier :write sb!vm:%write-barrier
42     :data-dependency sb!vm:%data-dependency-barrier))
43
44 (defun barrier-kind-function (kind)
45   (or (getf *barrier-kind-functions* kind)
46       (error "Unknown barrier kind ~S" kind)))
47
48 (def!macro barrier ((kind) &body forms)
49     "Insert a barrier in the code stream, preventing some sort of
50 reordering.
51
52 KIND should be one of:
53
54   :COMPILER
55     Prevent the compiler from reordering memory access across the
56     barrier.
57   :MEMORY
58     Prevent the cpu from reordering any memory access across the
59     barrier.
60   :READ
61     Prevent the cpu from reordering any read access across the
62     barrier.
63   :WRITE
64     Prevent the cpu from reordering any write access across the
65     barrier.
66   :DATA-DEPENDENCY
67     Prevent the cpu from reordering dependent memory reads across the
68     barrier (requiring reads before the barrier to complete before any
69     reads after the barrier that depend on them).  This is a weaker
70     form of the :READ barrier.
71
72 FORMS is an implicit PROGN, evaluated before the barrier.  BARRIER
73 returns the values of the last form in FORMS.
74
75 The file \"memory-barriers.txt\" in the Linux kernel documentation is
76 highly recommended reading for anyone programming at this level."
77   `(multiple-value-prog1
78     (progn ,@forms)
79     (,(barrier-kind-function kind))))