Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/lfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,12 @@ static void unlinkupval (UpVal *uv) {

void luaF_freeupval(lua_State *L, UpVal *uv)
{
if (uv->v != &uv->u.value) /* is it open? */
if (uv->v != &uv->u.value) { /* is it open? */
/* Block collector to prevent race with global trace traversing openupval */
luaC_blockcollector(L);
unlinkupval(uv); /* remove from open list */
luaC_unblockcollector(L);
}
luaM_free(L, LUA_MEM_UPVAL, uv); /* free upvalue */
}

Expand All @@ -144,6 +148,8 @@ void luaF_close (lua_State *L, StkId level) {
#if DEBUG_UPVAL
printf("close upval >= level %p\n", level);
#endif
/* Block collector to prevent race with global trace traversing openupval */
luaC_blockcollector(L);
while (L->openupval.u.l.next != &L->openupval &&
(uv = L->openupval.u.l.next)->v >= level) {
lua_assert(uv->v != &uv->u.value);
Expand All @@ -156,6 +162,7 @@ void luaF_close (lua_State *L, StkId level) {
// setobj(L, &uv->u.value, uv->v);
// luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */
}
luaC_unblockcollector(L);
#if DEBUG_UPVAL
dumpopenupvals(L);
#endif
Expand Down
7 changes: 7 additions & 0 deletions src/lgc.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ static INLINE int try_block_mutators(lua_State *L)
{
uint32_t pending;
thr_State *pt;
int *recursion = get_recursion();

/* For the non-signal thread stoppage, take a write lock. Important that
* we do this before setting intend to stop, as we acquire the write
Expand All @@ -352,6 +353,8 @@ static INLINE int try_block_mutators(lua_State *L)
pthread_rwlock_wrlock(&trace_rwlock);
}

(*recursion)++;

/* advertise our intent to stop everyone; this prevents any mutators
* from returning from their respective barriers */
ck_pr_store_32(&G(L)->intend_to_stop, 1);
Expand Down Expand Up @@ -401,6 +404,10 @@ static INLINE int try_block_mutators(lua_State *L)

static INLINE void unblock_mutators(lua_State *L)
{
int *recursion = get_recursion();

(*recursion)--;

ck_pr_store_32(&G(L)->intend_to_stop, 0);
ck_pr_fence_memory();

Expand Down