2007-11-23 21:06:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
* This file is part of the lwIP TCP/IP stack.
|
|
|
|
*
|
|
|
|
* Author: Adam Dunkels <adam@sics.se>
|
|
|
|
* Simon Goldschmidt
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2007-11-25 14:48:38 +00:00
|
|
|
#include <stdio.h> /* sprintf() for task names */
|
2007-11-23 21:06:07 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <lwip/opt.h>
|
2010-02-09 11:37:14 +00:00
|
|
|
#include <lwip/arch.h>
|
2007-11-23 21:06:07 +00:00
|
|
|
#include <lwip/stats.h>
|
|
|
|
#include <lwip/debug.h>
|
|
|
|
#include <lwip/sys.h>
|
|
|
|
|
|
|
|
/* These functions are used from NO_SYS also, for precise timer triggering */
|
|
|
|
LARGE_INTEGER freq, sys_start_time;
|
|
|
|
|
|
|
|
void sys_init_timing()
|
|
|
|
{
|
|
|
|
QueryPerformanceFrequency(&freq);
|
|
|
|
QueryPerformanceCounter(&sys_start_time);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONGLONG sys_get_ms_longlong()
|
|
|
|
{
|
|
|
|
LONGLONG ret;
|
|
|
|
LARGE_INTEGER now;
|
2011-10-18 18:14:05 +00:00
|
|
|
#if NO_SYS
|
|
|
|
if (freq.QuadPart == 0) {
|
|
|
|
sys_init_timing();
|
|
|
|
}
|
|
|
|
#endif /* NO_SYS */
|
2007-11-23 21:06:07 +00:00
|
|
|
QueryPerformanceCounter(&now);
|
|
|
|
ret = now.QuadPart-sys_start_time.QuadPart;
|
|
|
|
return (u32_t)(((ret)*1000)/freq.QuadPart);
|
|
|
|
}
|
|
|
|
|
2009-12-31 16:24:58 +00:00
|
|
|
u32_t sys_jiffies()
|
|
|
|
{
|
2010-01-24 10:09:57 +00:00
|
|
|
return (u32_t)sys_get_ms_longlong();
|
2009-12-31 16:24:58 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 21:06:07 +00:00
|
|
|
u32_t sys_now()
|
|
|
|
{
|
2010-01-24 10:09:57 +00:00
|
|
|
return (u32_t)sys_get_ms_longlong();
|
2007-11-23 21:06:07 +00:00
|
|
|
}
|
|
|
|
|
2009-04-27 20:14:04 +00:00
|
|
|
CRITICAL_SECTION critSec;
|
|
|
|
|
|
|
|
void InitSysArchProtect()
|
|
|
|
{
|
|
|
|
InitializeCriticalSection(&critSec);
|
|
|
|
}
|
|
|
|
u32_t sys_arch_protect()
|
|
|
|
{
|
|
|
|
EnterCriticalSection(&critSec);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
void sys_arch_unprotect(u32_t pval)
|
|
|
|
{
|
|
|
|
LWIP_UNUSED_ARG(pval);
|
|
|
|
LeaveCriticalSection(&critSec);
|
|
|
|
}
|
|
|
|
|
|
|
|
void msvc_sys_init()
|
|
|
|
{
|
2011-09-11 10:46:18 +00:00
|
|
|
srand(time(0));
|
2009-04-27 20:14:04 +00:00
|
|
|
sys_init_timing();
|
|
|
|
InitSysArchProtect();
|
|
|
|
}
|
|
|
|
|
2009-12-31 16:24:58 +00:00
|
|
|
void sys_init()
|
|
|
|
{
|
|
|
|
msvc_sys_init();
|
|
|
|
}
|
|
|
|
|
2007-11-23 21:06:07 +00:00
|
|
|
#if !NO_SYS
|
|
|
|
|
|
|
|
struct threadlist {
|
|
|
|
DWORD id;
|
|
|
|
struct threadlist *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct threadlist *lwip_win32_threads = NULL;
|
|
|
|
|
|
|
|
void do_sleep(int ms)
|
|
|
|
{
|
|
|
|
Sleep(ms);
|
|
|
|
}
|
|
|
|
|
2010-02-12 13:57:58 +00:00
|
|
|
err_t sys_sem_new(sys_sem_t *sem, u8_t count)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
|
|
|
HANDLE new_sem = NULL;
|
2010-02-13 17:30:15 +00:00
|
|
|
|
|
|
|
LWIP_ASSERT("sem != NULL", sem != NULL);
|
|
|
|
|
2007-11-23 21:06:07 +00:00
|
|
|
new_sem = CreateSemaphore(0, count, 100000, 0);
|
|
|
|
LWIP_ASSERT("Error creating semaphore", new_sem != NULL);
|
|
|
|
if(new_sem != NULL) {
|
2010-02-13 17:30:15 +00:00
|
|
|
SYS_STATS_INC_USED(sem);
|
|
|
|
#if LWIP_STATS && SYS_STATS
|
2007-11-23 21:06:07 +00:00
|
|
|
LWIP_ASSERT("sys_sem_new() counter overflow", lwip_stats.sys.sem.used != 0 );
|
2010-02-13 17:30:15 +00:00
|
|
|
#endif /* LWIP_STATS && SYS_STATS*/
|
|
|
|
sem->sem = new_sem;
|
2010-02-12 13:57:58 +00:00
|
|
|
return ERR_OK;
|
2007-11-23 21:06:07 +00:00
|
|
|
}
|
|
|
|
|
2007-11-25 14:48:38 +00:00
|
|
|
/* failed to allocate memory... */
|
2008-06-27 18:38:27 +00:00
|
|
|
SYS_STATS_INC(sem.err);
|
2010-02-13 17:30:15 +00:00
|
|
|
sem->sem = SYS_SEM_NULL;
|
2010-02-12 13:57:58 +00:00
|
|
|
return ERR_MEM;
|
2007-11-23 21:06:07 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 13:57:58 +00:00
|
|
|
void sys_sem_free(sys_sem_t *sem)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
2007-11-25 14:48:38 +00:00
|
|
|
/* parameter check */
|
2007-11-23 21:06:07 +00:00
|
|
|
LWIP_ASSERT("sem != NULL", sem != NULL);
|
2010-02-13 17:30:15 +00:00
|
|
|
LWIP_ASSERT("sem->sem != SYS_SEM_NULL", sem->sem != SYS_SEM_NULL);
|
|
|
|
LWIP_ASSERT("sem->sem != INVALID_HANDLE_VALUE", sem->sem != INVALID_HANDLE_VALUE);
|
|
|
|
CloseHandle(sem->sem);
|
2007-11-23 21:06:07 +00:00
|
|
|
|
2008-06-27 18:38:27 +00:00
|
|
|
SYS_STATS_DEC(sem.used);
|
2010-02-13 17:30:15 +00:00
|
|
|
#if LWIP_STATS && SYS_STATS
|
2007-11-23 21:06:07 +00:00
|
|
|
LWIP_ASSERT("sys_sem_free() closed more than created", lwip_stats.sys.sem.used != (u16_t)-1);
|
2010-02-13 17:30:15 +00:00
|
|
|
#endif /* LWIP_STATS && SYS_STATS */
|
|
|
|
sem->sem = NULL;
|
2007-11-23 21:06:07 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 13:57:58 +00:00
|
|
|
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
LONGLONG starttime, endtime;
|
|
|
|
LWIP_ASSERT("sem != NULL", sem != NULL);
|
2010-02-13 17:30:15 +00:00
|
|
|
LWIP_ASSERT("sem != INVALID_HANDLE_VALUE", sem != INVALID_HANDLE_VALUE);
|
2007-11-23 21:06:07 +00:00
|
|
|
if(!timeout)
|
|
|
|
{
|
2007-11-25 14:48:38 +00:00
|
|
|
/* wait infinite */
|
2007-11-23 21:06:07 +00:00
|
|
|
starttime = sys_get_ms_longlong();
|
2010-02-13 17:30:15 +00:00
|
|
|
ret = WaitForSingleObject(sem->sem, INFINITE);
|
|
|
|
LWIP_ASSERT("Error waiting for semaphore", ret == WAIT_OBJECT_0);
|
2007-11-23 21:06:07 +00:00
|
|
|
endtime = sys_get_ms_longlong();
|
2007-11-25 14:48:38 +00:00
|
|
|
/* return the time we waited for the sem */
|
2007-11-23 21:06:07 +00:00
|
|
|
return (u32_t)(endtime - starttime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
starttime = sys_get_ms_longlong();
|
2010-02-13 17:30:15 +00:00
|
|
|
ret = WaitForSingleObject(sem->sem, timeout);
|
|
|
|
LWIP_ASSERT("Error waiting for semaphore", (ret == WAIT_OBJECT_0) || (ret == WAIT_TIMEOUT));
|
2007-11-23 21:06:07 +00:00
|
|
|
if(ret == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
endtime = sys_get_ms_longlong();
|
2007-11-25 14:48:38 +00:00
|
|
|
/* return the time we waited for the sem */
|
2007-11-23 21:06:07 +00:00
|
|
|
return (u32_t)(endtime - starttime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-11-25 14:48:38 +00:00
|
|
|
/* timeout */
|
2007-11-23 21:06:07 +00:00
|
|
|
return SYS_ARCH_TIMEOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-12 13:57:58 +00:00
|
|
|
void sys_sem_signal(sys_sem_t *sem)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
LWIP_ASSERT("sem != NULL", sem != NULL);
|
2010-02-13 17:30:15 +00:00
|
|
|
LWIP_ASSERT("sem->sem != NULL", sem->sem != NULL);
|
|
|
|
LWIP_ASSERT("sem->sem != INVALID_HANDLE_VALUE", sem->sem != INVALID_HANDLE_VALUE);
|
|
|
|
ret = ReleaseSemaphore(sem->sem, 1, NULL);
|
|
|
|
LWIP_ASSERT("Error releasing semaphore", ret != 0);
|
2007-11-23 21:06:07 +00:00
|
|
|
}
|
|
|
|
|
2010-03-26 14:37:54 +00:00
|
|
|
sys_thread_t sys_thread_new(const char *name, lwip_thread_fn function, void *arg, int stacksize, int prio)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
|
|
|
struct threadlist *new_thread;
|
|
|
|
HANDLE h;
|
|
|
|
SYS_ARCH_DECL_PROTECT(lev);
|
|
|
|
|
|
|
|
LWIP_UNUSED_ARG(name);
|
|
|
|
LWIP_UNUSED_ARG(stacksize);
|
|
|
|
LWIP_UNUSED_ARG(prio);
|
|
|
|
|
|
|
|
new_thread = (struct threadlist*)malloc(sizeof(struct threadlist));
|
|
|
|
LWIP_ASSERT("new_thread != NULL", new_thread != NULL);
|
|
|
|
if(new_thread != NULL) {
|
|
|
|
SYS_ARCH_PROTECT(lev);
|
|
|
|
new_thread->next = lwip_win32_threads;
|
|
|
|
lwip_win32_threads = new_thread;
|
|
|
|
|
|
|
|
h = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)function, arg, 0, &(new_thread->id));
|
|
|
|
LWIP_ASSERT("h != 0", h != 0);
|
|
|
|
LWIP_ASSERT("h != -1", h != INVALID_HANDLE_VALUE);
|
|
|
|
|
|
|
|
SYS_ARCH_UNPROTECT(lev);
|
|
|
|
return new_thread->id;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-12 13:57:58 +00:00
|
|
|
err_t sys_mbox_new(sys_mbox_t *mbox, int size)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
2010-02-13 17:30:15 +00:00
|
|
|
LWIP_ASSERT("mbox != NULL", mbox != NULL);
|
2008-01-05 21:13:46 +00:00
|
|
|
LWIP_UNUSED_ARG(size);
|
|
|
|
|
2010-02-13 17:30:15 +00:00
|
|
|
mbox->sem = CreateSemaphore(0, 0, MAX_QUEUE_ENTRIES, 0);
|
|
|
|
LWIP_ASSERT("Error creating semaphore", mbox->sem != NULL);
|
|
|
|
if(mbox->sem == NULL) {
|
2008-06-27 18:38:27 +00:00
|
|
|
SYS_STATS_INC(mbox.err);
|
2010-02-12 13:57:58 +00:00
|
|
|
return ERR_MEM;
|
2007-11-23 21:06:07 +00:00
|
|
|
}
|
2010-02-13 17:30:15 +00:00
|
|
|
memset(&mbox->q_mem, 0, sizeof(u32_t)*MAX_QUEUE_ENTRIES);
|
|
|
|
mbox->head = 0;
|
|
|
|
mbox->tail = 0;
|
|
|
|
SYS_STATS_INC_USED(mbox);
|
|
|
|
#if LWIP_STATS && SYS_STATS
|
2007-11-23 21:06:07 +00:00
|
|
|
LWIP_ASSERT("sys_mbox_new() counter overflow", lwip_stats.sys.mbox.used != 0 );
|
2010-02-13 17:30:15 +00:00
|
|
|
#endif /* LWIP_STATS && SYS_STATS */
|
2010-02-12 13:57:58 +00:00
|
|
|
return ERR_OK;
|
2007-11-23 21:06:07 +00:00
|
|
|
}
|
|
|
|
|
2010-02-12 13:57:58 +00:00
|
|
|
void sys_mbox_free(sys_mbox_t *mbox)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
2007-11-25 14:48:38 +00:00
|
|
|
/* parameter check */
|
2010-02-12 13:57:58 +00:00
|
|
|
LWIP_ASSERT("mbox != NULL", mbox != NULL);
|
2010-02-13 17:30:15 +00:00
|
|
|
LWIP_ASSERT("mbox->sem != NULL", mbox->sem != NULL);
|
|
|
|
LWIP_ASSERT("mbox->sem != INVALID_HANDLE_VALUE", mbox->sem != INVALID_HANDLE_VALUE);
|
2007-11-23 21:06:07 +00:00
|
|
|
|
2010-02-13 17:30:15 +00:00
|
|
|
CloseHandle(mbox->sem);
|
2007-11-23 21:06:07 +00:00
|
|
|
|
2008-06-27 18:38:27 +00:00
|
|
|
SYS_STATS_DEC(mbox.used);
|
2010-02-13 17:30:15 +00:00
|
|
|
#if LWIP_STATS && SYS_STATS
|
2007-11-23 21:06:07 +00:00
|
|
|
LWIP_ASSERT( "sys_mbox_free() ", lwip_stats.sys.mbox.used!= (u16_t)-1 );
|
2010-02-13 17:30:15 +00:00
|
|
|
#endif /* LWIP_STATS && SYS_STATS */
|
|
|
|
mbox->sem = NULL;
|
2007-11-23 21:06:07 +00:00
|
|
|
}
|
|
|
|
|
2010-02-13 17:30:15 +00:00
|
|
|
void sys_mbox_post(sys_mbox_t *q, void *msg)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
SYS_ARCH_DECL_PROTECT(lev);
|
|
|
|
|
2007-11-25 14:48:38 +00:00
|
|
|
/* parameter check */
|
2010-02-13 17:30:15 +00:00
|
|
|
LWIP_ASSERT("q != SYS_MBOX_NULL", q != SYS_MBOX_NULL);
|
2007-11-23 21:06:07 +00:00
|
|
|
LWIP_ASSERT("q->sem != NULL", q->sem != NULL);
|
|
|
|
LWIP_ASSERT("q->sem != INVALID_HANDLE_VALUE", q->sem != INVALID_HANDLE_VALUE);
|
|
|
|
|
|
|
|
SYS_ARCH_PROTECT(lev);
|
|
|
|
q->q_mem[q->head] = msg;
|
|
|
|
(q->head)++;
|
|
|
|
if (q->head >= MAX_QUEUE_ENTRIES) {
|
|
|
|
q->head = 0;
|
|
|
|
}
|
|
|
|
LWIP_ASSERT("mbox is full!", q->head != q->tail);
|
|
|
|
ret = ReleaseSemaphore(q->sem, 1, 0);
|
|
|
|
LWIP_ASSERT("Error releasing sem", ret != 0);
|
|
|
|
|
|
|
|
SYS_ARCH_UNPROTECT(lev);
|
|
|
|
}
|
|
|
|
|
2010-02-13 17:30:15 +00:00
|
|
|
err_t sys_mbox_trypost(sys_mbox_t *q, void *msg)
|
2008-01-05 21:13:46 +00:00
|
|
|
{
|
2008-01-06 14:16:12 +00:00
|
|
|
u32_t new_head;
|
2008-01-05 21:13:46 +00:00
|
|
|
DWORD ret;
|
|
|
|
SYS_ARCH_DECL_PROTECT(lev);
|
|
|
|
|
|
|
|
/* parameter check */
|
2010-02-13 17:30:15 +00:00
|
|
|
LWIP_ASSERT("q != SYS_MBOX_NULL", q != SYS_MBOX_NULL);
|
2008-01-05 21:13:46 +00:00
|
|
|
LWIP_ASSERT("q->sem != NULL", q->sem != NULL);
|
|
|
|
LWIP_ASSERT("q->sem != INVALID_HANDLE_VALUE", q->sem != INVALID_HANDLE_VALUE);
|
|
|
|
|
|
|
|
SYS_ARCH_PROTECT(lev);
|
2008-01-06 14:16:12 +00:00
|
|
|
|
|
|
|
new_head = q->head + 1;
|
|
|
|
if (new_head >= MAX_QUEUE_ENTRIES) {
|
|
|
|
new_head = 0;
|
|
|
|
}
|
|
|
|
if (new_head == q->tail) {
|
|
|
|
SYS_ARCH_UNPROTECT(lev);
|
|
|
|
return ERR_MEM;
|
2008-01-05 21:13:46 +00:00
|
|
|
}
|
2008-01-06 14:16:12 +00:00
|
|
|
|
|
|
|
q->q_mem[q->head] = msg;
|
|
|
|
q->head = new_head;
|
2008-01-05 21:13:46 +00:00
|
|
|
LWIP_ASSERT("mbox is full!", q->head != q->tail);
|
|
|
|
ret = ReleaseSemaphore(q->sem, 1, 0);
|
|
|
|
LWIP_ASSERT("Error releasing sem", ret != 0);
|
|
|
|
|
|
|
|
SYS_ARCH_UNPROTECT(lev);
|
|
|
|
return ERR_OK;
|
|
|
|
}
|
|
|
|
|
2010-02-13 17:30:15 +00:00
|
|
|
u32_t sys_arch_mbox_fetch(sys_mbox_t *q, void **msg, u32_t timeout)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
LONGLONG starttime, endtime;
|
|
|
|
SYS_ARCH_DECL_PROTECT(lev);
|
|
|
|
|
2007-11-25 14:48:38 +00:00
|
|
|
/* parameter check */
|
2010-02-13 17:30:15 +00:00
|
|
|
LWIP_ASSERT("q != SYS_MBOX_NULL", q != SYS_MBOX_NULL);
|
2007-11-23 21:06:07 +00:00
|
|
|
LWIP_ASSERT("q->sem != NULL", q->sem != NULL);
|
|
|
|
LWIP_ASSERT("q->sem != INVALID_HANDLE_VALUE", q->sem != INVALID_HANDLE_VALUE);
|
|
|
|
|
|
|
|
if (timeout == 0) {
|
|
|
|
timeout = INFINITE;
|
|
|
|
}
|
|
|
|
starttime = sys_get_ms_longlong();
|
|
|
|
if ((ret = WaitForSingleObject(q->sem, timeout)) == WAIT_OBJECT_0) {
|
|
|
|
SYS_ARCH_PROTECT(lev);
|
|
|
|
if(msg != NULL) {
|
|
|
|
*msg = q->q_mem[q->tail];
|
|
|
|
}
|
2007-11-25 14:48:38 +00:00
|
|
|
|
2007-11-23 21:06:07 +00:00
|
|
|
(q->tail)++;
|
|
|
|
if (q->tail >= MAX_QUEUE_ENTRIES) {
|
|
|
|
q->tail = 0;
|
|
|
|
}
|
|
|
|
SYS_ARCH_UNPROTECT(lev);
|
|
|
|
endtime = sys_get_ms_longlong();
|
|
|
|
return (u32_t)(endtime - starttime);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LWIP_ASSERT("Error waiting for sem", ret == WAIT_TIMEOUT);
|
|
|
|
if(msg != NULL) {
|
|
|
|
*msg = NULL;
|
|
|
|
}
|
2007-11-25 14:48:38 +00:00
|
|
|
|
2007-11-23 21:06:07 +00:00
|
|
|
return SYS_ARCH_TIMEOUT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-13 17:30:15 +00:00
|
|
|
u32_t sys_arch_mbox_tryfetch(sys_mbox_t *q, void **msg)
|
2007-11-23 21:06:07 +00:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
SYS_ARCH_DECL_PROTECT(lev);
|
|
|
|
|
2007-11-25 14:48:38 +00:00
|
|
|
/* parameter check */
|
2010-02-13 17:30:15 +00:00
|
|
|
LWIP_ASSERT("q != SYS_MBOX_NULL", q != SYS_MBOX_NULL);
|
2007-11-23 21:06:07 +00:00
|
|
|
LWIP_ASSERT("q->sem != NULL", q->sem != NULL);
|
|
|
|
LWIP_ASSERT("q->sem != INVALID_HANDLE_VALUE", q->sem != INVALID_HANDLE_VALUE);
|
|
|
|
|
|
|
|
if ((ret = WaitForSingleObject(q->sem, 0)) == WAIT_OBJECT_0) {
|
|
|
|
SYS_ARCH_PROTECT(lev);
|
|
|
|
if(msg != NULL) {
|
|
|
|
*msg = q->q_mem[q->tail];
|
|
|
|
}
|
2007-11-25 14:48:38 +00:00
|
|
|
|
2007-11-23 21:06:07 +00:00
|
|
|
(q->tail)++;
|
|
|
|
if (q->tail >= MAX_QUEUE_ENTRIES) {
|
|
|
|
q->tail = 0;
|
|
|
|
}
|
|
|
|
SYS_ARCH_UNPROTECT(lev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LWIP_ASSERT("Error waiting for sem", ret == WAIT_TIMEOUT);
|
|
|
|
if(msg != NULL) {
|
|
|
|
*msg = NULL;
|
|
|
|
}
|
2007-11-25 14:48:38 +00:00
|
|
|
|
2007-11-23 21:06:07 +00:00
|
|
|
return SYS_ARCH_TIMEOUT;
|
|
|
|
}
|
|
|
|
}
|
2010-02-13 17:30:15 +00:00
|
|
|
|
2007-11-23 21:06:07 +00:00
|
|
|
#endif /* !NO_SYS */
|