Skip to content

Commit

Permalink
Merge pull request #5061 from lethosor/le/lua-lock-recursive
Browse files Browse the repository at this point in the history
Lua: switch to recursive mutex in lua_lock()
  • Loading branch information
myk002 authored Dec 1, 2024
2 parents c0f208a + 7c1713f commit acb24ba
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions depends/lua/include/dfhack_llimits.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@ struct lua_extra_state {
#define lua_lock(L) EnterCriticalSection(luai_mutex(L))
#define lua_unlock(L) LeaveCriticalSection(luai_mutex(L))
#else
#define luai_userstateopen(L) luai_mutex(L) = (mutex_t*)malloc(sizeof(mutex_t)); *luai_mutex(L) = PTHREAD_MUTEX_INITIALIZER
#define luai_userstateclose(L) lua_unlock(L); pthread_mutex_destroy(luai_mutex(L)); free(luai_mutex(L))
#define luai_userstateopen(L) do { \
luai_mutex(L) = (mutex_t*)malloc(sizeof(mutex_t)); \
pthread_mutexattr_t attr; \
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
pthread_mutex_init(luai_mutex(L), &attr); \
} while (0)
#define luai_userstateclose(L) do { \
lua_unlock(L); \
pthread_mutex_destroy(luai_mutex(L)); \
free(luai_mutex(L)); \
} while (0)
#define lua_lock(L) pthread_mutex_lock(luai_mutex(L))
#define lua_unlock(L) pthread_mutex_unlock(luai_mutex(L))
#endif

0 comments on commit acb24ba

Please sign in to comment.