libthreads: create header file
authorBrian Norris <banorris@uci.edu>
Thu, 8 Mar 2012 23:41:34 +0000 (15:41 -0800)
committerBrian Norris <banorris@uci.edu>
Thu, 8 Mar 2012 23:42:05 +0000 (15:42 -0800)
Makefile
libthreads.c
libthreads.h [new file with mode: 0644]

index 25b9459a8cfa0176d8b9f61f7ae4405f8d36a4cb..1867a44479b5e75d06e6ea85b037321b3a33e41c 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,11 @@
 BIN=libthreads
 SOURCE=libthreads.c
 BIN=libthreads
 SOURCE=libthreads.c
+HEADERS=libthreads.h
 FLAGS=
 
 all: ${BIN}
 
 FLAGS=
 
 all: ${BIN}
 
-${BIN}: ${SOURCE}
+${BIN}: ${SOURCE} ${HEADERS}
        gcc -o ${BIN} ${SOURCE} ${FLAGS}
 
 clean:
        gcc -o ${BIN} ${SOURCE} ${FLAGS}
 
 clean:
index 4545ee3640a79a542e1c61f199bd37853c4c9231..5ede8d7eafa5a7cf0e32f740434872c5f9c82987 100644 (file)
@@ -1,28 +1,13 @@
 #include <string.h>
 #include <stdlib.h>
 #include <ucontext.h>
 #include <string.h>
 #include <stdlib.h>
 #include <ucontext.h>
-#include <stdio.h>
 
 //#define CONFIG_DEBUG
 
 
 //#define CONFIG_DEBUG
 
-#ifdef CONFIG_DEBUG
-#define DBG() do { printf("Here: %s, L%d\n", __func__, __LINE__); } while (0)
-#define DEBUG(fmt, ...) printf(fmt, ##__VA_ARGS__)
-#else
-#define DBG()
-#define DEBUG(fmt, ...)
-#endif
+#include "libthreads.h"
 
 #define STACK_SIZE (1024 * 1024)
 
 
 #define STACK_SIZE (1024 * 1024)
 
-struct thread {
-       void (*start_routine);
-       void *arg;
-       ucontext_t context;
-       void *stack;
-       int index;
-};
-
 static struct thread *current;
 static ucontext_t *cleanup;
 
 static struct thread *current;
 static ucontext_t *cleanup;
 
diff --git a/libthreads.h b/libthreads.h
new file mode 100644 (file)
index 0000000..8522871
--- /dev/null
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+#ifdef CONFIG_DEBUG
+#define DBG() do { printf("Here: %s, L%d\n", __func__, __LINE__); } while (0)
+#define DEBUG(fmt, ...) printf(fmt, ##__VA_ARGS__)
+#else
+#define DBG()
+#define DEBUG(fmt, ...)
+#endif
+
+struct thread {
+       void (*start_routine);
+       void *arg;
+       ucontext_t context;
+       void *stack;
+       int index;
+};
+
+int thread_create(struct thread *t, void (*start_routine), void *arg);
+void thread_start(struct thread *t);