Skip to content

Commit 2724129

Browse files
committed
cc3200/mpthreadport: Make mutex statically allocated.
Reduced the need for the FreeRTOS heap to allocate the mutex.
1 parent 0455755 commit 2724129

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

cc3200/mpthreadport.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,19 +157,16 @@ void mp_thread_finish(void) {
157157
}
158158

159159
void mp_thread_mutex_init(mp_thread_mutex_t *mutex) {
160-
*mutex = xSemaphoreCreateMutex();
161-
if (*mutex == NULL) {
162-
// error!
163-
}
160+
mutex->handle = xSemaphoreCreateMutexStatic(&mutex->buffer);
164161
}
165162

166163
int mp_thread_mutex_lock(mp_thread_mutex_t *mutex, int wait) {
167-
int ret = xSemaphoreTake(*mutex, wait ? portMAX_DELAY : 0);
164+
int ret = xSemaphoreTake(mutex->handle, wait ? portMAX_DELAY : 0);
168165
return ret == pdTRUE;
169166
}
170167

171168
void mp_thread_mutex_unlock(mp_thread_mutex_t *mutex) {
172-
xSemaphoreGive(*mutex);
169+
xSemaphoreGive(mutex->handle);
173170
// TODO check return value
174171
}
175172

cc3200/mpthreadport.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828

2929
#include "FreeRTOS.h"
3030

31-
typedef SemaphoreHandle_t mp_thread_mutex_t;
31+
typedef struct _mp_thread_mutex_t {
32+
SemaphoreHandle_t handle;
33+
StaticSemaphore_t buffer;
34+
} mp_thread_mutex_t;
3235

3336
void mp_thread_init(void);
3437
void mp_thread_gc_others(void);

0 commit comments

Comments
 (0)