diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-01-31 13:51:38 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-01-31 13:51:38 -0300 |
commit | fa1382b5cd504bdfc5fc3f5c447ed09a4c9804fd (patch) | |
tree | 5c5f4f75e46a0ce1e82eca4395457627895c665c /lstate.h | |
parent | d1e677c52be3b107a7a29fdc482158f6d9251e79 (diff) | |
download | lua-fa1382b5cd504bdfc5fc3f5c447ed09a4c9804fd.tar.gz lua-fa1382b5cd504bdfc5fc3f5c447ed09a4c9804fd.tar.bz2 lua-fa1382b5cd504bdfc5fc3f5c447ed09a4c9804fd.zip |
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.
Diffstat (limited to 'lstate.h')
-rw-r--r-- | lstate.h | 78 |
1 files changed, 44 insertions, 34 deletions
@@ -284,6 +284,48 @@ struct CallInfo { | |||
284 | 284 | ||
285 | 285 | ||
286 | /* | 286 | /* |
287 | ** 'per thread' state | ||
288 | */ | ||
289 | struct lua_State { | ||
290 | CommonHeader; | ||
291 | lu_byte allowhook; | ||
292 | TStatus status; | ||
293 | unsigned short nci; /* number of items in 'ci' list */ | ||
294 | StkIdRel top; /* first free slot in the stack */ | ||
295 | struct global_State *l_G; | ||
296 | CallInfo *ci; /* call info for current function */ | ||
297 | StkIdRel stack_last; /* end of stack (last element + 1) */ | ||
298 | StkIdRel stack; /* stack base */ | ||
299 | UpVal *openupval; /* list of open upvalues in this stack */ | ||
300 | StkIdRel tbclist; /* list of to-be-closed variables */ | ||
301 | GCObject *gclist; | ||
302 | struct lua_State *twups; /* list of threads with open upvalues */ | ||
303 | struct lua_longjmp *errorJmp; /* current error recover point */ | ||
304 | CallInfo base_ci; /* CallInfo for first level (C host) */ | ||
305 | volatile lua_Hook hook; | ||
306 | ptrdiff_t errfunc; /* current error handling function (stack index) */ | ||
307 | l_uint32 nCcalls; /* number of nested non-yieldable or C calls */ | ||
308 | int oldpc; /* last pc traced */ | ||
309 | int basehookcount; | ||
310 | int hookcount; | ||
311 | volatile l_signalT hookmask; | ||
312 | struct { /* info about transferred values (for call/return hooks) */ | ||
313 | int ftransfer; /* offset of first value transferred */ | ||
314 | int ntransfer; /* number of values transferred */ | ||
315 | } transferinfo; | ||
316 | }; | ||
317 | |||
318 | |||
319 | /* | ||
320 | ** thread state + extra space | ||
321 | */ | ||
322 | typedef struct LX { | ||
323 | lu_byte extra_[LUA_EXTRASPACE]; | ||
324 | lua_State l; | ||
325 | } LX; | ||
326 | |||
327 | |||
328 | /* | ||
287 | ** 'global state', shared by all threads of this state | 329 | ** 'global state', shared by all threads of this state |
288 | */ | 330 | */ |
289 | typedef struct global_State { | 331 | typedef struct global_State { |
@@ -324,50 +366,18 @@ typedef struct global_State { | |||
324 | GCObject *finobjrold; /* list of really old objects with finalizers */ | 366 | GCObject *finobjrold; /* list of really old objects with finalizers */ |
325 | struct lua_State *twups; /* list of threads with open upvalues */ | 367 | struct lua_State *twups; /* list of threads with open upvalues */ |
326 | lua_CFunction panic; /* to be called in unprotected errors */ | 368 | lua_CFunction panic; /* to be called in unprotected errors */ |
327 | struct lua_State *mainthread; | ||
328 | TString *memerrmsg; /* message for memory-allocation errors */ | 369 | TString *memerrmsg; /* message for memory-allocation errors */ |
329 | TString *tmname[TM_N]; /* array with tag-method names */ | 370 | TString *tmname[TM_N]; /* array with tag-method names */ |
330 | struct Table *mt[LUA_NUMTYPES]; /* metatables for basic types */ | 371 | struct Table *mt[LUA_NUMTYPES]; /* metatables for basic types */ |
331 | TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */ | 372 | TString *strcache[STRCACHE_N][STRCACHE_M]; /* cache for strings in API */ |
332 | lua_WarnFunction warnf; /* warning function */ | 373 | lua_WarnFunction warnf; /* warning function */ |
333 | void *ud_warn; /* auxiliary data to 'warnf' */ | 374 | void *ud_warn; /* auxiliary data to 'warnf' */ |
375 | LX mainth; /* main thread of this state */ | ||
334 | } global_State; | 376 | } global_State; |
335 | 377 | ||
336 | 378 | ||
337 | /* | ||
338 | ** 'per thread' state | ||
339 | */ | ||
340 | struct lua_State { | ||
341 | CommonHeader; | ||
342 | lu_byte allowhook; | ||
343 | TStatus status; | ||
344 | unsigned short nci; /* number of items in 'ci' list */ | ||
345 | StkIdRel top; /* first free slot in the stack */ | ||
346 | global_State *l_G; | ||
347 | CallInfo *ci; /* call info for current function */ | ||
348 | StkIdRel stack_last; /* end of stack (last element + 1) */ | ||
349 | StkIdRel stack; /* stack base */ | ||
350 | UpVal *openupval; /* list of open upvalues in this stack */ | ||
351 | StkIdRel tbclist; /* list of to-be-closed variables */ | ||
352 | GCObject *gclist; | ||
353 | struct lua_State *twups; /* list of threads with open upvalues */ | ||
354 | struct lua_longjmp *errorJmp; /* current error recover point */ | ||
355 | CallInfo base_ci; /* CallInfo for first level (C host) */ | ||
356 | volatile lua_Hook hook; | ||
357 | ptrdiff_t errfunc; /* current error handling function (stack index) */ | ||
358 | l_uint32 nCcalls; /* number of nested non-yieldable or C calls */ | ||
359 | int oldpc; /* last pc traced */ | ||
360 | int basehookcount; | ||
361 | int hookcount; | ||
362 | volatile l_signalT hookmask; | ||
363 | struct { /* info about transferred values (for call/return hooks) */ | ||
364 | int ftransfer; /* offset of first value transferred */ | ||
365 | int ntransfer; /* number of values transferred */ | ||
366 | } transferinfo; | ||
367 | }; | ||
368 | |||
369 | |||
370 | #define G(L) (L->l_G) | 379 | #define G(L) (L->l_G) |
380 | #define mainthread(G) (&(G)->mainth.l) | ||
371 | 381 | ||
372 | /* | 382 | /* |
373 | ** 'g->nilvalue' being a nil value flags that the state was completely | 383 | ** 'g->nilvalue' being a nil value flags that the state was completely |