diff --git a/src/boehm_gc.c b/src/boehm_gc.c index ed7aca9f05..f88095ddeb 100644 --- a/src/boehm_gc.c +++ b/src/boehm_gc.c @@ -76,14 +76,14 @@ void MakeBagTypePublic(int type) Bag MakeBagPublic(Bag bag) { MEMBAR_WRITE(); - REGION(bag) = 0; + SET_REGION(bag, 0); return bag; } Bag MakeBagReadOnly(Bag bag) { MEMBAR_WRITE(); - REGION(bag) = ReadOnlyRegion; + SET_REGION(bag, ReadOnlyRegion); return bag; } @@ -424,7 +424,7 @@ void RetypeBag(Bag bag, UInt new_type) #ifdef HPCGAP switch (DSInfoBags[new_type]) { case DSI_PUBLIC: - REGION(bag) = NULL; + SET_REGION(bag, NULL); break; } #endif // HPCGAP @@ -500,10 +500,10 @@ Bag NewBag(UInt type, UInt size) #ifdef HPCGAP switch (DSInfoBags[type]) { case DSI_TL: - REGION(bag) = CurrentRegion(); + SET_REGION(bag, CurrentRegion()); break; case DSI_PUBLIC: - REGION(bag) = NULL; + SET_REGION(bag, NULL); break; } #endif diff --git a/src/debug.c b/src/debug.c index e91f74398f..6a4b21de7e 100644 --- a/src/debug.c +++ b/src/debug.c @@ -5,6 +5,10 @@ #include "calls.h" #include "fibhash.h" +#ifdef HPCGAP +#include "hpc/region.h" +#endif + #if defined(HAVE_BACKTRACE) && defined(PRINT_BACKTRACE) #include #include @@ -391,6 +395,8 @@ VoidFunc debug_func_pointers[] = { (VoidFunc)ATOMIC_SET_ELM_PLIST, (VoidFunc)GetTLS, (VoidFunc)LCKS_FUNC, + (VoidFunc)REGION, (VoidFunc)SET_LCKS_FUNC, + (VoidFunc)SET_REGION, #endif }; diff --git a/src/hpc/aobjects.c b/src/hpc/aobjects.c index ca292831aa..f0ce7fa3d1 100644 --- a/src/hpc/aobjects.c +++ b/src/hpc/aobjects.c @@ -1181,7 +1181,7 @@ static Obj NewTLRecord(Obj defaults, Obj constructors) { ADDR_OBJ(inner)[TLR_SIZE] = 0; ADDR_OBJ(inner)[TLR_DEFAULTS] = CreateTLDefaults(defaults); WriteGuard(constructors); - REGION(constructors) = LimboRegion; + SET_REGION(constructors, LimboRegion); MEMBAR_WRITE(); ADDR_OBJ(inner)[TLR_CONSTRUCTORS] = NewAtomicRecordFrom(constructors); ((AtomicObj *)(ADDR_OBJ(result)))->obj = inner; diff --git a/src/hpc/region.h b/src/hpc/region.h index b0959212da..4d9156c039 100644 --- a/src/hpc/region.h +++ b/src/hpc/region.h @@ -39,7 +39,15 @@ Region *NewRegion(void); ** ** RegionBag() also contains a memory barrier. */ -#define REGION(bag) (((Region **)(bag))[1]) +static inline Region * REGION(Obj bag) +{ + return ((Region **)bag)[1]; +} + +static inline void SET_REGION(Obj bag, Region * region) +{ + ((Region **)bag)[1] = region; +} Region *RegionBag(Bag bag); diff --git a/src/hpc/threadapi.c b/src/hpc/threadapi.c index 6ce3e67c01..c7052d4a8f 100644 --- a/src/hpc/threadapi.c +++ b/src/hpc/threadapi.c @@ -358,7 +358,7 @@ pthread_mutex_t KeepAliveLock; Obj KeepAlive(Obj obj) { Obj newKeepAlive = NewBag(T_PLIST, 4 * sizeof(Obj)); - REGION(newKeepAlive) = NULL; // public region + SET_REGION(newKeepAlive, NULL); // public region pthread_mutex_lock(&KeepAliveLock); ADDR_OBJ(newKeepAlive)[0] = (Obj)3; /* Length 3 */ KEPTALIVE(newKeepAlive) = obj; @@ -413,7 +413,7 @@ Obj FuncCreateThread(Obj self, Obj funcargs) "CreateThread: Needs at least one function argument"); templist = NEW_PLIST(T_PLIST, n); SET_LEN_PLIST(templist, n); - REGION(templist) = NULL; /* make it public */ + SET_REGION(templist, NULL); /* make it public */ for (i = 1; i <= n; i++) SET_ELM_PLIST(templist, i, ELM_PLIST(funcargs, i)); thread = RunThread(ThreadedInterpreter, KeepAlive(templist)); @@ -1012,7 +1012,7 @@ static void ExpandChannel(Channel * channel) Obj newqueue; newqueue = NEW_PLIST(T_PLIST, newCapacity); SET_LEN_PLIST(newqueue, newCapacity); - REGION(newqueue) = REGION(channel->queue); + SET_REGION(newqueue, REGION(channel->queue)); channel->capacity = newCapacity; for (i = channel->head; i < oldCapacity; i++) ADDR_OBJ(newqueue)[i + 1] = ADDR_OBJ(channel->queue)[i + 1]; @@ -1045,7 +1045,7 @@ static void AddToChannel(Channel * channel, Obj obj, int migrate) } for (i = 1; i <= len; i++) { Obj item = ELM_PLIST(children, i); - REGION(item) = region; + SET_REGION(item, region); } ADDR_OBJ(channel->queue)[++channel->tail] = obj; ADDR_OBJ(channel->queue)[++channel->tail] = children; @@ -1066,7 +1066,7 @@ static Obj RetrieveFromChannel(Channel * channel) channel->head = 0; for (i = 1; i <= len; i++) { Obj item = ELM_PLIST(children, i); - REGION(item) = region; + SET_REGION(item, region); } channel->size -= 2; return obj; @@ -1286,7 +1286,7 @@ static Obj CreateChannel(int capacity) channel->dynamic = (capacity < 0); channel->waiting = 0; channel->queue = NEW_PLIST(T_PLIST, channel->capacity); - REGION(channel->queue) = LimboRegion; + SET_REGION(channel->queue, LimboRegion); SET_LEN_PLIST(channel->queue, channel->capacity); return channelBag; } @@ -2030,13 +2030,13 @@ MigrateObjects(int count, Obj * objects, Region * target, int retype) for (i = 0; i < count; i++) { Region * region; if (IS_BAG_REF(objects[i])) { - region = (Region *)(REGION(objects[i])); + region = REGION(objects[i]); if (!region || region->owner != GetTLS()) return 0; } } for (i = 0; i < count; i++) - REGION(objects[i]) = target; + SET_REGION(objects[i], target); return 1; } diff --git a/src/objects.c b/src/objects.c index 0010ff179e..ccb701f944 100644 --- a/src/objects.c +++ b/src/objects.c @@ -1905,7 +1905,7 @@ Obj FuncCLONE_OBJ ( memcpy(pdst, psrc, SIZE_OBJ(src)); CHANGED_BAG(dst); #ifdef HPCGAP - REGION(dst) = REGION(src); + SET_REGION(dst, REGION(src)); MEMBAR_WRITE(); /* The following is a no-op unless the region is public */ SET_PTR_BAG(dst, PTR_BAG(tmp)); @@ -1942,8 +1942,8 @@ Obj FuncSWITCH_OBJ(Obj self, Obj obj1, Obj obj2) { ErrorQuit("SWITCH_OBJ: Cannot write to first object's region.", 0, 0); if (!ds2 || ds2->owner != GetTLS()) ErrorQuit("SWITCH_OBJ: Cannot write to second object's region.", 0, 0); - REGION(obj2) = ds1; - REGION(obj1) = ds2; + SET_REGION(obj2, ds1); + SET_REGION(obj1, ds2); #endif SwapMasterPoint(obj1, obj2); CHANGED_BAG(obj1); @@ -1987,9 +1987,9 @@ Obj FuncFORCE_SWITCH_OBJ(Obj self, Obj obj1, Obj obj2) { ErrorQuit("FORCE_SWITCH_OBJ: Cannot write to first object's region.", 0, 0); if (ds2 && ds2->owner != GetTLS()) ErrorQuit("FORCE_SWITCH_OBJ: Cannot write to second object's region.", 0, 0); - REGION(obj2) = ds1; + SET_REGION(obj2, ds1); SET_PTR_BAG(obj2, ptr1); - REGION(obj1) = ds2; + SET_REGION(obj1, ds2); SET_PTR_BAG(obj1, ptr2); CHANGED_BAG(obj1); CHANGED_BAG(obj2); diff --git a/src/opers.c b/src/opers.c index f19fdedd7a..f7b2c63e3c 100644 --- a/src/opers.c +++ b/src/opers.c @@ -4219,8 +4219,8 @@ static Int InitLibrary ( AssGVar(GVarName("HIDDEN_IMPS"), HIDDEN_IMPS); #ifdef HPCGAP - REGION(HIDDEN_IMPS) = NewRegion(); - REGION(WITH_HIDDEN_IMPS_FLAGS_CACHE) = REGION(HIDDEN_IMPS); + SET_REGION(HIDDEN_IMPS, NewRegion()); + SET_REGION(WITH_HIDDEN_IMPS_FLAGS_CACHE, REGION(HIDDEN_IMPS)); #endif IMPLICATIONS_SIMPLE = NEW_PLIST(T_PLIST, 0); @@ -4231,9 +4231,9 @@ static Int InitLibrary ( AssGVar(GVarName("IMPLICATIONS_COMPOSED"), IMPLICATIONS_COMPOSED); #ifdef HPCGAP - REGION(IMPLICATIONS_SIMPLE) = NewRegion(); - REGION(IMPLICATIONS_COMPOSED) = REGION(IMPLICATIONS_SIMPLE); - REGION(WITH_IMPS_FLAGS_CACHE) = REGION(IMPLICATIONS_SIMPLE); + SET_REGION(IMPLICATIONS_SIMPLE, NewRegion()); + SET_REGION(IMPLICATIONS_COMPOSED, REGION(IMPLICATIONS_SIMPLE)); + SET_REGION(WITH_IMPS_FLAGS_CACHE, REGION(IMPLICATIONS_SIMPLE)); #endif /* make the 'true' operation */