@@ 29,6 29,14 @@ typedef struct WorkerArgs {
pthread_t *thread; // Actual Thread
} WorkerArg;
+// MACROS
+// Multi Threading
+#define lock(i) pthread_mutex_lock(&locks[i]);
+#define unlock(i) pthread_mutex_unlock(&locks[i]);
+
+// Release i'th worker thread, is thread safe
+#define rel_thread(i) lock(FETCH_THREAD_LOCK); thread_avail[i] = 1; unlock(FETCH_THREAD_LOCK);
+
extern char *baal_home;
Server serv;
pthread_t workers[SERVER_MAX_THREADS]; // Actual thread
@@ 42,13 50,8 @@ cJSON *fetchUser(char *user); // Return user json if exists, null other whise
// Server Handlers
int register_user_handler(WorkerArg *arg, cJSON *data); // Handler for registering a user.
-
-// Multi Threading
-#define lock(i) pthread_mutex_lock(&locks[i]);
-#define unlock(i) pthread_mutex_unlock(&locks[i]);
-void *worker(void *args); // Worker thread.
-pthread_t *fetch_thread(int *id); // Attempt to fetch a thread, this is thread safe.
-void rel_thread(int i); // Release i'th worker thread
+void *worker(void *args); // Worker thread.
+pthread_t *fetch_thread(int *id); // Attempt to fetch a thread, this is thread safe.
void init_threads();
cJSON *
@@ 154,16 157,6 @@ fetch_thread(int *id)
return ret;
}
-// Release i'th worker thread, is thread safe
-// TODO. This can be macro'd
-void
-rel_thread(int i)
-{
- lock(FETCH_THREAD_LOCK);
- thread_avail[i] = 1;
- unlock(FETCH_THREAD_LOCK);
-}
-
// Init threads, locks, etc
void
init_threads()