aboutsummaryrefslogtreecommitdiff
path: root/src/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread.c')
-rw-r--r--src/thread.c65
1 files changed, 0 insertions, 65 deletions
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);