From 52589e05f86d593bc3e6ea3f1a0b8f6ceae94fe6 Mon Sep 17 00:00:00 2001 From: Esa Ilari Vuokko Date: Wed, 23 Aug 2006 00:30:41 +0000 Subject: [PATCH] Add shared Typeable support --- includes/RtsTypeable.h | 19 +++++++++++++++++++ rts/Linker.c | 2 ++ rts/RtsStartup.c | 7 +++++++ rts/Typeable.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 includes/RtsTypeable.h create mode 100644 rts/Typeable.c diff --git a/includes/RtsTypeable.h b/includes/RtsTypeable.h new file mode 100644 index 0000000..28b59cd --- /dev/null +++ b/includes/RtsTypeable.h @@ -0,0 +1,19 @@ +/* ----------------------------------------------------------------------------- + * + * (c) The GHC Team, 2006 + * + * Support for shared Typeable + * + * ---------------------------------------------------------------------------*/ + +#ifndef GHC_RTS_TYPEABLE_H +#define GHC_RTS_TYPEABLE_H + +#include "Stg.h" + +void initTypeableStore(void); +void exitTypeableStore(void); + +StgPtr getOrSetTypeableStore(StgPtr); + +#endif diff --git a/rts/Linker.c b/rts/Linker.c index 2c9b07e..933f4dd 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 @@ -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 3fef259..2deb3d8 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 0000000..e07c764 --- /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; +} -- 1.7.10.4