Skip to content

Commit

Permalink
kernel: move InitModuleState etc. to StructInitInfo
Browse files Browse the repository at this point in the history
This will eventually make it possible for kernel extensions to also define
their own module state, for use in HPC-GAP.
  • Loading branch information
fingolfin committed Jun 18, 2018
1 parent 8f6a003 commit c966897
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -3369,11 +3369,11 @@ static StructInitInfo module = {
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.preSave = PreSave,
.postRestore = PostRestore
.postRestore = PostRestore,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoCode ( void )
{
RegisterModuleState(0, InitModuleState, 0);
return &module;
}
5 changes: 4 additions & 1 deletion src/cyclotom.c
Original file line number Diff line number Diff line change
Expand Up @@ -2277,10 +2277,13 @@ static StructInitInfo module = {
.name = "cyclotom",
.initKernel = InitKernel,
.initLibrary = InitLibrary,

.moduleStateSize = sizeof(struct CycModuleState),
.moduleStateOffsetPtr = &CycStateOffset,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoCyc ( void )
{
CycStateOffset = RegisterModuleState(sizeof(struct CycModuleState), InitModuleState, 0);
return &module;
}
5 changes: 4 additions & 1 deletion src/funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,10 +1193,13 @@ static StructInitInfo module = {
.name = "funcs",
.initKernel = InitKernel,
.initLibrary = InitLibrary,

.moduleStateSize = sizeof(struct FuncsModuleState),
.moduleStateOffsetPtr = &FuncsStateOffset,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoFuncs ( void )
{
FuncsStateOffset = RegisterModuleState(sizeof(struct FuncsModuleState), InitModuleState, 0);
return &module;
}
4 changes: 2 additions & 2 deletions src/gvars.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,11 +1778,11 @@ static StructInitInfo module = {
.checkInit = CheckInit,
.preSave = PreSave,
.postSave = PostSave,
.postRestore = PostRestore
.postRestore = PostRestore,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoGVars ( void )
{
RegisterModuleState(0, InitModuleState, 0);
return &module;
}
3 changes: 2 additions & 1 deletion src/hpc/aobjects.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,10 +2075,11 @@ static StructInitInfo module = {
.name = "aobjects",
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.initModuleState = InitAObjectsState,
.destroyModuleState = DestroyAObjectsState,
};

StructInitInfo * InitInfoAObjects ( void )
{
RegisterModuleState(0, InitAObjectsState, DestroyAObjectsState);
return &module;
}
5 changes: 3 additions & 2 deletions src/hpc/serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,12 +1201,13 @@ static StructInitInfo module = {
.name = "serialize",
.initKernel = InitKernel,
.initLibrary = InitLibrary,

.moduleStateSize = sizeof(SerializeModuleState),
.moduleStateOffsetPtr = &SerializeStateOffset,
};

StructInitInfo * InitInfoSerialize(void)
{
SerializeStateOffset =
RegisterModuleState(sizeof(SerializeModuleState), 0, 0);
return &module;
}

Expand Down
4 changes: 3 additions & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -2142,10 +2142,12 @@ static StructInitInfo module = {
.name = "scanner",
.initKernel = InitKernel,
.initLibrary = InitLibrary,

.moduleStateSize = sizeof(struct IOModuleState),
.moduleStateOffsetPtr = &IOStateOffset,
};

StructInitInfo * InitInfoIO ( void )
{
IOStateOffset = RegisterModuleState(sizeof(struct IOModuleState), 0, 0);
return &module;
}
10 changes: 10 additions & 0 deletions src/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,16 @@ void ModulesSetup(void)
FPUTS_TO_STDERR(info->name);
FPUTS_TO_STDERR(")\n");
}

// register module state if necessary
if (info->moduleStateSize || info->initModuleState ||
info->destroyModuleState) {
UInt offset = RegisterModuleState(info->moduleStateSize,
info->initModuleState,
info->destroyModuleState);
if (info->moduleStateOffsetPtr)
*info->moduleStateOffsetPtr = offset;
}
}
NrBuiltinModules = NrModules;
}
Expand Down
15 changes: 14 additions & 1 deletion src/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
**
*/

#define GAP_KERNEL_MAJOR_VERSION 2
#define GAP_KERNEL_MAJOR_VERSION 3
#define GAP_KERNEL_MINOR_VERSION 0
#define GAP_KERNEL_API_VERSION \
((GAP_KERNEL_MAJOR_VERSION)*1000 + (GAP_KERNEL_MINOR_VERSION))
Expand Down Expand Up @@ -114,6 +114,19 @@ struct init_info {
/* function to call after restoring workspace */
Int (*postRestore)(StructInitInfo *);

// number of bytes this module needs for its per-thread module state
UInt moduleStateSize;

// if this is not zero, then the module state offset is stored into
// the address this points at
Int * moduleStateOffsetPtr;

// initialize thread local module state
Int (*initModuleState)(void);

// destroy thread local module state
Int (*destroyModuleState)(void);

};


Expand Down
7 changes: 5 additions & 2 deletions src/objcftl.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,14 @@ static StructInitInfo module = {
.name = "objcftl",
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.postRestore = PostRestore
.postRestore = PostRestore,

.moduleStateSize = sizeof(struct CFTLModuleState),
.moduleStateOffsetPtr = &CFTLStateOffset,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoPcc ( void )
{
CFTLStateOffset = RegisterModuleState(sizeof(struct CFTLModuleState), InitModuleState, 0);
return &module;
}
4 changes: 3 additions & 1 deletion src/objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -2315,10 +2315,12 @@ static StructInitInfo module = {
.name = "objects",
.initKernel = InitKernel,
.initLibrary = InitLibrary,

.moduleStateSize = sizeof(ObjectsModuleState),
.moduleStateOffsetPtr = &ObjectsStateOffset,
};

StructInitInfo * InitInfoObjects ( void )
{
ObjectsStateOffset = RegisterModuleState(sizeof(ObjectsModuleState), 0, 0);
return &module;
}
2 changes: 1 addition & 1 deletion src/objscoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,10 +833,10 @@ static StructInitInfo module = {
.name = "objscoll",
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoSingleCollector ( void )
{
RegisterModuleState(0, InitModuleState, 0);
return &module;
}
4 changes: 2 additions & 2 deletions src/opers.c
Original file line number Diff line number Diff line change
Expand Up @@ -4264,11 +4264,11 @@ static StructInitInfo module = {
.name = "opers",
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.postRestore = postRestore
.postRestore = postRestore,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoOpers ( void )
{
RegisterModuleState(0, InitModuleState, 0);
return &module;
}
5 changes: 4 additions & 1 deletion src/permutat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4574,10 +4574,13 @@ static StructInitInfo module = {
.name = "permutat",
.initKernel = InitKernel,
.initLibrary = InitLibrary,

.moduleStateSize = sizeof(PermutatModuleState),
.moduleStateOffsetPtr = &PermutatStateOffset,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoPermutat ( void )
{
PermutatStateOffset = RegisterModuleState(sizeof(PermutatModuleState), InitModuleState, 0);
return &module;
}
6 changes: 4 additions & 2 deletions src/pperm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6728,11 +6728,13 @@ static StructInitInfo module = {
.name = "pperm",
.initKernel = InitKernel,
.initLibrary = InitLibrary,

.moduleStateSize = sizeof(PPermModuleState),
.moduleStateOffsetPtr = &PPermStateOffset,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoPPerm(void)
{
PPermStateOffset =
RegisterModuleState(sizeof(PPermModuleState), InitModuleState, 0);
return &module;
}
2 changes: 1 addition & 1 deletion src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -2948,10 +2948,10 @@ static StructInitInfo module = {
.type = MODULE_BUILTIN,
.name = "read",
.initKernel = InitKernel,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoRead ( void )
{
RegisterModuleState(0, InitModuleState, 0);
return &module;
}
2 changes: 1 addition & 1 deletion src/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,10 +1740,10 @@ static StructInitInfo module = {
.name = "stats",
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoStats ( void )
{
RegisterModuleState(0, InitModuleState, 0);
return &module;
}
4 changes: 3 additions & 1 deletion src/trans.c
Original file line number Diff line number Diff line change
Expand Up @@ -5688,10 +5688,12 @@ static StructInitInfo module = {
.name = "trans",
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.moduleStateSize = sizeof(TransModuleState),
.moduleStateOffsetPtr = &TransStateOffset,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoTrans(void)
{
TransStateOffset = RegisterModuleState(sizeof(TransModuleState), InitModuleState, 0);
return &module;
}
4 changes: 2 additions & 2 deletions src/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -2795,11 +2795,11 @@ static StructInitInfo module = {
.name = "vars",
.initKernel = InitKernel,
.initLibrary = InitLibrary,
.postRestore = PostRestore
.postRestore = PostRestore,
.initModuleState = InitModuleState,
};

StructInitInfo * InitInfoVars ( void )
{
RegisterModuleState(0, InitModuleState, 0);
return &module;
}

0 comments on commit c966897

Please sign in to comment.