Skip to content

Commit

Permalink
Add ActiveGAPState() helper, use it in STATE macro
Browse files Browse the repository at this point in the history
This allows implementing the STATE() macro uniformly for GAP and HPC-GAP.
ActiveGAPState() also provides a uniform way to access the active GAP state
when debugging the kernel with gdb or lldb.
  • Loading branch information
fingolfin authored and stevelinton committed Nov 1, 2017
1 parent 10cf8d4 commit 502fdf1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void InstallBacktraceHandlers(void) {
// gdb or lldb.
typedef void (* VoidFunc)(void);
VoidFunc debug_func_pointers[] = {
(VoidFunc)ActiveGAPState,
(VoidFunc)ADDR_OBJ,
(VoidFunc)ADDR_PPERM2,
(VoidFunc)ADDR_PPERM4,
Expand Down
8 changes: 7 additions & 1 deletion src/gapstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,16 @@ typedef struct GAPState {
#else

extern GAPState MainGAPState;
#define STATE(x) (MainGAPState.x)

static inline GAPState * ActiveGAPState(void)
{
return &MainGAPState;
}

#endif

#define STATE(x) (ActiveGAPState()->x)

/* Access a module's registered state */
#define MODULE_STATE(module, var) \
(((module ## ModuleState *)(&STATE(StateSlots)[module ## StateOffset]))->var)
Expand Down
6 changes: 5 additions & 1 deletion src/hpc/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ static ALWAYS_INLINE ThreadLocalStorage *GetTLS(void)
#endif /* HAVE_NATIVE_TLS */

#define TLS(x) realTLS->x
#define STATE(x) TLS(state).x

static inline GAPState * ActiveGAPState(void)
{
return &TLS(state);
}

static inline int IsMainThread(void)
{
Expand Down

0 comments on commit 502fdf1

Please sign in to comment.