From 77a371ec23b0ecf13b002df2d28461d88b5785cc Mon Sep 17 00:00:00 2001 From: ame Date: Tue, 28 Oct 2025 17:38:31 -0500 Subject: remove tlock, tunlock --- library/lullaby/thread.lua | 10 ------- src/thread.c | 65 ---------------------------------------------- src/thread.h | 4 --- 3 files changed, 79 deletions(-) diff --git a/library/lullaby/thread.lua b/library/lullaby/thread.lua index ca0f1be..7a1888c 100644 --- a/library/lullaby/thread.lua +++ b/library/lullaby/thread.lua @@ -61,16 +61,6 @@ function buffer.mod(T, fun) end ---@return buffer-table function thread.buffer(value) end ----locks any thread reaching this lock id until a corresponding unlock is met ----@param tid integer ----@return nil -function thread.lock(tid) end - ----unlocks a lock id ----@param tid integer ----@return nil -function thread.unlock(tid) end - ---@deprecated function thread.testcopy() end diff --git a/src/thread.c b/src/thread.c index 7d48bda..2a2de39 100644 --- a/src/thread.c +++ b/src/thread.c @@ -23,71 +23,6 @@ struct thread_info { #include "io.h" -//give the current thread priority to locking thread_lock_lock (fixes race conds) -pthread_mutex_t thread_priority_lock = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; -pthread_mutex_t thread_lock_lock = (pthread_mutex_t)PTHREAD_MUTEX_INITIALIZER; -larray_t* thread_locks = NULL; - -void lib_thread_clean(){ - if(thread_locks == NULL) return; - - for(int i = 0; i != thread_locks->size; i++){ - if(thread_locks->arr[i].used){ - //pthread_mutex_destroy(thread_locks->arr[i].value); - free(thread_locks->arr[i].value); - } - } - - larray_clear(thread_locks); -} -int l_tlock(lua_State* L){ - int idx = luaL_checkinteger(L, 1); - - pthread_mutex_lock(&thread_lock_lock); - //pthread_mutex_lock(&thread_priority_lock); - //pthread_mutex_unlock(&thread_priority_lock); - pthread_mutex_t mutex; - if(thread_locks == NULL) thread_locks = larray_init(); - int i = 0; - if((i = larray_geti(thread_locks, idx)) == -1){ - pthread_mutex_init(&mutex, NULL); - pthread_mutex_lock(&mutex); - pthread_mutex_t* mp = malloc(sizeof * mp); - *mp = mutex; - larray_set(&thread_locks, idx, (void*)mp); - } else { - pthread_mutex_t *m = (pthread_mutex_t*)thread_locks->arr[i].value; - pthread_mutex_lock(&thread_priority_lock); - - pthread_mutex_unlock(&thread_lock_lock); - pthread_mutex_lock(m); - pthread_mutex_lock(&thread_lock_lock); - - pthread_mutex_unlock(&thread_priority_lock); - thread_locks->arr[i].value = (void*)m; - - } - - pthread_mutex_unlock(&thread_lock_lock); - return 0; -} - -int l_tunlock(lua_State* L){ - int idx = luaL_checkinteger(L, 1); - - pthread_mutex_lock(&thread_lock_lock); - int i = 0; - if(thread_locks != NULL && (i = larray_geti(thread_locks, idx)) != -1){ - pthread_mutex_t *m = (pthread_mutex_t*)thread_locks->arr[i].value; - - pthread_mutex_unlock(m); - thread_locks->arr[i].value = (void*)m; - } - - pthread_mutex_unlock(&thread_lock_lock); - return 0; -} - int _mutex_lock(lua_State* L){ lua_pushstring(L, "_"); lua_gettable(L, 1); diff --git a/src/thread.h b/src/thread.h index 4fa0e04..f0435eb 100644 --- a/src/thread.h +++ b/src/thread.h @@ -6,8 +6,6 @@ #endif int l_async(lua_State*); -int l_tlock(lua_State*); -int l_tunlock(lua_State*); int l_buffer(lua_State*); int l_testcopy(lua_State*); int l_mutex(lua_State*); @@ -18,8 +16,6 @@ void lib_thread_clean(); static const luaL_Reg thread_function_list [] = { {"async",l_async}, - {"lock",l_tlock}, - {"unlock",l_tunlock}, {"buffer",l_buffer}, {"testcopy",l_testcopy}, {"mutex", l_mutex}, -- cgit v1.2.3