Main thread is a regular field of global_State
They were already allocated as a single block, so there is no need for the global_State to point to its main thread.
This commit is contained in:
78
lstate.h
78
lstate.h
@@ -283,6 +283,48 @@ struct CallInfo {
|
||||
#define getoah(ci) (((ci)->callstatus & CIST_OAH) ? 1 : 0)
|
||||
|
||||
|
||||
/*
|
||||
** 'per thread' state
|
||||
*/
|
||||
struct lua_State {
|
||||
CommonHeader;
|
||||
lu_byte allowhook;
|
||||
TStatus status;
|
||||
unsigned short nci; /* number of items in 'ci' list */
|
||||
StkIdRel top; /* first free slot in the stack */
|
||||
struct global_State *l_G;
|
||||
CallInfo *ci; /* call info for current function */
|
||||
StkIdRel stack_last; /* end of stack (last element + 1) */
|
||||
StkIdRel stack; /* stack base */
|
||||
UpVal *openupval; /* list of open upvalues in this stack */
|
||||
StkIdRel tbclist; /* list of to-be-closed variables */
|
||||
GCObject *gclist;
|
||||
struct lua_State *twups; /* list of threads with open upvalues */
|
||||
struct lua_longjmp *errorJmp; /* current error recover point */
|
||||
CallInfo base_ci; /* CallInfo for first level (C host) */
|
||||
volatile lua_Hook hook;
|
||||
ptrdiff_t errfunc; /* current error handling function (stack index) */
|
||||
l_uint32 nCcalls; /* number of nested non-yieldable or C calls */
|
||||
int oldpc; /* last pc traced */
|
||||
int basehookcount;
|
||||
int hookcount;
|
||||
volatile l_signalT hookmask;
|
||||
struct { /* info about transferred values (for call/return hooks) */
|
||||
int ftransfer; /* offset of first value transferred */
|
||||
int ntransfer; /* number of values transferred */
|
||||
} transferinfo;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
** thread state + extra space
|
||||
*/
|
||||
typedef struct LX {
|
||||
lu_byte extra_[LUA_EXTRASPACE];
|
||||
lua_State l;
|
||||
} LX;
|
||||
|
||||
|
||||
/*
|
||||
** 'global state', shared by all threads of this state
|
||||
*/
|
||||
@@ -324,50 +366,18 @@ typedef struct global_State {
|
||||
GCObject *finobjrold; /* list of really old objects with finalizers */
|
||||
struct lua_State *twups; /* list of threads with open upvalues */
|
||||
lua_CFunction panic; /* to be called in unprotected errors */
|
||||
struct lua_State *mainthread;
|
||||
TString *memerrmsg; /* message for memory-allocation errors */
|
||||
TString *tmname[TM_N]; /* array with tag-method names */
|
||||
struct Table *mt[LUA_NUMTYPES]; /* metatables for basic types */
|
||||
TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */
|
||||
lua_WarnFunction warnf; /* warning function */
|
||||
void *ud_warn; /* auxiliary data to 'warnf' */
|
||||
LX mainth; /* main thread of this state */
|
||||
} global_State;
|
||||
|
||||
|
||||
/*
|
||||
** 'per thread' state
|
||||
*/
|
||||
struct lua_State {
|
||||
CommonHeader;
|
||||
lu_byte allowhook;
|
||||
TStatus status;
|
||||
unsigned short nci; /* number of items in 'ci' list */
|
||||
StkIdRel top; /* first free slot in the stack */
|
||||
global_State *l_G;
|
||||
CallInfo *ci; /* call info for current function */
|
||||
StkIdRel stack_last; /* end of stack (last element + 1) */
|
||||
StkIdRel stack; /* stack base */
|
||||
UpVal *openupval; /* list of open upvalues in this stack */
|
||||
StkIdRel tbclist; /* list of to-be-closed variables */
|
||||
GCObject *gclist;
|
||||
struct lua_State *twups; /* list of threads with open upvalues */
|
||||
struct lua_longjmp *errorJmp; /* current error recover point */
|
||||
CallInfo base_ci; /* CallInfo for first level (C host) */
|
||||
volatile lua_Hook hook;
|
||||
ptrdiff_t errfunc; /* current error handling function (stack index) */
|
||||
l_uint32 nCcalls; /* number of nested non-yieldable or C calls */
|
||||
int oldpc; /* last pc traced */
|
||||
int basehookcount;
|
||||
int hookcount;
|
||||
volatile l_signalT hookmask;
|
||||
struct { /* info about transferred values (for call/return hooks) */
|
||||
int ftransfer; /* offset of first value transferred */
|
||||
int ntransfer; /* number of values transferred */
|
||||
} transferinfo;
|
||||
};
|
||||
|
||||
|
||||
#define G(L) (L->l_G)
|
||||
#define mainthread(G) (&(G)->mainth.l)
|
||||
|
||||
/*
|
||||
** 'g->nilvalue' being a nil value flags that the state was completely
|
||||
|
||||
Reference in New Issue
Block a user