cc3200/mpthreadport: Make mutex statically allocated.
Reduced the need for the FreeRTOS heap to allocate the mutex.
This commit is contained in:
parent
0455755296
commit
27241293c4
@ -157,19 +157,16 @@ void mp_thread_finish(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void mp_thread_mutex_init(mp_thread_mutex_t *mutex) {
|
void mp_thread_mutex_init(mp_thread_mutex_t *mutex) {
|
||||||
*mutex = xSemaphoreCreateMutex();
|
mutex->handle = xSemaphoreCreateMutexStatic(&mutex->buffer);
|
||||||
if (*mutex == NULL) {
|
|
||||||
// error!
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int mp_thread_mutex_lock(mp_thread_mutex_t *mutex, int wait) {
|
int mp_thread_mutex_lock(mp_thread_mutex_t *mutex, int wait) {
|
||||||
int ret = xSemaphoreTake(*mutex, wait ? portMAX_DELAY : 0);
|
int ret = xSemaphoreTake(mutex->handle, wait ? portMAX_DELAY : 0);
|
||||||
return ret == pdTRUE;
|
return ret == pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mp_thread_mutex_unlock(mp_thread_mutex_t *mutex) {
|
void mp_thread_mutex_unlock(mp_thread_mutex_t *mutex) {
|
||||||
xSemaphoreGive(*mutex);
|
xSemaphoreGive(mutex->handle);
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,10 @@
|
|||||||
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
|
||||||
typedef SemaphoreHandle_t mp_thread_mutex_t;
|
typedef struct _mp_thread_mutex_t {
|
||||||
|
SemaphoreHandle_t handle;
|
||||||
|
StaticSemaphore_t buffer;
|
||||||
|
} mp_thread_mutex_t;
|
||||||
|
|
||||||
void mp_thread_init(void);
|
void mp_thread_init(void);
|
||||||
void mp_thread_gc_others(void);
|
void mp_thread_gc_others(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user