diff --git a/src/sys/i386/spinlock.c b/src/sys/i386/spinlock.c index 6670f72..5a4de76 100644 --- a/src/sys/i386/spinlock.c +++ b/src/sys/i386/spinlock.c @@ -1,31 +1,28 @@ -/***************************************************************************************** - Copyright (c) 2002-2004 The UbixOS Project - All rights reserved. - - Redistribution and use in source and binary forms, with or without modification, are - permitted provided that the following conditions are met: - - Redistributions of source code must retain the above copyright notice, this list of - conditions, the following disclaimer and the list of authors. Redistributions in binary - form must reproduce the above copyright notice, this list of conditions, the following - disclaimer and the list of authors in the documentation and/or other materials provided - with the distribution. Neither the name of the UbixOS Project nor the names of its - contributors may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - $Id: spinlock.c 54 2016-01-11 01:29:55Z reddawg $ - - *****************************************************************************************/ +/*- + * Copyright (c) 2002-2004, 2017 The UbixOS Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this list of + * conditions, the following disclaimer and the list of authors. Redistributions in binary + * form must reproduce the above copyright notice, this list of conditions, the following + * disclaimer and the list of authors in the documentation and/or other materials provided + * with the distribution. Neither the name of the UbixOS Project nor the names of its + * contributors may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ #include #include @@ -47,123 +44,6 @@ memset(lock, 0x0, sizeof(spinLock_t)); } -#ifdef _BALLS -void spinLock(spinLock_t lock) { - struct spinLock me; - spinLock_t tail; - - /* Fast path - no users */ - if (!cmpxchg(lock, NULL, LLOCK_FLAG)) - return; - - me.next = LLOCK_FLAG; - me.locked = 0; - - /* Convert into a wait list */ - tail = xchg_32(lock, &me); - - if (tail) { - /* Add myself to the list of waiters */ - if (tail == LLOCK_FLAG) - tail = NULL; - - me.next = tail; - - /* Wait for being able to go */ - while (!me.locked) - sched_yield(); - - return; - } - - /* Try to convert to an exclusive lock */ - if (cmpxchg(lock, &me, LLOCK_FLAG) == &me) - return; - - /* Failed - there is now a wait list */ - tail = *lock; - - /* Scan to find who is after me */ - while (1) { - /* Wait for them to enter their next link */ - while (tail->next == LLOCK_FLAG ) - sched_yield(); - - if (tail->next == &me) { - /* Fix their next pointer */ - tail->next = NULL; - - return; - } - - tail = tail->next; - } -} - -void spinUnlock(spinLock_t *l) { - spinLock_t tail; - spinLock_t tp; - - while (1) { - tail = *l; - - barrier(); - - /* Fast path */ - if (tail == LLOCK_FLAG) { - if (cmpxchg(l, LLOCK_FLAG, NULL) == LLOCK_FLAG) - return; - - continue; - } - - tp = NULL; - - /* Wait for partially added waiter */ - while (tail->next == LLOCK_FLAG ) - sched_yield(); - - /* There is a wait list */ - if (tail->next) - break; - - /* Try to convert to a single-waiter lock */ - if (cmpxchg(l, tail, LLOCK_FLAG) == tail) { - /* Unlock */ - tail->locked = 1; - - return; - } - - sched_yield(); - } - - /* A long list */ - tp = tail; - tail = tail->next; - - /* Scan wait list */ - while (1) { - /* Wait for partially added waiter */ - while (tail->next == LLOCK_FLAG ) - sched_yield(); - - if (!tail->next) - break; - - tp = tail; - tail = tail->next; - } - - tp->next = NULL; - - barrier(); - - /* Unlock */ - tail->locked = 1; -} -#endif - int spinTryLock(spinLock_t lock) { if (!cmpxchg(&lock->locked, NULL, LLOCK_FLAG)) return 0; @@ -172,7 +52,6 @@ return LOCKED; } - void spinUnlock(spinLock_t lock) { barrier(); lock->locked = 0x0; @@ -186,15 +65,3 @@ sched_yield(); } } - -#ifdef _BALLS -void spinLock_scheduler_old(spinLock_t *lock) { - while (!spinTryLock(lock)) - while (*lock == 1) - ; -} - -int spinLockLocked_old(spinLock_t *lock) { - return (*lock != 0); -} -#endif diff --git a/src/sys/include/stdatomic.h b/src/sys/include/stdatomic.h index 11f09a9..f03022f 100644 --- a/src/sys/include/stdatomic.h +++ b/src/sys/include/stdatomic.h @@ -83,11 +83,11 @@ */ #if defined(__CLANG_ATOMICS) -#define ATOMIC_VAR_INIT(value) (value) -#define atomic_init(obj, value) __c11_atomic_init(obj, value) +#define ATOMIC_VAR_INIT(value) (value) +#define atomic_init(obj, value) __c11_atomic_init(obj, value) #else -#define ATOMIC_VAR_INIT(value) { .__val = (value) } -#define atomic_init(obj, value) ((void)((obj)->__val = (value))) +#define ATOMIC_VAR_INIT(value) { .__val = (value) } +#define atomic_init(obj, value) ((void)((obj)->__val = (value))) #endif /* @@ -123,41 +123,32 @@ */ typedef enum { - memory_order_relaxed = __ATOMIC_RELAXED, - memory_order_consume = __ATOMIC_CONSUME, - memory_order_acquire = __ATOMIC_ACQUIRE, - memory_order_release = __ATOMIC_RELEASE, - memory_order_acq_rel = __ATOMIC_ACQ_REL, - memory_order_seq_cst = __ATOMIC_SEQ_CST + memory_order_relaxed = __ATOMIC_RELAXED, memory_order_consume = __ATOMIC_CONSUME, memory_order_acquire = __ATOMIC_ACQUIRE, memory_order_release = __ATOMIC_RELEASE, memory_order_acq_rel = __ATOMIC_ACQ_REL, memory_order_seq_cst = __ATOMIC_SEQ_CST } memory_order; /* * 7.17.4 Fences. */ -static __inline void -atomic_thread_fence(memory_order __order __unused) -{ +static __inline void atomic_thread_fence(memory_order __order __unused) { #ifdef __CLANG_ATOMICS - __c11_atomic_thread_fence(__order); + __c11_atomic_thread_fence(__order); #elif defined(__GNUC_ATOMICS) - __atomic_thread_fence(__order); + __atomic_thread_fence(__order); #else - __sync_synchronize(); + __sync_synchronize(); #endif } -static __inline void -atomic_signal_fence(memory_order __order __unused) -{ +static __inline void atomic_signal_fence(memory_order __order __unused) { #ifdef __CLANG_ATOMICS - __c11_atomic_signal_fence(__order); + __c11_atomic_signal_fence(__order); #elif defined(__GNUC_ATOMICS) - __atomic_signal_fence(__order); + __atomic_signal_fence(__order); #else - __asm volatile ("" ::: "memory"); + __asm volatile ("" ::: "memory"); #endif } @@ -184,43 +175,43 @@ * 7.17.6 Atomic integer types. */ -typedef _Atomic(_Bool) atomic_bool; -typedef _Atomic(char) atomic_char; -typedef _Atomic(signed char) atomic_schar; -typedef _Atomic(unsigned char) atomic_uchar; -typedef _Atomic(short) atomic_short; -typedef _Atomic(unsigned short) atomic_ushort; -typedef _Atomic(int) atomic_int; -typedef _Atomic(unsigned int) atomic_uint; -typedef _Atomic(long) atomic_long; -typedef _Atomic(unsigned long) atomic_ulong; -typedef _Atomic(long long) atomic_llong; -typedef _Atomic(unsigned long long) atomic_ullong; -typedef _Atomic(__char16_t) atomic_char16_t; -typedef _Atomic(__char32_t) atomic_char32_t; -typedef _Atomic(___wchar_t) atomic_wchar_t; -typedef _Atomic(__int_least8_t) atomic_int_least8_t; -typedef _Atomic(__uint_least8_t) atomic_uint_least8_t; -typedef _Atomic(__int_least16_t) atomic_int_least16_t; -typedef _Atomic(__uint_least16_t) atomic_uint_least16_t; -typedef _Atomic(__int_least32_t) atomic_int_least32_t; -typedef _Atomic(__uint_least32_t) atomic_uint_least32_t; -typedef _Atomic(__int_least64_t) atomic_int_least64_t; -typedef _Atomic(__uint_least64_t) atomic_uint_least64_t; -typedef _Atomic(__int_fast8_t) atomic_int_fast8_t; -typedef _Atomic(__uint_fast8_t) atomic_uint_fast8_t; -typedef _Atomic(__int_fast16_t) atomic_int_fast16_t; -typedef _Atomic(__uint_fast16_t) atomic_uint_fast16_t; -typedef _Atomic(__int_fast32_t) atomic_int_fast32_t; -typedef _Atomic(__uint_fast32_t) atomic_uint_fast32_t; -typedef _Atomic(__int_fast64_t) atomic_int_fast64_t; -typedef _Atomic(__uint_fast64_t) atomic_uint_fast64_t; -typedef _Atomic(__intptr_t) atomic_intptr_t; -typedef _Atomic(__uintptr_t) atomic_uintptr_t; -typedef _Atomic(__size_t) atomic_size_t; -typedef _Atomic(__ptrdiff_t) atomic_ptrdiff_t; -typedef _Atomic(__intmax_t) atomic_intmax_t; -typedef _Atomic(__uintmax_t) atomic_uintmax_t; +typedef _Atomic(_Bool) atomic_bool; +typedef _Atomic(char) atomic_char; +typedef _Atomic(signed char) atomic_schar; +typedef _Atomic(unsigned char) atomic_uchar; +typedef _Atomic(short) atomic_short; +typedef _Atomic(unsigned short) atomic_ushort; +typedef _Atomic(int) atomic_int; +typedef _Atomic(unsigned int) atomic_uint; +typedef _Atomic(long) atomic_long; +typedef _Atomic(unsigned long) atomic_ulong; +typedef _Atomic(long long) atomic_llong; +typedef _Atomic(unsigned long long) atomic_ullong; +typedef _Atomic(__char16_t) atomic_char16_t; +typedef _Atomic(__char32_t) atomic_char32_t; +typedef _Atomic(___wchar_t) atomic_wchar_t; +typedef _Atomic(__int_least8_t) atomic_int_least8_t; +typedef _Atomic(__uint_least8_t) atomic_uint_least8_t; +typedef _Atomic(__int_least16_t) atomic_int_least16_t; +typedef _Atomic(__uint_least16_t) atomic_uint_least16_t; +typedef _Atomic(__int_least32_t) atomic_int_least32_t; +typedef _Atomic(__uint_least32_t) atomic_uint_least32_t; +typedef _Atomic(__int_least64_t) atomic_int_least64_t; +typedef _Atomic(__uint_least64_t) atomic_uint_least64_t; +typedef _Atomic(__int_fast8_t) atomic_int_fast8_t; +typedef _Atomic(__uint_fast8_t) atomic_uint_fast8_t; +typedef _Atomic(__int_fast16_t) atomic_int_fast16_t; +typedef _Atomic(__uint_fast16_t) atomic_uint_fast16_t; +typedef _Atomic(__int_fast32_t) atomic_int_fast32_t; +typedef _Atomic(__uint_fast32_t) atomic_uint_fast32_t; +typedef _Atomic(__int_fast64_t) atomic_int_fast64_t; +typedef _Atomic(__uint_fast64_t) atomic_uint_fast64_t; +typedef _Atomic(__intptr_t) atomic_intptr_t; +typedef _Atomic(__uintptr_t) atomic_uintptr_t; +typedef _Atomic(__size_t) atomic_size_t; +typedef _Atomic(__ptrdiff_t) atomic_ptrdiff_t; +typedef _Atomic(__intmax_t) atomic_intmax_t; +typedef _Atomic(__uintmax_t) atomic_uintmax_t; /* * 7.17.7 Operations on atomic types. @@ -372,39 +363,29 @@ */ typedef struct { - atomic_bool __flag; + atomic_bool __flag; } atomic_flag; #define ATOMIC_FLAG_INIT { ATOMIC_VAR_INIT(0) } -static __inline _Bool -atomic_flag_test_and_set_explicit(volatile atomic_flag *__object, - memory_order __order) -{ - return (atomic_exchange_explicit(&__object->__flag, 1, __order)); +static __inline _Bool atomic_flag_test_and_set_explicit(volatile atomic_flag *__object, memory_order __order) { + return (atomic_exchange_explicit(&__object->__flag, 1, __order)); } -static __inline void -atomic_flag_clear_explicit(volatile atomic_flag *__object, memory_order __order) -{ +static __inline void atomic_flag_clear_explicit(volatile atomic_flag *__object, memory_order __order) { - atomic_store_explicit(&__object->__flag, 0, __order); + atomic_store_explicit(&__object->__flag, 0, __order); } #ifndef _KERNEL -static __inline _Bool -atomic_flag_test_and_set(volatile atomic_flag *__object) -{ +static __inline _Bool atomic_flag_test_and_set(volatile atomic_flag *__object) { - return (atomic_flag_test_and_set_explicit(__object, - memory_order_seq_cst)); + return (atomic_flag_test_and_set_explicit(__object, memory_order_seq_cst)); } -static __inline void -atomic_flag_clear(volatile atomic_flag *__object) -{ +static __inline void atomic_flag_clear(volatile atomic_flag *__object) { - atomic_flag_clear_explicit(__object, memory_order_seq_cst); + atomic_flag_clear_explicit(__object, memory_order_seq_cst); } #endif /* !_KERNEL */ diff --git a/src/sys/include/ubixos/ubthread.h b/src/sys/include/ubixos/ubthread.h index 44f22f8..88a1324 100644 --- a/src/sys/include/ubixos/ubthread.h +++ b/src/sys/include/ubixos/ubthread.h @@ -52,13 +52,11 @@ struct ubthread_cond { int id; - //_Atomic bool lock; bool lock; }; struct ubthread_mutex { int id; - //_Atomic bool lock; bool lock; pidType pid; }; diff --git a/src/sys/kernel/ubthread.c b/src/sys/kernel/ubthread.c index cc4fc27..7972281 100644 --- a/src/sys/kernel/ubthread.c +++ b/src/sys/kernel/ubthread.c @@ -87,21 +87,20 @@ 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); - while (1) { - if (!xchg_32(&ubmutex->lock, TRUE)) - break; - - while (ubmutex->lock == TRUE) - sched_yield(); - } - } - else if (ubmutex->lock == TRUE && ubmutex->pid == _current->id) { + if (ubmutex->lock == TRUE && ubmutex->pid == _current->id) { kprintf("Mutex Already Locked By This Thread"); + kpanic("WHY?"); return (0x0); } + while (1) { + if (!xchg_32(&ubmutex->lock, TRUE)) + break; + + while (ubmutex->lock == TRUE) + sched_yield(); + } + ubmutex->pid = _current->id; return (0x0); } @@ -116,6 +115,7 @@ } else { kprintf("Trying To Unlock Mutex From No Locking Thread[%i - %i:0x%X]\n", ubmutex->pid, _current->id, *ubmutex); + kpanic("WTF2"); while (ubmutex->pid != _current->id) sched_yield(); kprintf("GOT IT UNLOCKING"); diff --git a/src/sys/net/api/tcpip.c b/src/sys/net/api/tcpip.c index 56d0c76..28a2d02 100644 --- a/src/sys/net/api/tcpip.c +++ b/src/sys/net/api/tcpip.c @@ -1,9 +1,3 @@ -/** - * @file - * Sequential API Main thread module - * - */ - /* * Copyright (c) 2001-2004 Swedish Institute of Computer Science. * All rights reserved. @@ -183,20 +177,20 @@ if (msg == NULL) { return ERR_MEM; } -kprintf("INPKT %i\n", __LINE__); + kprintf("INPKT %i\n", __LINE__); msg->type = TCPIP_MSG_INPKT; msg->msg.inp.p = p; msg->msg.inp.netif = inp; msg->msg.inp.input_fn = input_fn; -kprintf("%s:%i\n", __FILE__, __LINE__); + kprintf("%s:%i\n", __FILE__, __LINE__); if (sys_mbox_trypost(&mbox, msg) != ERR_OK) { -kprintf("INPKT %i\n", __LINE__); + kprintf("INPKT %i\n", __LINE__); memp_free(MEMP_TCPIP_MSG_INPKT, msg); -kprintf("INPKT %i\n", __LINE__); + kprintf("INPKT %i\n", __LINE__); return ERR_MEM; } -kprintf("INPKT %i\n", __LINE__); + kprintf("INPKT %i\n", __LINE__); return ERR_OK; #endif /* LWIP_TCPIP_CORE_LOCKING_INPUT */ @@ -223,7 +217,7 @@ else #endif /* LWIP_ETHERNET */ //kprintf("tcpip_input2\n"); - return tcpip_inpkt(p, inp, ip_input); + return tcpip_inpkt(p, inp, ip_input); //kprintf("tcpip_input3\n"); } diff --git a/src/sys/net/net/init.c b/src/sys/net/net/init.c index 2ca2577..631586b 100644 --- a/src/sys/net/net/init.c +++ b/src/sys/net/net/init.c @@ -46,8 +46,6 @@ void lnc_thread(); -//void netMainThread(); -//static void tcpip_init_done(void *arg); struct netif lnc_netif; int net_init() { @@ -61,59 +59,7 @@ netif_add(&lnc_netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input); netif_set_default(&lnc_netif); - - //netif_set_default(netif_add(&ipaddr, &netmask, &gw, ethernetif_init, tcpip_input)); sys_thread_new("lncThread", (void *) lnc_thread, 0x0, 0x1000, 0x0); return(0x0); } - -#ifdef _BALLS -int net_init_dead() { - sys_init(); - mem_init(); - memp_init(); - pbuf_init(); - - - return (0x0); -} - -void netMainThread() { - struct ip_addr ipaddr, netmask, gw; - sys_sem_t sem; - - netif_init(); - - sem = sys_sem_new(0); - tcpip_init(tcpip_init_done, &sem); - - sys_sem_wait(sem); - sys_sem_free(sem); - - kprintf("TCP/IP initialized.\n"); - - IP4_ADDR(&gw, 10, 50, 0, 1); - IP4_ADDR(&ipaddr, 10, 50, 0, 7); - IP4_ADDR(&netmask, 255, 255, 0, 0); - netif_set_default(netif_add(&ipaddr, &netmask, &gw, ethernetif_init, tcpip_input)); - - IP4_ADDR(&gw, 127, 0, 0, 1); - IP4_ADDR(&ipaddr, 127, 0, 0, 1); - IP4_ADDR(&netmask, 255, 0, 0, 0); - netif_add(&ipaddr, &netmask, &gw, loopif_init, tcpip_input); - - //udpecho_init(); - shell_init(); - //bot_init(); - endTask(_current->id); - while (1) - sched_yield(); -} - -static void tcpip_init_done(void *arg) { - sys_sem_t *sem = 0x0; - sem = arg; - sys_sem_signal(*sem); -} -#endif diff --git a/src/sys/net/net/sys_arch.c b/src/sys/net/net/sys_arch.c index 42a629a..e1b2a31 100644 --- a/src/sys/net/net/sys_arch.c +++ b/src/sys/net/net/sys_arch.c @@ -34,7 +34,7 @@ static struct sys_sem *sys_sem_new_internal(uint8_t count) { struct sys_sem *sem; - sem = (struct sys_sem *)kmalloc(sizeof(struct sys_sem)); + sem = (struct sys_sem *) kmalloc(sizeof(struct sys_sem)); if (sem != NULL) { sem->signaled = count; ubthread_cond_init(&(sem->cond), NULL); @@ -49,6 +49,7 @@ newSem = kmalloc(sizeof(struct sys_sem)); newSem->signaled = count; + ubthread_cond_init(&(newSem->cond), NULL); ubthread_mutex_init(&(newSem->mutex), NULL); @@ -106,8 +107,9 @@ return SYS_ARCH_TIMEOUT; } /* ubthread_mutex_unlock(&(sem->mutex)); - return time_needed; */ - } else { + return time_needed; */ + } + else { cond_wait(&(sem->cond), &(sem->mutex), 0); } } @@ -138,23 +140,22 @@ void sys_mutex_lock(sys_mutex_t *mutex) { kprintf("L4.0"); - ubthread_mutex_lock(&(mutex->mutex)) ; + ubthread_mutex_lock(&(mutex->mutex)); kprintf("L4.1"); } void sys_mutex_unlock(sys_mutex_t *mutex) { - ubthread_mutex_unlock(&(mutex->mutex)) ; + ubthread_mutex_unlock(&(mutex->mutex)); } err_t sys_mbox_new(struct sys_mbox **mb, int size) { struct sys_mbox *mbox = 0x0; LWIP_UNUSED_ARG(size); - mbox = (struct sys_mbox *)kmalloc(sizeof(struct sys_mbox)); + mbox = (struct sys_mbox *) kmalloc(sizeof(struct sys_mbox)); if (mbox == NULL) - return(ERR_MEM); - + return (ERR_MEM); mbox->head = 0; mbox->tail = 0; @@ -184,7 +185,7 @@ if ((mb != NULL) && (*mb != SYS_MBOX_NULL)) { struct sys_mbox *mbox = *mb; sys_arch_sem_wait(&mbox->lock, 0); - + sys_sem_free_internal(mbox->full); sys_sem_free_internal(mbox->empty); sys_sem_free_internal(mbox->lock); @@ -217,7 +218,8 @@ if (mbox->tail == mbox->head) { head = 1; - } else { + } + else { head = 0; } @@ -239,7 +241,7 @@ sys_arch_sem_wait(&mbox->lock, 0); LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_trypost: mbox %p msg %p\n", - (void *)mbox, (void *)msg)); + (void *)mbox, (void *)msg)); if ((mbox->tail + 1) >= (mbox->head + SYS_MBOX_SIZE)) { sys_sem_signal(&mbox->lock); @@ -250,7 +252,8 @@ if (mbox->tail == mbox->head) { head = 1; - } else { + } + else { head = 0; } @@ -272,21 +275,22 @@ mbox = *mb; /* The mutex lock is quick so we don't bother with the timeout - stuff here. */ + stuff here. */ sys_arch_sem_wait(&mbox->lock, 0); while (mbox->head == mbox->tail) { sys_sem_signal(&mbox->lock); /* We block while waiting for a mail to arrive in the mailbox. We - must be prepared to timeout. */ + must be prepared to timeout. */ if (timeout != 0) { time_needed = sys_arch_sem_wait(&mbox->full, timeout); if (time_needed == SYS_ARCH_TIMEOUT) { return SYS_ARCH_TIMEOUT; } - } else { + } + else { sys_arch_sem_wait(&mbox->full, 0); } @@ -297,7 +301,7 @@ LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", (void *)mbox, *msg)); *msg = mbox->msgs[mbox->head % SYS_MBOX_SIZE]; } - else{ + else { LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p, null msg\n", (void *)mbox)); } @@ -328,7 +332,7 @@ LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p msg %p\n", (void *)mbox, *msg)); *msg = mbox->msgs[mbox->head % SYS_MBOX_SIZE]; } - else{ + else { LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p, null msg\n", (void *)mbox)); } @@ -343,7 +347,6 @@ return 0; } - int sys_mbox_valid(sys_mbox_t *mbox) { return mbox != NULL; } @@ -396,7 +399,6 @@ void *arg; }; - static uint32_t cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uint32_t timeout) { unsigned int tdiff; unsigned long sec, usec; @@ -436,7 +438,6 @@ } } - static struct sys_thread *current_thread(void) { struct sys_thread *st; kTask_t *pt;