Start dirmonitor check thread only after a watch is added (#1072)

This commit is contained in:
Guldoman 2022-07-11 23:14:50 +02:00 committed by GitHub
parent e646f2fb28
commit 86024586fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -63,8 +63,6 @@ static int f_dirmonitor_new(lua_State* L) {
luaL_setmetatable(L, API_TYPE_DIRMONITOR);
memset(monitor, 0, sizeof(struct dirmonitor));
monitor->internal = init_dirmonitor();
if (monitor->internal)
monitor->thread = SDL_CreateThread(dirmonitor_check_thread, "dirmonitor_check_thread", monitor);
return 1;
}
@ -83,7 +81,10 @@ static int f_dirmonitor_gc(lua_State* L) {
static int f_dirmonitor_watch(lua_State *L) {
lua_pushnumber(L, add_dirmonitor(((struct dirmonitor*)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR))->internal, luaL_checkstring(L, 2)));
struct dirmonitor* monitor = luaL_checkudata(L, 1, API_TYPE_DIRMONITOR);
lua_pushnumber(L, add_dirmonitor(monitor->internal, luaL_checkstring(L, 2)));
if (!monitor->thread)
monitor->thread = SDL_CreateThread(dirmonitor_check_thread, "dirmonitor_check_thread", monitor);
return 1;
}
@ -97,7 +98,7 @@ static int f_dirmonitor_unwatch(lua_State *L) {
static int f_dirmonitor_check(lua_State* L) {
struct dirmonitor* monitor = luaL_checkudata(L, 1, API_TYPE_DIRMONITOR);
SDL_LockMutex(monitor->mutex);
if (monitor->length < 0)
if (monitor->length < 0)
lua_pushnil(L);
else if (monitor->length > 0) {
if (translate_changes_dirmonitor(monitor->internal, monitor->buffer, monitor->length, f_check_dir_callback, L) == 0)