BIN=libthreads
SOURCE=libthreads.c
+HEADERS=libthreads.h
FLAGS=
all: ${BIN}
-${BIN}: ${SOURCE}
+${BIN}: ${SOURCE} ${HEADERS}
gcc -o ${BIN} ${SOURCE} ${FLAGS}
clean:
#include <string.h>
#include <stdlib.h>
#include <ucontext.h>
-#include <stdio.h>
//#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)
-struct thread {
- void (*start_routine);
- void *arg;
- ucontext_t context;
- void *stack;
- int index;
-};
-
static struct thread *current;
static ucontext_t *cleanup;
--- /dev/null
+#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);