From 2703ecc9e98819ab4d13bdb6da6e0d02ee840d86 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Tue, 21 Jun 2022 00:24:53 +0200 Subject: [BUG] Fix deadlocks on disconnected secondary half (#17423) --- platforms/synchronization_util.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'platforms/synchronization_util.h') diff --git a/platforms/synchronization_util.h b/platforms/synchronization_util.h index 3730f271db..81ce074cac 100644 --- a/platforms/synchronization_util.h +++ b/platforms/synchronization_util.h @@ -12,3 +12,33 @@ void split_shared_memory_unlock(void); inline void split_shared_memory_lock(void){}; inline void split_shared_memory_unlock(void){}; #endif + +/* GCCs cleanup attribute expects a function with one parameter, which is a + * pointer to a type compatible with the variable. As we don't want to expose + * the platforms internal mutex type this workaround with auto generated adapter + * function is defined */ +#define QMK_DECLARE_AUTOUNLOCK_HELPERS(prefix) \ + inline unsigned prefix##_autounlock_lock_helper(void) { \ + prefix##_lock(); \ + return 0; \ + } \ + \ + inline void prefix##_autounlock_unlock_helper(unsigned* unused_guard) { \ + prefix##_unlock(); \ + } + +/* Convinience macro the automatically generate the correct RAII-style + * lock_autounlock function macro */ +#define QMK_DECLARE_AUTOUNLOCK_CALL(prefix) unsigned prefix##_guard __attribute__((unused, cleanup(prefix##_autounlock_unlock_helper))) = prefix##_autounlock_lock_helper + +QMK_DECLARE_AUTOUNLOCK_HELPERS(split_shared_memory) + +/** + * @brief Acquire exclusive access to the split keyboard shared memory, by + * calling the platforms `split_shared_memory_lock()` function. The lock is + * automatically released by calling the platforms `split_shared_memory_unlock()` + * function. This happens when the block where + * `split_shared_memory_lock_autounlock()` is called in goes out of scope i.e. + * when the enclosing function returns. + */ +#define split_shared_memory_lock_autounlock QMK_DECLARE_AUTOUNLOCK_CALL(split_shared_memory) -- cgit v1.2.3 From 6a81cb44f2ec10472fd58496ad18f812798cc275 Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Tue, 21 Jun 2022 01:31:20 +0200 Subject: [Fix] Fix compilation warning for non-split keebs after #17423 (#17439) --- platforms/synchronization_util.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'platforms/synchronization_util.h') diff --git a/platforms/synchronization_util.h b/platforms/synchronization_util.h index 81ce074cac..59933945c3 100644 --- a/platforms/synchronization_util.h +++ b/platforms/synchronization_util.h @@ -9,8 +9,10 @@ void split_shared_memory_lock(void); void split_shared_memory_unlock(void); # endif #else +# if defined(SPLIT_KEYBOARD) inline void split_shared_memory_lock(void){}; inline void split_shared_memory_unlock(void){}; +# endif #endif /* GCCs cleanup attribute expects a function with one parameter, which is a @@ -31,6 +33,7 @@ inline void split_shared_memory_unlock(void){}; * lock_autounlock function macro */ #define QMK_DECLARE_AUTOUNLOCK_CALL(prefix) unsigned prefix##_guard __attribute__((unused, cleanup(prefix##_autounlock_unlock_helper))) = prefix##_autounlock_lock_helper +#if defined(SPLIT_KEYBOARD) QMK_DECLARE_AUTOUNLOCK_HELPERS(split_shared_memory) /** @@ -41,4 +44,5 @@ QMK_DECLARE_AUTOUNLOCK_HELPERS(split_shared_memory) * `split_shared_memory_lock_autounlock()` is called in goes out of scope i.e. * when the enclosing function returns. */ -#define split_shared_memory_lock_autounlock QMK_DECLARE_AUTOUNLOCK_CALL(split_shared_memory) +# define split_shared_memory_lock_autounlock QMK_DECLARE_AUTOUNLOCK_CALL(split_shared_memory) +#endif -- cgit v1.2.3