Wrap gcc on Windows, to provide the -B flags
[ghc-hetmet.git] / rts / Globals.c
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1995-2009
4  *
5  * The RTS stores some "global" values on behalf of libraries, so that
6  * some libraries can ensure that certain top-level things are shared
7  * even when multiple versions of the library are loaded.  e.g. see
8  * Data.Typeable and GHC.Conc.
9  *
10  * ---------------------------------------------------------------------------*/
11
12 #include "PosixSource.h"
13 #include "Rts.h"
14
15 #include "Globals.h"
16 #include "Stable.h"
17
18 static StgStablePtr typeableStore      = 0;
19 static StgStablePtr signalHandlerStore = 0;
20
21 #ifdef THREADED_RTS
22 Mutex globalStoreLock;
23 #endif
24
25 void
26 initGlobalStore(void)
27 {
28     typeableStore      = 0;
29     signalHandlerStore = 0;
30 #ifdef THREADED_RTS
31     initMutex(&globalStoreLock);
32 #endif
33 }
34
35 void
36 exitGlobalStore(void)
37 {
38 #ifdef THREADED_RTS
39     closeMutex(&globalStoreLock);
40 #endif
41     if(typeableStore!=0) {
42         freeStablePtr((StgStablePtr)typeableStore);
43         typeableStore=0;
44     }
45     if(signalHandlerStore!=0) {
46         freeStablePtr((StgStablePtr)signalHandlerStore);
47         signalHandlerStore=0;
48     }
49 }
50
51 StgStablePtr
52 getOrSetTypeableStore(StgStablePtr ptr)
53 {
54     StgStablePtr ret = typeableStore;
55     if(ret==0) {
56 #ifdef THREADED_RTS
57         ACQUIRE_LOCK(&globalStoreLock);
58         ret=typeableStore;
59         if(ret==0) {
60 #endif
61             typeableStore = ret = ptr;
62 #ifdef THREADED_RTS
63         }
64         RELEASE_LOCK(&globalStoreLock);
65 #endif
66     }
67     return ret;
68 }
69
70 StgStablePtr
71 getOrSetSignalHandlerStore(StgStablePtr ptr)
72 {
73     StgStablePtr ret = signalHandlerStore;
74     if(ret==0) {
75 #ifdef THREADED_RTS
76         ACQUIRE_LOCK(&globalStoreLock);
77         ret=signalHandlerStore;
78         if(ret==0) {
79 #endif
80             signalHandlerStore = ret = ptr;
81 #ifdef THREADED_RTS
82         }
83         RELEASE_LOCK(&globalStoreLock);
84 #endif
85     }
86     return ret;
87 }