Replace "tail -n +2" with "sed 1d", as Solaris doesn't understand the former
[ghc.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
12 static StgPtr typeableStore = 0;
13 #ifdef THREADED_RTS
14 Mutex typeableStoreLock;
15 #endif
16
17
18 void
19 initTypeableStore()
20 {
21 typeableStore=0;
22 #ifdef THREADED_RTS
23 initMutex(&typeableStoreLock);
24 #endif
25 }
26
27 void
28 exitTypeableStore()
29 {
30 #ifdef THREADED_RTS
31 closeMutex(&typeableStoreLock);
32 #endif
33 if(typeableStore!=0) {
34 freeStablePtr((StgStablePtr)typeableStore);
35 typeableStore=0;
36 }
37 }
38
39 StgPtr
40 getOrSetTypeableStore(StgPtr ptr)
41 {
42 StgPtr ret = typeableStore;
43 if(ret==0) {
44 #ifdef THREADED_RTS
45 ACQUIRE_LOCK(&typeableStoreLock);
46 ret=typeableStore;
47 if(ret==0) {
48 #endif
49 typeableStore = ret = ptr;
50 #ifdef THREADED_RTS
51 }
52 RELEASE_LOCK(&typeableStoreLock);
53 #endif
54 }
55 return ret;
56 }