Split GC.c, and move storage manager into sm/ directory
[ghc-hetmet.git] / rts / Typeable.c
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1995-2005
4  *
5  * Data.Typeable support
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #include "RtsTypeable.h"
10 #include "Rts.h"
11 #include "Storage.h"
12 #include "Stable.h"
13
14 static StgPtr typeableStore = 0;
15 #ifdef THREADED_RTS
16 Mutex typeableStoreLock;
17 #endif
18
19
20 void
21 initTypeableStore()
22 {
23     typeableStore=0;
24 #ifdef THREADED_RTS
25     initMutex(&typeableStoreLock);
26 #endif
27 }
28
29 void
30 exitTypeableStore()
31 {
32 #ifdef THREADED_RTS
33     closeMutex(&typeableStoreLock);
34 #endif
35     if(typeableStore!=0) {
36         freeStablePtr((StgStablePtr)typeableStore);
37         typeableStore=0;
38     }
39 }
40
41 StgPtr
42 getOrSetTypeableStore(StgPtr ptr)
43 {
44     StgPtr ret = typeableStore;
45     if(ret==0) {
46 #ifdef THREADED_RTS
47         ACQUIRE_LOCK(&typeableStoreLock);
48         ret=typeableStore;
49         if(ret==0) {
50 #endif
51             typeableStore = ret = ptr;
52 #ifdef THREADED_RTS
53         }
54         RELEASE_LOCK(&typeableStoreLock);
55 #endif
56     }
57     return ret;
58 }