From 60e0a49ba320b32b9cc0d2f8d73c8d95c92fc0ba Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Fri, 9 Mar 2012 17:37:05 -0800 Subject: [PATCH] common.h: move common code (non-user) to header Enable us to include libthreads.h in a "user program". --- Makefile | 2 +- common.h | 16 ++++++++++++++++ libthreads.c | 1 + libthreads.h | 11 ----------- schedule.c | 1 + 5 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 common.h diff --git a/Makefile b/Makefile index 49994ac..fc75543 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ BIN=libthreads SOURCE=libthreads.c schedule.c -HEADERS=libthreads.h schedule.h +HEADERS=libthreads.h schedule.h common.h FLAGS= all: ${BIN} diff --git a/common.h b/common.h new file mode 100644 index 0000000..79f42eb --- /dev/null +++ b/common.h @@ -0,0 +1,16 @@ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +#include + +//#define CONFIG_DEBUG + +#ifdef CONFIG_DEBUG +#define DEBUG(fmt, ...) do { printf("*** %25s(): line %-4d *** " fmt, __func__, __LINE__, ##__VA_ARGS__); } while (0) +#define DBG() DEBUG("\n"); +#else +#define DEBUG(fmt, ...) +#define DBG() +#endif + +#endif /* __CONFIG_H__ */ diff --git a/libthreads.c b/libthreads.c index 2e3474a..3eae58f 100644 --- a/libthreads.c +++ b/libthreads.c @@ -2,6 +2,7 @@ #include #include "libthreads.h" +#include "common.h" #define STACK_SIZE (1024 * 1024) diff --git a/libthreads.h b/libthreads.h index b73ab1c..0201ea6 100644 --- a/libthreads.h +++ b/libthreads.h @@ -1,19 +1,8 @@ #ifndef __LIBTHREADS_H__ #define __LIBTHREADS_H__ -#include #include -//#define CONFIG_DEBUG - -#ifdef CONFIG_DEBUG -#define DEBUG(fmt, ...) do { printf("*** %25s(): line %-4d *** " fmt, __func__, __LINE__, ##__VA_ARGS__); } while (0) -#define DBG() DEBUG("\n"); -#else -#define DEBUG(fmt, ...) -#define DBG() -#endif - struct thread { void (*start_routine); void *arg; diff --git a/schedule.c b/schedule.c index a4613c5..10e7fdc 100644 --- a/schedule.c +++ b/schedule.c @@ -1,4 +1,5 @@ #include "schedule.h" +#include "common.h" struct thread_list_node { struct thread *this; -- 2.34.1