TactilityKernel improvements and more (#459)
This commit is contained in:
committed by
GitHub
parent
96eccbdc8d
commit
dfe2c865d1
@@ -12,6 +12,7 @@ extern "C" {
|
||||
|
||||
struct Mutex {
|
||||
QueueHandle_t handle;
|
||||
// TODO: Debugging functionality
|
||||
};
|
||||
|
||||
inline static void mutex_construct(struct Mutex* mutex) {
|
||||
@@ -27,18 +28,30 @@ inline static void mutex_destruct(struct Mutex* mutex) {
|
||||
}
|
||||
|
||||
inline static void mutex_lock(struct Mutex* mutex) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
xSemaphoreTake(mutex->handle, portMAX_DELAY);
|
||||
}
|
||||
|
||||
inline static bool mutex_try_lock(struct Mutex* mutex) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
return xSemaphoreTake(mutex->handle, 0) == pdTRUE;
|
||||
}
|
||||
|
||||
inline static bool mutex_try_lock_timed(struct Mutex* mutex, TickType_t timeout) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
return xSemaphoreTake(mutex->handle, timeout) == pdTRUE;
|
||||
}
|
||||
|
||||
inline static bool mutex_is_locked(struct Mutex* mutex) {
|
||||
return xSemaphoreGetMutexHolder(mutex->handle) != NULL;
|
||||
if (xPortInIsrContext() == pdTRUE) {
|
||||
return xSemaphoreGetMutexHolderFromISR(mutex->handle) != NULL;
|
||||
} else {
|
||||
return xSemaphoreGetMutexHolder(mutex->handle) != NULL;
|
||||
}
|
||||
}
|
||||
|
||||
inline static void mutex_unlock(struct Mutex* mutex) {
|
||||
assert(xPortInIsrContext() != pdTRUE);
|
||||
xSemaphoreGive(mutex->handle);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user