task #10139 (Prefer statically allocated memory): converted mbox and semaphore functions to take pointers to sys_mbox_t/sys_sem_t; converted sys_mbox_new/sys_sem_new to take pointers and return err_t; task #7212: Add Mutex concept in sys_arch (define LWIP_COMPAT_MUTEX to let sys.h use binary semaphores instead of mutexes - as before)

This commit is contained in:
goldsimon
2010-02-12 13:49:21 +00:00
parent 2d1631792a
commit 0030d1ade5
11 changed files with 232 additions and 151 deletions

View File

@@ -189,7 +189,7 @@ static struct mem *ram_end;
static struct mem *lfree;
/** concurrent access protection */
static sys_sem_t mem_sem;
static sys_mutex_t mem_mutex;
#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
@@ -207,8 +207,8 @@ static volatile u8_t mem_free_count;
/* Protect the heap only by using a semaphore */
#define LWIP_MEM_FREE_DECL_PROTECT()
#define LWIP_MEM_FREE_PROTECT() sys_arch_sem_wait(mem_sem, 0)
#define LWIP_MEM_FREE_UNPROTECT() sys_sem_signal(mem_sem)
#define LWIP_MEM_FREE_PROTECT() sys_mutex_lock(&mem_mutex)
#define LWIP_MEM_FREE_UNPROTECT() sys_mutex_unlock(&mem_mutex)
/* mem_malloc is protected using semaphore AND LWIP_MEM_ALLOC_PROTECT */
#define LWIP_MEM_ALLOC_DECL_PROTECT()
#define LWIP_MEM_ALLOC_PROTECT()
@@ -287,7 +287,9 @@ mem_init(void)
ram_end->next = MEM_SIZE_ALIGNED;
ram_end->prev = MEM_SIZE_ALIGNED;
mem_sem = sys_sem_new(1);
if(sys_mutex_new(&mem_mutex) != ERR_OK) {
LWIP_ASSERT("failed to create mem_mutex", 0);
}
/* initialize the lowest-free pointer to the start of the heap */
lfree = (struct mem *)ram;
@@ -514,7 +516,7 @@ mem_malloc(mem_size_t size)
}
/* protect the heap from concurrent access */
sys_arch_sem_wait(mem_sem, 0);
sys_mutex_lock(&mem_mutex);
LWIP_MEM_ALLOC_PROTECT();
#if LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT
/* run as long as a mem_free disturbed mem_malloc */
@@ -592,7 +594,7 @@ mem_malloc(mem_size_t size)
LWIP_ASSERT("mem_malloc: !lfree->used", ((lfree == ram_end) || (!lfree->used)));
}
LWIP_MEM_ALLOC_UNPROTECT();
sys_sem_signal(mem_sem);
sys_mutex_unlock(&mem_mutex);
LWIP_ASSERT("mem_malloc: allocated memory not above ram_end.",
(mem_ptr_t)mem + SIZEOF_STRUCT_MEM + size <= (mem_ptr_t)ram_end);
LWIP_ASSERT("mem_malloc: allocated memory properly aligned.",
@@ -610,7 +612,7 @@ mem_malloc(mem_size_t size)
LWIP_DEBUGF(MEM_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("mem_malloc: could not allocate %"S16_F" bytes\n", (s16_t)size));
MEM_STATS_INC(err);
LWIP_MEM_ALLOC_UNPROTECT();
sys_sem_signal(mem_sem);
sys_mutex_unlock(&mem_mutex);
return NULL;
}

View File

@@ -54,9 +54,12 @@ void
sys_msleep(u32_t ms)
{
if (ms > 0) {
sys_sem_t delaysem = sys_sem_new(0);
sys_arch_sem_wait(delaysem, ms);
sys_sem_free(delaysem);
sys_sem_t delaysem;
err_t err = sys_sem_new(&delaysem, 0);
if (err == ERR_OK) {
sys_arch_sem_wait(&delaysem, ms);
sys_sem_free(&delaysem);
}
}
}

View File

@@ -423,7 +423,7 @@ sys_restart_timeouts(void)
* @param msg the place to store the message
*/
void
sys_timeouts_mbox_fetch(sys_mbox_t mbox, void **msg)
sys_timeouts_mbox_fetch(sys_mbox_t *mbox, void **msg)
{
u32_t time_needed;
struct sys_timeo *tmptimeout;