aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-09-14 21:34:57 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-09-14 21:34:57 -0700
commit3e5252d46385ecfbf1159251d5f47a6ec490f161 (patch)
tree2f922b8e94039a17a53afdb6f3b65aa6b8b68379
parent4595de34bde9fdd4f1db8fabf2786218e36e2954 (diff)
downloadlwip-3e5252d46385ecfbf1159251d5f47a6ec490f161.tar.gz
lwip-3e5252d46385ecfbf1159251d5f47a6ec490f161.tar.xz
lwip-3e5252d46385ecfbf1159251d5f47a6ec490f161.zip
core: thread: add a name field, static declaration of semaphores
Add a name field to struct thread, for debugging's sake. Add the ability to statically declare initialized semaphores. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--core/fs/pxe/isr.c7
-rw-r--r--core/fs/pxe/pxe.c6
-rw-r--r--core/include/thread.h14
-rw-r--r--core/lwip/src/include/arch/sys_arch.h11
-rw-r--r--core/lwip/src/include/lwip/sys.h2
-rw-r--r--core/lwip/src/netif/undiif.c2
-rw-r--r--core/thread/idle_thread.c2
-rw-r--r--core/thread/root_thread.c1
-rw-r--r--core/thread/start_thread.c3
9 files changed, 38 insertions, 10 deletions
diff --git a/core/fs/pxe/isr.c b/core/fs/pxe/isr.c
index 40dc458f..e92e731c 100644
--- a/core/fs/pxe/isr.c
+++ b/core/fs/pxe/isr.c
@@ -11,7 +11,7 @@
#include <string.h>
extern uint8_t pxe_irq_pending;
-static struct semaphore pxe_receive_thread_sem;
+static DECLARE_INIT_SEMAPHORE(pxe_receive_thread_sem, 0);
static void pm_return(void)
{
@@ -27,7 +27,8 @@ static void pm_return(void)
if (pxe_irq_pending) {
pxe_irq_pending = 0;
- sem_up(&pxe_receive_thread_sem);
+ if (pxe_receive_thread_sem.count <= 0)
+ sem_up(&pxe_receive_thread_sem);
}
__schedule_lock--;
@@ -89,7 +90,7 @@ static void pxe_receive_thread(void *dummy)
void pxe_init_isr(void)
{
start_idle_thread();
- sem_init(&pxe_receive_thread_sem, 0);
+ start_thread("pxe receive", 16384, 0, pxe_receive_thread, NULL);
core_pm_hook = pm_return;
}
diff --git a/core/fs/pxe/pxe.c b/core/fs/pxe/pxe.c
index 4d081916..56037075 100644
--- a/core/fs/pxe/pxe.c
+++ b/core/fs/pxe/pxe.c
@@ -5,6 +5,7 @@
#include <minmax.h>
#include <sys/cpu.h>
#include "pxe.h"
+#include "thread.h"
#define GPXE 1
@@ -1484,8 +1485,11 @@ static void network_init(void)
*/
static int pxe_fs_init(struct fs_info *fs)
{
+ extern void pxe_init_isr(void); /* XXX */
(void)fs; /* drop the compile warning message */
-
+
+ pxe_init_isr();
+
/* Initialize the Files structure */
files_init();
diff --git a/core/include/thread.h b/core/include/thread.h
index c26e795b..75cc7e1f 100644
--- a/core/include/thread.h
+++ b/core/include/thread.h
@@ -24,9 +24,10 @@ struct sys_timeouts;
struct thread {
void *esp; /* Must be first; stack pointer */
+ const char *name; /* Name (for debugging) */
struct thread_list list;
struct thread_block *blocked;
- struct sys_timeouts *timeouts; /* For the benefit of lwIP */
+ void *pvt; /* For the benefit of lwIP */
int prio;
};
@@ -48,6 +49,15 @@ struct semaphore {
struct thread_list list;
};
+#define DECLARE_INIT_SEMAPHORE(sem, cnt) \
+ struct semaphore sem = { \
+ .count = (cnt), \
+ .list = { \
+ .next = &sem.list, \
+ .prev = &sem.list \
+ } \
+ }
+
jiffies_t sem_down(struct semaphore *, jiffies_t);
void sem_up(struct semaphore *);
void sem_init(struct semaphore *, int);
@@ -75,7 +85,7 @@ static inline void irq_restore(irq_state_t __st)
asm volatile("pushl %0 ; popfl" : : "rm" (__st));
}
-struct thread *start_thread(size_t stack_size, int prio,
+struct thread *start_thread(const char *name, size_t stack_size, int prio,
void (*start_func)(void *), void *func_arg);
void __exit_thread(void);
void kill_thread(struct thread *);
diff --git a/core/lwip/src/include/arch/sys_arch.h b/core/lwip/src/include/arch/sys_arch.h
index 735f8258..867cf314 100644
--- a/core/lwip/src/include/arch/sys_arch.h
+++ b/core/lwip/src/include/arch/sys_arch.h
@@ -15,6 +15,12 @@ typedef struct thread *sys_thread_t;
#define SYS_MBOX_NULL NULL
#define SYS_SEM_NULL NULL
+static inline sys_thread_t sys_thread_new(char *name, void (*thread)(void *),
+ void *arg, int stacksize, int prio)
+{
+ return start_thread(name, stacksize, prio, thread, arg);
+}
+
extern void __compile_time_error(void);
#define SYS_ARCH_OP(var, val, inc, add) \
@@ -52,6 +58,11 @@ do { \
} \
} while (0)
+static inline struct sys_timeouts *sys_arch_timeouts(void)
+{
+ return (struct sys_timeouts *)&current()->pvt;
+}
+
#define SYS_ARCH_INC(var, val) SYS_ARCH_OP(var, val, "inc", "add")
#define SYS_ARCH_DEC(var, val) SYS_ARCH_OP(var, val, "dec", "sub")
diff --git a/core/lwip/src/include/lwip/sys.h b/core/lwip/src/include/lwip/sys.h
index 0cc84ddf..5c04d2f3 100644
--- a/core/lwip/src/include/lwip/sys.h
+++ b/core/lwip/src/include/lwip/sys.h
@@ -104,7 +104,7 @@ void sys_init(void);
*/
void sys_timeout(u32_t msecs, sys_timeout_handler h, void *arg);
void sys_untimeout(sys_timeout_handler h, void *arg);
-struct sys_timeouts *sys_arch_timeouts(void);
+//struct sys_timeouts *sys_arch_timeouts(void);
/* Semaphore functions. */
sys_sem_t sys_sem_new(u8_t count);
diff --git a/core/lwip/src/netif/undiif.c b/core/lwip/src/netif/undiif.c
index 01a021d5..1aa45ef6 100644
--- a/core/lwip/src/netif/undiif.c
+++ b/core/lwip/src/netif/undiif.c
@@ -218,7 +218,7 @@ low_level_input(t_PXENV_UNDI_ISR *isr)
* available data in the pbuf is given by the q->len
* variable.
*/
- char *s;
+ char *s = q->payload;
int ql = q->len;
while (ql) {
diff --git a/core/thread/idle_thread.c b/core/thread/idle_thread.c
index 5c79e316..c5db9f4a 100644
--- a/core/thread/idle_thread.c
+++ b/core/thread/idle_thread.c
@@ -15,6 +15,6 @@ static void idle_thread_func(void *dummy)
void start_idle_thread(void)
{
- start_thread(4096, INT_MAX, idle_thread_func, NULL);
+ start_thread("idle", 4096, INT_MAX, idle_thread_func, NULL);
}
diff --git a/core/thread/root_thread.c b/core/thread/root_thread.c
index c5efd65b..60f34927 100644
--- a/core/thread/root_thread.c
+++ b/core/thread/root_thread.c
@@ -1,6 +1,7 @@
#include "thread.h"
struct thread __root_thread = {
+ .name = "root",
.list = { .next = &__root_thread.list, .prev = &__root_thread.list },
.blocked = NULL,
.prio = 0,
diff --git a/core/thread/start_thread.c b/core/thread/start_thread.c
index 29e99722..5486e562 100644
--- a/core/thread/start_thread.c
+++ b/core/thread/start_thread.c
@@ -13,7 +13,7 @@ struct thread_stack {
void (*eip)(void);
};
-struct thread *start_thread(size_t stack_size, int prio,
+struct thread *start_thread(const char *name, size_t stack_size, int prio,
void (*start_func)(void *), void *func_arg)
{
irq_state_t irq;
@@ -42,6 +42,7 @@ struct thread *start_thread(size_t stack_size, int prio,
sp->ebx = irq_state(); /* Inherit the IRQ state from the spawner */
sp->eip = __start_thread;
t->prio = prio;
+ t->name = name;
irq = irq_save();
curr = current();