From a51b890508f152c81067db4989f887353ba0a789 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 3 Sep 2021 16:53:58 -0700 Subject: [PATCH] ... --- inc/log.h | 4 +--- inc/setup.h | 8 ++++++++ src/default.c | 4 ---- src/log.c | 9 ++++++++- src/main.c | 3 +++ src/setup.c | 8 ++++++++ 6 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 inc/setup.h create mode 100644 src/setup.c diff --git a/inc/log.h b/inc/log.h index 3ecca33..08dcf18 100644 --- a/inc/log.h +++ b/inc/log.h @@ -3,7 +3,6 @@ #include #include -#include extern int verbose_flag; @@ -14,13 +13,12 @@ enum log_level { LOG_LEVEL_VERBOSE = 3 /* logging and debugging info */ }; -extern thrd_t logging_thread; - #define log_err(...) log_enqueue(LOG_LEVEL_ERRORS,stderr,__VA_ARGS__) #define log_info(...) log_enqueue(LOG_LEVEL_VERBOSE,stdout,__VA_ARGS__) #define log_msg(...) log_enqueue(LOG_LEVEL_DEFAULT,stdout,__VA_ARGS__) void log_enqueue(enum log_level,FILE*,const char*,...); void log_message(enum log_level,FILE*,const char*,...); +void log_poll(); #endif diff --git a/inc/setup.h b/inc/setup.h new file mode 100644 index 0000000..9077be8 --- /dev/null +++ b/inc/setup.h @@ -0,0 +1,8 @@ +#ifndef __SETUP_H_ +#define __SETUP_H_ + +#include + +int setup(); + +#endif diff --git a/src/default.c b/src/default.c index 262fd21..b891dc4 100644 --- a/src/default.c +++ b/src/default.c @@ -1,10 +1,6 @@ #include -thrd_t logging_thread; - int defaults() { - logging_thread = thrd_current(); - opt_set_log_level(LOG_LEVEL_DEFAULT); return 1; diff --git a/src/log.c b/src/log.c index 5c73ef5..38691a2 100644 --- a/src/log.c +++ b/src/log.c @@ -12,7 +12,7 @@ void log_enqueue(enum log_level level, FILE *out_stream, const char *format,...) void log_message(enum log_level level, FILE *out_stream, const char *format,...) { if(level>verbose_flag) { return; } - if(thrd_equal(logging_thread,thrd_current)) { + if(thrd_equal(logging_thread,thrd_current())) { va_list args; va_start(args,format); vfprintf(out_stream,message); @@ -21,3 +21,10 @@ void log_message(enum log_level level, FILE *out_stream, const char *format,...) log_enqueue(level,out_stream,format,...); } } + +int log_poll(void *arg) { + while(1) { + } + + return 1; +} diff --git a/src/main.c b/src/main.c index 84740b5..97a854b 100644 --- a/src/main.c +++ b/src/main.c @@ -40,5 +40,8 @@ int main(int argc, char **argv) { log_msg("here?\n"); + if(setup()<0) { return EXIT_FAILURE; } + + log_msg("here!\n"); return EXIT_FAILURE; } diff --git a/src/setup.c b/src/setup.c new file mode 100644 index 0000000..b71171c --- /dev/null +++ b/src/setup.c @@ -0,0 +1,8 @@ +#include + +int setup() { + if(pthread_create(&logging_thread,&log_poll)!=0) { + perror("pthread_create"); + return -1; + } +} -- 2.30.2