Skip to content

Commit

Permalink
Fixed issue with multi-computer cache
Browse files Browse the repository at this point in the history
  • Loading branch information
MCJack123 committed Jun 15, 2024
1 parent af0ce15 commit 6a028e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ static ProtectedObject<std::unordered_map<void*, Computer*> > getCompCache;

Computer * get_comp(lua_State *L) {
try {
return getCompCache->at(L->l_G);
return getCompCache->at(L->glref);
} catch (std::out_of_range &e) {
LockGuard lock(getCompCache);
lua_rawgeti(L, LUA_REGISTRYINDEX, 1);
Computer * retval = (Computer*)lua_touserdata(L, -1);
lua_pop(L, 1);
getCompCache->insert(std::make_pair(L->l_G, retval));
getCompCache->insert(std::make_pair(L->glref, retval));
return retval;
}
}

void uncache_state(lua_State *L) {
LockGuard lock(getCompCache);
getCompCache->erase(L->l_G);
getCompCache->erase(L->glref);
}

void load_library(Computer *comp, lua_State *L, const library_t& lib) {
Expand Down
32 changes: 12 additions & 20 deletions src/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,18 @@ class Value {
// For get_comp
struct lua_State {
void *next; uint8_t tt; uint8_t marked;
uint8_t status;
void* top; /* first free slot in the stack */
void* l_G;
void *ci; /* call info for current function */
const int *oldpc; /* last pc traced */
void* stack_last; /* last free slot in the stack */
void* stack; /* stack base */
int stacksize;
unsigned short nny; /* number of non-yieldable calls in stack */
unsigned short nCcalls; /* number of nested C calls */
uint8_t hookmask;
uint8_t allowhook;
int basehookcount;
int hookcount;
lua_Hook hook;
void *openupval; /* list of open upvalues in this stack */
void *gclist;
struct lua_longjmp *errorJmp; /* current error recover point */
ptrdiff_t errfunc; /* current error handling function (stack index) */
void* base_ci; /* CallInfo for first level (C calling Lua) */
uint8_t dummy_ffid; /* Fake FF_C for curr_funcisL() on dummy frames. */
uint8_t status; /* Thread status. */
void* glref; /* Link to global state. */
void* gclist; /* GC chain. */
void *base; /* Base of currently executing function. */
void *top; /* First free slot in the stack. */
void* maxstack; /* Last free slot in the stack. */
void* stack; /* Stack base. */
void* openupval; /* List of open upvalues in the stack. */
void* env; /* Thread environment (table of globals). */
void *cframe; /* End of C stack frame chain. */
uint32_t stacksize; /* True stack size (incl. LJ_STACK_EXTRA). */
};

inline int log2i(int num) {
Expand Down

0 comments on commit 6a028e9

Please sign in to comment.