diff --git a/src/sys/include/ubixos/ubthread.h b/src/sys/include/ubixos/ubthread.h index ee33f01..d86915a 100644 --- a/src/sys/include/ubixos/ubthread.h +++ b/src/sys/include/ubixos/ubthread.h @@ -25,7 +25,7 @@ $Id: ubthread.h 79 2016-01-11 16:21:27Z reddawg $ -*****************************************************************************************/ + *****************************************************************************************/ #ifndef _UBTHREAD_H #define _UBTHREAD_H @@ -42,47 +42,48 @@ #define LOCKED 1 #define UNLOCKED 0 -typedef struct ubthread *ubthread_t; -typedef struct ubthread_cond *ubthread_cond_t; +typedef struct ubthread *ubthread_t; +typedef struct ubthread_cond *ubthread_cond_t; typedef struct ubthread_mutex *ubthread_mutex_t; struct ubthread { - kTask_t *task; - }; + kTask_t *task; +}; struct ubthread_cond { - int id; - _Atomic bool lock; - }; + int id; + //_Atomic bool lock; + bool lock; +}; struct ubthread_mutex { - int id; - _Atomic bool lock; - pidType pid; - }; + int id; + //_Atomic bool lock; + bool lock; + pidType pid; +}; struct ubthread_list { - struct ubthread_list *next; - ubthread_t thread; - }; + struct ubthread_list *next; + ubthread_t thread; +}; struct ubthread_cond_list { - struct ubthread_cond_list *next; - ubthread_cond_t *cond; - }; + struct ubthread_cond_list *next; + ubthread_cond_t *cond; +}; struct ubthread_mutex_list { - struct ubthread_mutex_list *next; - ubthread_mutex_t *mutex; - }; - + struct ubthread_mutex_list *next; + ubthread_mutex_t *mutex; +}; kTask_t *ubthread_self(); -int ubthread_cond_init(ubthread_cond_t *cond,const uInt32 attr); -int ubthread_mutex_init(ubthread_mutex_t *mutex,const uInt32 attr); +int ubthread_cond_init(ubthread_cond_t *cond, const uInt32 attr); +int ubthread_mutex_init(ubthread_mutex_t *mutex, const uInt32 attr); int ubthread_cond_destroy(ubthread_cond_t *cond); int ubthread_mutex_destroy(ubthread_mutex_t *mutex); -int ubthread_create(kTask_t **thread,const uInt32 *attr,void (* tproc)(void), void *arg); +int ubthread_create(kTask_t **thread, const uInt32 *attr, void (*tproc)(void), void *arg); int ubthread_mutex_lock(ubthread_mutex_t *mutex); int ubthread_mutex_unlock(ubthread_mutex_t *mutex); int ubthread_cond_timedwait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime); @@ -90,24 +91,3 @@ int ubthread_cond_signal(ubthread_cond_t *cond); #endif - -/*** - $Log: ubthread.h,v $ - Revision 1.1.1.1 2006/06/01 12:46:14 reddawg - ubix2 - - Revision 1.2 2005/10/12 00:13:37 reddawg - Removed - - Revision 1.1.1.1 2005/09/26 17:23:57 reddawg - no message - - Revision 1.3 2004/09/07 20:58:35 reddawg - time to roll back i can't think straight by friday - - Revision 1.2 2004/05/21 15:20:00 reddawg - Cleaned up - - - END - ***/ diff --git a/src/sys/kernel/ubthread.c b/src/sys/kernel/ubthread.c index 7200ae8..ef3329c 100644 --- a/src/sys/kernel/ubthread.c +++ b/src/sys/kernel/ubthread.c @@ -25,7 +25,7 @@ $Id: ubthread.c 54 2016-01-11 01:29:55Z reddawg $ -*****************************************************************************************/ + *****************************************************************************************/ /* All these must be converted to be done atomically */ @@ -38,125 +38,124 @@ #include #include - struct ubthread_cond_list *conds = 0x0; struct ubthread_mutex_list *mutex = 0x0; kTask_t *ubthread_self() { - return(_current); - } + return (_current); +} -int ubthread_cond_init(ubthread_cond_t *cond,const uint32_t attr) { - ubthread_cond_t ubcond = kmalloc(sizeof(struct ubthread_cond)); +int ubthread_cond_init(ubthread_cond_t *cond, const uint32_t attr) { + ubthread_cond_t ubcond = kmalloc(sizeof(struct ubthread_cond)); memset(ubcond, 0x0, sizeof(struct ubthread_cond)); - ubcond->id = (int)cond; + ubcond->id = (int) cond; ubcond->lock = ATOMIC_VAR_INIT(0); *cond = ubcond; - return(0x0); - } + return (0x0); +} -int ubthread_mutex_init(ubthread_mutex_t *mutex,const uint32_t attr) { +int ubthread_mutex_init(ubthread_mutex_t *mutex, const uint32_t attr) { ubthread_mutex_t ubmutex = kmalloc(sizeof(struct ubthread_mutex)); memset(ubmutex, 0x0, sizeof(struct ubthread_mutex)); - ubmutex->id = (int)mutex; + ubmutex->id = (int) mutex; ubmutex->lock = ATOMIC_VAR_INIT(0); *mutex = ubmutex; - return(0x0); - } + return (0x0); +} int ubthread_cond_destroy(ubthread_cond_t *cond) { kfree(*cond); *cond = 0x0; - return(0x0); - } + return (0x0); +} int ubthread_mutex_destroy(ubthread_mutex_t *mutex) { kfree(*mutex); *mutex = 0x0; - return(0x0); - } + return (0x0); +} -int ubthread_create(kTask_t **thread,const uInt32 *attr,void (* tproc)(void), void *arg) { - *thread = (void *)execThread(tproc,(int)(kmalloc(0x2000)+0x2000),arg); - return(0x0); - } +int ubthread_create(kTask_t **thread, const uInt32 *attr, void (*tproc)(void), void *arg) { + *thread = (void *) execThread(tproc, (int) (kmalloc(0x2000) + 0x2000), arg); + return (0x0); +} int ubthread_mutex_lock(ubthread_mutex_t *mutex) { ubthread_mutex_t ubmutex = *mutex; - if (ubmutex->lock == true && ubmutex->pid != _current->id) { - kprintf("Mutex Already Lock By PID %x Wiating To Be Relocked By %x\n",ubmutex->pid,_current->id); + if (ubmutex->lock == TRUE && ubmutex->pid != _current->id) { + kprintf("Mutex Already Lock By PID %x Wiating To Be Relocked By %x\n", ubmutex->pid, _current->id); while (1) { - if (!xchg_32(&ubmutex->lock, true)) + if (!xchg_32(&ubmutex->lock, TRUE)) break; - while (ubmutex->lock == true) - sched_yield(); + while (ubmutex->lock == TRUE) + sched_yield(); } - } - else if (ubmutex->lock == true && ubmutex->pid == _current->id) { - kprintf("Mutex Already Locked By This Thread"); - return(0x0); } - + else if (ubmutex->lock == TRUE && ubmutex->pid == _current->id) { + kprintf("Mutex Already Locked By This Thread"); + return (0x0); + } ubmutex->pid = _current->id; - return(0x0); - } + return (0x0); +} int ubthread_mutex_unlock(ubthread_mutex_t *mutex) { ubthread_mutex_t ubmutex = *mutex; - if (ubmutex->pid == _current->id) { - while(xchg_32(&ubmutex->lock, false)) + if (ubmutex->pid == _current->id) { + while (xchg_32(&ubmutex->lock, FALSE)) sched_yield(); - return(0x0); - } + return (0x0); + } else { - kprintf("Trying To Unlock Mutex From No Locking Thread[%i - %i:0x%X]\n", ubmutex->pid, _current->id,*ubmutex); + kprintf("Trying To Unlock Mutex From No Locking Thread[%i - %i:0x%X]\n", ubmutex->pid, _current->id, *ubmutex); while (ubmutex->pid != _current->id) sched_yield(); kprintf("GOT IT UNLOCKING"); - while (!xchg_32(&ubmutex->lock, false)) + while (!xchg_32(&ubmutex->lock, FALSE)) sched_yield(); - return(0x0); - } + return (0x0); } +} int ubthread_cond_timedwait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime) { - ubthread_cond_t ubcond = *cond; + ubthread_cond_t ubcond = *cond; ubthread_mutex_t ubmutex = *mutex; - uint32_t enterTime = systemVitals->sysUptime+20; + uint32_t enterTime = systemVitals->sysUptime + 20; ubthread_mutex_unlock(mutex); while (enterTime > systemVitals->sysUptime) { - if (ubcond->lock == false) break; + if (ubcond->lock == FALSE) + break; sched_yield(); - } + } ubthread_mutex_lock(mutex); - return(0x0); - } - + return (0x0); +} int ubthread_cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex) { ubthread_cond_t ubcond = *cond; ubthread_mutex_unlock(mutex); - while (ubcond->lock == true) sched_yield(); + while (ubcond->lock == TRUE) + sched_yield(); ubthread_mutex_lock(mutex); - return(0x0); + return (0x0); } int ubthread_cond_signal(ubthread_cond_t *cond) { ubthread_cond_t ubcond = *cond; - while (xchg_32(&ubcond->lock, false)) + while (xchg_32(&ubcond->lock, FALSE)) sched_yield(); - return(0x0); - } + return (0x0); +} diff --git a/src/sys/net/api/tcpip.c b/src/sys/net/api/tcpip.c index d29a8d1..0a55a9d 100644 --- a/src/sys/net/api/tcpip.c +++ b/src/sys/net/api/tcpip.c @@ -83,9 +83,7 @@ * * @param arg unused argument */ -static void -tcpip_thread(void *arg) -{ +static void tcpip_thread(void *arg) { struct tcpip_msg *msg; LWIP_UNUSED_ARG(arg); @@ -94,11 +92,11 @@ } LOCK_TCPIP_CORE(); - while (1) { /* MAIN Loop */ + while (1) { /* MAIN Loop */ UNLOCK_TCPIP_CORE(); LWIP_TCPIP_THREAD_ALIVE(); /* wait for a message, timeouts are processed while waiting */ - TCPIP_MBOX_FETCH(&mbox, (void **)&msg); + TCPIP_MBOX_FETCH(&mbox, (void ** )&msg); LOCK_TCPIP_CORE(); if (msg == NULL) { LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: NULL\n")); @@ -107,11 +105,11 @@ } switch (msg->type) { #if !LWIP_TCPIP_CORE_LOCKING - case TCPIP_MSG_API: + case TCPIP_MSG_API: LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API message %p\n", (void *)msg)); msg->msg.api_msg.function(msg->msg.api_msg.msg); break; - case TCPIP_MSG_API_CALL: + case TCPIP_MSG_API_CALL: LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: API CALL message %p\n", (void *)msg)); msg->msg.api_call.arg->err = msg->msg.api_call.function(msg->msg.api_call.arg); sys_sem_signal(msg->msg.api_call.sem); @@ -119,40 +117,40 @@ #endif /* !LWIP_TCPIP_CORE_LOCKING */ #if !LWIP_TCPIP_CORE_LOCKING_INPUT - case TCPIP_MSG_INPKT: - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg)); - msg->msg.inp.input_fn(msg->msg.inp.p, msg->msg.inp.netif); - memp_free(MEMP_TCPIP_MSG_INPKT, msg); + case TCPIP_MSG_INPKT: + LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: PACKET %p\n", (void *)msg)); + msg->msg.inp.input_fn(msg->msg.inp.p, msg->msg.inp.netif); + memp_free(MEMP_TCPIP_MSG_INPKT, msg); break; #endif /* !LWIP_TCPIP_CORE_LOCKING_INPUT */ #if LWIP_TCPIP_TIMEOUT && LWIP_TIMERS - case TCPIP_MSG_TIMEOUT: - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg)); - sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg); - memp_free(MEMP_TCPIP_MSG_API, msg); - break; - case TCPIP_MSG_UNTIMEOUT: - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: UNTIMEOUT %p\n", (void *)msg)); - sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg); - memp_free(MEMP_TCPIP_MSG_API, msg); - break; + case TCPIP_MSG_TIMEOUT: + LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: TIMEOUT %p\n", (void *)msg)); + sys_timeout(msg->msg.tmo.msecs, msg->msg.tmo.h, msg->msg.tmo.arg); + memp_free(MEMP_TCPIP_MSG_API, msg); + break; + case TCPIP_MSG_UNTIMEOUT: + LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: UNTIMEOUT %p\n", (void *)msg)); + sys_untimeout(msg->msg.tmo.h, msg->msg.tmo.arg); + memp_free(MEMP_TCPIP_MSG_API, msg); + break; #endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ - case TCPIP_MSG_CALLBACK: - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg)); - msg->msg.cb.function(msg->msg.cb.ctx); - memp_free(MEMP_TCPIP_MSG_API, msg); + case TCPIP_MSG_CALLBACK: + LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK %p\n", (void *)msg)); + msg->msg.cb.function(msg->msg.cb.ctx); + memp_free(MEMP_TCPIP_MSG_API, msg); break; - case TCPIP_MSG_CALLBACK_STATIC: - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK_STATIC %p\n", (void *)msg)); - msg->msg.cb.function(msg->msg.cb.ctx); + case TCPIP_MSG_CALLBACK_STATIC: + LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: CALLBACK_STATIC %p\n", (void *)msg)); + msg->msg.cb.function(msg->msg.cb.ctx); break; - default: - LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: %d\n", msg->type)); - LWIP_ASSERT("tcpip_thread: invalid message", 0); + default: + LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: invalid message: %d\n", msg->type)); + LWIP_ASSERT("tcpip_thread: invalid message", 0); break; } } @@ -165,9 +163,7 @@ * @param inp the network interface on which the packet was received * @param input_fn input function to call */ -err_t -tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn) -{ +err_t tcpip_inpkt(struct pbuf *p, struct netif *inp, netif_input_fn input_fn) { #if LWIP_TCPIP_CORE_LOCKING_INPUT err_t ret; LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_inpkt: PACKET %p/%p\n", (void *)p, (void *)inp)); @@ -182,7 +178,7 @@ LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox)); - msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_INPKT); + msg = (struct tcpip_msg *) memp_malloc(MEMP_TCPIP_MSG_INPKT); //kprintf("INPKT %i\n", __LINE__); if (msg == NULL) { return ERR_MEM; @@ -216,19 +212,18 @@ * NETIF_FLAG_ETHERNET flags) * @param inp the network interface on which the packet was received */ -err_t -tcpip_input(struct pbuf *p, struct netif *inp) -{ +err_t tcpip_input(struct pbuf *p, struct netif *inp) { #if LWIP_ETHERNET -kprintf("tcpip_input0\n"); + kprintf("tcpip_input0\n"); if (inp->flags & (NETIF_FLAG_ETHARP | NETIF_FLAG_ETHERNET)) { -kprintf("tcpip_input1\n"); + kprintf("tcpip_input1\n"); return tcpip_inpkt(p, inp, ethernet_input); - } else + } + else #endif /* LWIP_ETHERNET */ -kprintf("tcpip_input2\n"); + kprintf("tcpip_input2\n"); return tcpip_inpkt(p, inp, ip_input); -kprintf("tcpip_input3\n"); + kprintf("tcpip_input3\n"); } /** @@ -242,14 +237,12 @@ * @param block 1 to block until the request is posted, 0 to non-blocking mode * @return ERR_OK if the function was called, another err_t if not */ -err_t -tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block) -{ +err_t tcpip_callback_with_block(tcpip_callback_fn function, void *ctx, u8_t block) { struct tcpip_msg *msg; LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox)); - msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API); + msg = (struct tcpip_msg *) memp_malloc(MEMP_TCPIP_MSG_API); if (msg == NULL) { return ERR_MEM; } @@ -259,7 +252,8 @@ msg->msg.cb.ctx = ctx; if (block) { sys_mbox_post(&mbox, msg); - } else { + } + else { if (sys_mbox_trypost(&mbox, msg) != ERR_OK) { memp_free(MEMP_TCPIP_MSG_API, msg); return ERR_MEM; @@ -324,7 +318,6 @@ } #endif /* LWIP_TCPIP_TIMEOUT && LWIP_TIMERS */ - /** * Sends a message to TCPIP thread to call a function. Caller thread blocks on * on a provided semaphore, which ist NOT automatically signalled by TCPIP thread, @@ -337,9 +330,7 @@ * @param sem semaphore to wait on * @return ERR_OK if the function was called, another err_t if not */ -err_t -tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem) -{ +err_t tcpip_send_msg_wait_sem(tcpip_callback_fn fn, void *apimsg, sys_sem_t* sem) { #if LWIP_TCPIP_CORE_LOCKING LWIP_UNUSED_ARG(sem); LOCK_TCPIP_CORE(); @@ -373,9 +364,7 @@ * @param call Call parameters * @return Return value from tcpip_api_call_fn */ -err_t -tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call) -{ +err_t tcpip_api_call(tcpip_api_call_fn fn, struct tcpip_api_call_data *call) { #if LWIP_TCPIP_CORE_LOCKING err_t err; LOCK_TCPIP_CORE(); @@ -424,16 +413,15 @@ * @return a struct pointer to pass to tcpip_trycallback(). */ struct tcpip_callback_msg* -tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx) -{ - struct tcpip_msg *msg = (struct tcpip_msg *)memp_malloc(MEMP_TCPIP_MSG_API); +tcpip_callbackmsg_new(tcpip_callback_fn function, void *ctx) { + struct tcpip_msg *msg = (struct tcpip_msg *) memp_malloc(MEMP_TCPIP_MSG_API); if (msg == NULL) { return NULL; } msg->type = TCPIP_MSG_CALLBACK_STATIC; msg->msg.cb.function = function; msg->msg.cb.ctx = ctx; - return (struct tcpip_callback_msg*)msg; + return (struct tcpip_callback_msg*) msg; } /** @@ -441,9 +429,7 @@ * * @param msg the message to free */ -void -tcpip_callbackmsg_delete(struct tcpip_callback_msg* msg) -{ +void tcpip_callbackmsg_delete(struct tcpip_callback_msg* msg) { memp_free(MEMP_TCPIP_MSG_API, msg); } @@ -454,9 +440,7 @@ * @param msg pointer to the message to post * @return sys_mbox_trypost() return code */ -err_t -tcpip_trycallback(struct tcpip_callback_msg* msg) -{ +err_t tcpip_trycallback(struct tcpip_callback_msg* msg) { LWIP_ASSERT("Invalid mbox", sys_mbox_valid_val(mbox)); return sys_mbox_trypost(&mbox, msg); } @@ -470,9 +454,7 @@ * @param initfunc a function to call when tcpip_thread is running and finished initializing * @param arg argument to pass to initfunc */ -void -tcpip_init(tcpip_init_done_fn initfunc, void *arg) -{ +void tcpip_init(tcpip_init_done_fn initfunc, void *arg) { lwip_init(); tcpip_init_done = initfunc; @@ -495,10 +477,8 @@ * * @param p The pbuf (chain) to be dereferenced. */ -static void -pbuf_free_int(void *p) -{ - struct pbuf *q = (struct pbuf *)p; +static void pbuf_free_int(void *p) { + struct pbuf *q = (struct pbuf *) p; pbuf_free(q); } @@ -508,9 +488,7 @@ * @param p The pbuf (chain) to be dereferenced. * @return ERR_OK if callback could be enqueued, an err_t if not */ -err_t -pbuf_free_callback(struct pbuf *p) -{ +err_t pbuf_free_callback(struct pbuf *p) { return tcpip_callback_with_block(pbuf_free_int, p, 0); } @@ -521,9 +499,7 @@ * @param m the heap memory to free * @return ERR_OK if callback could be enqueued, an err_t if not */ -err_t -mem_free_callback(void *m) -{ +err_t mem_free_callback(void *m) { return tcpip_callback_with_block(mem_free, m, 0); }