diff --git a/log/log.c b/log/log.c index 3425670..fece9bc 100644 --- a/log/log.c +++ b/log/log.c @@ -180,7 +180,11 @@ void log_write(int log_id, int priority, const char *cat, const char *func, vsnprintf(line, LOG_MAXLINELEN, fmt, ap); now = time(NULL); + + /* localtime() isn't threadsafe, localtime_r isn't portable enough... */ + _lock_logger(); strftime(tyme, 128, "[%Y-%m-%d %H:%M:%S]", localtime(&now)); + _unlock_logger(); snprintf(pre, 256, "%s %s%s", prior[priority-1], cat, func); diff --git a/thread/thread.c b/thread/thread.c index d4e5672..26038b1 100644 --- a/thread/thread.c +++ b/thread/thread.c @@ -228,7 +228,7 @@ static void _catch_signals(void) } -long thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file) +thread_t *thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file) { int created; thread_t *thread; @@ -259,11 +259,10 @@ long thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int if (created == 0) { LOG_ERROR("System won't let me create more threads, giving up"); - return -1; + return NULL; } -// return thread->thread_id; - return thread->sys_thread; + return thread; } /* _mutex_create @@ -676,12 +675,12 @@ void thread_library_unlock(void) _mutex_unlock(&_library_mutex); } -void thread_join(long thread) +void thread_join(thread_t *thread) { void *ret; int i; - i = pthread_join(thread, &ret); + i = pthread_join(thread->sys_thread, &ret); } /* AVL tree functions */ diff --git a/thread/thread.h b/thread/thread.h index 6ab5c7b..1065e17 100644 --- a/thread/thread.h +++ b/thread/thread.h @@ -105,7 +105,7 @@ void thread_initialize_with_log_id(int log_id); void thread_shutdown(void); /* creation, destruction, locking, unlocking, signalling and waiting */ -long thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file); +thread_t *thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file); void thread_mutex_create_c(mutex_t *mutex, int line, char *file); void thread_mutex_lock_c(mutex_t *mutex, int line, char *file); void thread_mutex_unlock_c(mutex_t *mutex, int line, char *file); @@ -138,7 +138,7 @@ thread_t *thread_self(void); void thread_rename(const char *name); /* waits until thread_exit is called for another thread */ -void thread_join(long thread); +void thread_join(thread_t *thread); #endif /* __THREAD_H__ */