Skip to content

Commit

Permalink
kernel: turn REGION macro into function; add SET_REGION
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Oct 30, 2018
1 parent 0344ae1 commit e25cf0d
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
10 changes: 5 additions & 5 deletions src/boehm_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <execinfo.h>
#include <signal.h>
Expand Down Expand Up @@ -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
};
2 changes: 1 addition & 1 deletion src/hpc/aobjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion src/hpc/region.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
16 changes: 8 additions & 8 deletions src/hpc/threadapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/opers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand Down

0 comments on commit e25cf0d

Please sign in to comment.