common.h: move common code (non-user) to header
authorBrian Norris <banorris@uci.edu>
Sat, 10 Mar 2012 01:37:05 +0000 (17:37 -0800)
committerBrian Norris <banorris@uci.edu>
Sat, 10 Mar 2012 01:38:48 +0000 (17:38 -0800)
Enable us to include libthreads.h in a "user program".

Makefile
common.h [new file with mode: 0644]
libthreads.c
libthreads.h
schedule.c

index 49994aca16dd05804c52b676bd8d4182d8ab3fd9..fc75543c3d814547a74ea94f45ea4a4d5a6610e3 100644 (file)
--- 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 (file)
index 0000000..79f42eb
--- /dev/null
+++ b/common.h
@@ -0,0 +1,16 @@
+#ifndef __CONFIG_H__
+#define __CONFIG_H__
+
+#include <stdio.h>
+
+//#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__ */
index 2e3474aaa881b0c460e3cc0e150b5fbcb7461545..3eae58fca24da4556c9dfb993faba81105e91f0b 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 
 #include "libthreads.h"
+#include "common.h"
 
 #define STACK_SIZE (1024 * 1024)
 
index b73ab1c0cee46fc063c42d703f2b8e922d0d5210..0201ea616eb8842f4f3e86a2d7001421a3cb8252 100644 (file)
@@ -1,19 +1,8 @@
 #ifndef __LIBTHREADS_H__
 #define __LIBTHREADS_H__
 
-#include <stdio.h>
 #include <ucontext.h>
 
-//#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;
index a4613c597f95d3362888df1ba6051fbbb1d75a58..10e7fdc181499c2ef2142ad609b3902e00075edd 100644 (file)
@@ -1,4 +1,5 @@
 #include "schedule.h"
+#include "common.h"
 
 struct thread_list_node {
        struct thread *this;