From 7712a286dccea029785976311433cf8673594f6f Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Tue, 19 Apr 2022 12:56:16 +0200 Subject: [Core] Use a mutex guard for split shared memory (#16647) --- platforms/chibios/synchronization_util.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 platforms/chibios/synchronization_util.c (limited to 'platforms/chibios/synchronization_util.c') diff --git a/platforms/chibios/synchronization_util.c b/platforms/chibios/synchronization_util.c new file mode 100644 index 0000000000..bc4a4e621f --- /dev/null +++ b/platforms/chibios/synchronization_util.c @@ -0,0 +1,26 @@ +// Copyright 2022 Stefan Kerkmann +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "synchronization_util.h" +#include "ch.h" + +#if defined(SPLIT_KEYBOARD) +static MUTEX_DECL(SPLIT_SHARED_MEMORY_MUTEX); + +/** + * @brief Acquire exclusive access to the split keyboard shared memory, by + * locking the mutex guarding it. If the mutex is already held, the calling + * thread will be suspended until the mutex currently owning thread releases the + * mutex again. + */ +void split_shared_memory_lock(void) { + chMtxLock(&SPLIT_SHARED_MEMORY_MUTEX); +} + +/** + * @brief Release the split shared memory mutex that has been acquired before. + */ +void split_shared_memory_unlock(void) { + chMtxUnlock(&SPLIT_SHARED_MEMORY_MUTEX); +} +#endif -- cgit v1.2.3