From d5409daa794d9384555eb540e3baaaa8b6a8600c Mon Sep 17 00:00:00 2001 From: Vojtech Horky Date: Thu, 13 Jul 2023 22:05:54 +0200 Subject: [PATCH] C++: mutex::init should be constexpr --- uspace/lib/c/generic/thread/fibril_synch.c | 7 ------- uspace/lib/c/include/adt/list.h | 2 +- uspace/lib/c/include/fibril_synch.h | 14 +++++++++++++- uspace/lib/cpp/include/__bits/thread/threading.hpp | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/uspace/lib/c/generic/thread/fibril_synch.c b/uspace/lib/c/generic/thread/fibril_synch.c index 54a05e925..2326d001a 100644 --- a/uspace/lib/c/generic/thread/fibril_synch.c +++ b/uspace/lib/c/generic/thread/fibril_synch.c @@ -161,13 +161,6 @@ static void check_for_deadlock(fibril_owner_info_t *oi) check_fibril_for_deadlock(oi, fibril_self()); } -void fibril_mutex_initialize(fibril_mutex_t *fm) -{ - fm->oi.owned_by = NULL; - fm->counter = 1; - list_initialize(&fm->waiters); -} - void fibril_mutex_lock(fibril_mutex_t *fm) { fibril_t *f = (fibril_t *) fibril_get_id(); diff --git a/uspace/lib/c/include/adt/list.h b/uspace/lib/c/include/adt/list.h index 0c8cbf965..9013a6380 100644 --- a/uspace/lib/c/include/adt/list.h +++ b/uspace/lib/c/include/adt/list.h @@ -182,7 +182,7 @@ _NO_TRACE static inline void link_initialize(link_t *link) * @param list Pointer to list_t structure. * */ -_NO_TRACE static inline void list_initialize(list_t *list) +_NO_TRACE static inline __CONSTEXPR void list_initialize(list_t *list) { list->head.prev = &list->head; list->head.next = &list->head; diff --git a/uspace/lib/c/include/fibril_synch.h b/uspace/lib/c/include/fibril_synch.h index db374ed4a..fc32aa13d 100644 --- a/uspace/lib/c/include/fibril_synch.h +++ b/uspace/lib/c/include/fibril_synch.h @@ -152,7 +152,19 @@ typedef struct { extern void __fibril_synch_init(void); extern void __fibril_synch_fini(void); -extern void fibril_mutex_initialize(fibril_mutex_t *); +/** Initialize fibril mutex. + * + * Kept as in-line to allow constexpr marker for C++ library where this + * is used by C++ mutex type (list initialization are two assignments + * so it is actually reasonable to have this inlined). + */ +static inline __CONSTEXPR void fibril_mutex_initialize(fibril_mutex_t *fm) +{ + fm->oi.owned_by = NULL; + fm->counter = 1; + list_initialize(&fm->waiters); +} + extern void fibril_mutex_lock(fibril_mutex_t *); extern bool fibril_mutex_trylock(fibril_mutex_t *); extern void fibril_mutex_unlock(fibril_mutex_t *); diff --git a/uspace/lib/cpp/include/__bits/thread/threading.hpp b/uspace/lib/cpp/include/__bits/thread/threading.hpp index 76de59184..020800775 100644 --- a/uspace/lib/cpp/include/__bits/thread/threading.hpp +++ b/uspace/lib/cpp/include/__bits/thread/threading.hpp @@ -86,7 +86,7 @@ namespace std::aux struct mutex { - static void init(mutex_type& mtx) + static constexpr void init(mutex_type& mtx) { ::helenos::fibril_mutex_initialize(&mtx); } -- 2.11.4.GIT