[kernel] simple thread local storage
diff --git a/include/kernel/thread.h b/include/kernel/thread.h
index 99a6c41..0bd286a 100644
--- a/include/kernel/thread.h
+++ b/include/kernel/thread.h
@@ -40,6 +40,11 @@
typedef int (*thread_start_routine)(void *arg);
+/* thread local storage */
+enum thread_tls_list {
+ MAX_TLS_ENTRY
+};
+
#define THREAD_MAGIC 'thrd'
typedef struct thread {
@@ -71,6 +76,9 @@
/* return code */
int retcode;
+ /* thread local storage */
+ uint32_t tls[MAX_TLS_ENTRY];
+
char name[32];
} thread_t;
@@ -140,6 +148,19 @@
static inline void inc_critical_section(void) { critical_section_count++; }
static inline void dec_critical_section(void) { critical_section_count--; }
+/* thread local storage */
+static inline __ALWAYS_INLINE uint32_t tls_get(uint entry)
+{
+ return current_thread->tls[entry];
+}
+
+static inline __ALWAYS_INLINE uint32_t tls_set(uint entry, uint32_t val)
+{
+ uint32_t oldval = current_thread->tls[entry];
+ current_thread->tls[entry] = val;
+ return oldval;
+}
+
/* wait queue stuff */
#define WAIT_QUEUE_MAGIC 'wait'
diff --git a/kernel/thread.c b/kernel/thread.c
index fc9d9ca..1a23478 100644
--- a/kernel/thread.c
+++ b/kernel/thread.c
@@ -122,6 +122,11 @@
t->stack_size = stack_size;
+ /* inheirit thread local storage from the parent */
+ int i;
+ for (i=0; i < MAX_TLS_ENTRY; i++)
+ t->tls[i] = current_thread->tls[i];
+
/* set up the initial stack frame */
arch_thread_initialize(t);
@@ -456,6 +461,12 @@
dprintf(INFO, "\tstack %p, stack_size %zd\n", t->stack, t->stack_size);
dprintf(INFO, "\tentry %p, arg %p\n", t->entry, t->arg);
dprintf(INFO, "\twait queue %p, wait queue ret %d\n", t->blocking_wait_queue, t->wait_queue_block_ret);
+ dprintf(INFO, "\ttls:");
+ int i;
+ for (i=0; i < MAX_TLS_ENTRY; i++) {
+ dprintf(INFO, " 0x%x", t->tls[i]);
+ }
+ dprintf(INFO, "\n");
}
void dump_all_threads(void)