diff options
author | Esa Ilari Vuokko <ei@vuokko.info> | 2006-08-23 00:30:41 +0000 |
---|---|---|
committer | Esa Ilari Vuokko <ei@vuokko.info> | 2006-08-23 00:30:41 +0000 |
commit | 52589e05f86d593bc3e6ea3f1a0b8f6ceae94fe6 (patch) | |
tree | 478412900cabc3f4a23551eec2a705cde5badfac /rts | |
parent | 22afade657206fa4ac86ebb6ecc8f2352cca3c4f (diff) | |
download | haskell-52589e05f86d593bc3e6ea3f1a0b8f6ceae94fe6.tar.gz |
Add shared Typeable support
Diffstat (limited to 'rts')
-rw-r--r-- | rts/Linker.c | 2 | ||||
-rw-r--r-- | rts/RtsStartup.c | 7 | ||||
-rw-r--r-- | rts/Typeable.c | 48 |
3 files changed, 57 insertions, 0 deletions
diff --git a/rts/Linker.c b/rts/Linker.c index 2c9b07e54e..933f4dd5d5 100644 --- a/rts/Linker.c +++ b/rts/Linker.c @@ -27,6 +27,7 @@ #include "Schedule.h" #include "Storage.h" #include "Sparks.h" +#include "RtsTypeable.h" #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> @@ -508,6 +509,7 @@ typedef struct _RtsSymbolVal { SymX(forkOS_createThread) \ SymX(freeHaskellFunctionPtr) \ SymX(freeStablePtr) \ + SymX(getOrSetTypeableStore) \ SymX(gcdIntegerzh_fast) \ SymX(gcdIntegerIntzh_fast) \ SymX(gcdIntzh_fast) \ diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c index 3fef259126..2deb3d8e67 100644 --- a/rts/RtsStartup.c +++ b/rts/RtsStartup.c @@ -28,6 +28,7 @@ #include "ThreadLabels.h" #include "BlockAlloc.h" #include "Trace.h" +#include "RtsTypeable.h" #if defined(RTS_GTK_FRONTPANEL) #include "FrontPanel.h" @@ -196,6 +197,9 @@ hs_init(int *argc, char **argv[]) /* initialise the stable pointer table */ initStablePtrTable(); + /* initialise the shared Typeable store */ + initTypeableStore(); + #if defined(DEBUG) /* initialise thread label table (tso->char*) */ initThreadLabelTable(); @@ -390,6 +394,9 @@ hs_exit(void) // also outputs the stats (+RTS -s) info. exitStorage(); + /* free shared Typeable store */ + exitTypeableStore(); + /* initialise the stable pointer table */ exitStablePtrTable(); diff --git a/rts/Typeable.c b/rts/Typeable.c new file mode 100644 index 0000000000..e07c764c55 --- /dev/null +++ b/rts/Typeable.c @@ -0,0 +1,48 @@ +#include "RtsTypeable.h" +#include "Rts.h" +
+static StgPtr typeableStore = 0;
+#ifdef THREADED_RTS
+Mutex typeableStoreLock;
+#endif
+
+
+void
+initTypeableStore()
+{
+ typeableStore=0;
+#ifdef THREADED_RTS
+ initMutex(&typeableStoreLock);
+#endif
+}
+
+void
+exitTypeableStore()
+{
+#ifdef THREADED_RTS
+ /* TODO: Free Mutex! */
+#endif
+ if(typeableStore!=0) {
+ freeStablePtr((StgStablePtr)typeableStore);
+ typeableStore=0;
+ }
+}
+
+StgPtr
+getOrSetTypeableStore(StgPtr ptr)
+{
+ StgPtr ret = typeableStore;
+ if(ret==0) {
+#ifdef THREADED_RTS
+ ACQUIRE_LOCK(&typeableStoreLock);
+ ret=typeableStore;
+ if(ret==0) {
+#endif
+ typeableStore = ret = ptr;
+#ifdef THREADED_RTS
+ }
+ RELEASE_LOCK(&typeableStoreLock);
+#endif
+ }
+ return ret;
+}
|