From e874ef9b845424dceeac4211ca9dfec24949f03c Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Mon, 9 Sep 2019 17:40:33 +0100 Subject: COMPMID-2646: Wrap thread-related structure to ease bare-metal support Wraps "lock_guard" and "unique_lock" to ease bare-metal support. Adds basic armclang compilation flow. Change-Id: I44ccd042652acd6a9b442c57c879db3891abb0e2 Signed-off-by: Georgios Pinitas Reviewed-on: https://review.mlplatform.org/c/1923 Tested-by: Arm Jenkins Reviewed-by: Pablo Marquez Comments-Addressed: Arm Jenkins --- support/Mutex.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'support/Mutex.h') diff --git a/support/Mutex.h b/support/Mutex.h index d70dd7595b..c398c570af 100644 --- a/support/Mutex.h +++ b/support/Mutex.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2018 ARM Limited. + * Copyright (c) 2017-2019 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -31,6 +31,14 @@ namespace arm_compute #ifndef NO_MULTI_THREADING /** Wrapper of Mutex data-object */ using Mutex = std::mutex; + +/** Wrapper of lock_guard data-object */ +template +using lock_guard = std::lock_guard; + +/** Wrapper of lock_guard data-object */ +template +using unique_lock = std::unique_lock; #else /* NO_MULTI_THREADING */ /** Wrapper implementation of Mutex data-object */ class Mutex @@ -56,6 +64,62 @@ public: return true; } }; + +/** Wrapper implementation of lock-guard data-object */ +template +class lock_guard +{ +public: + typedef Mutex mutex_type; + +public: + explicit lock_guard(Mutex &m_) + : m(m_) + { + } + ~lock_guard() + { + } + lock_guard(const lock_guard &) = delete; + +private: + mutex_type &m; +}; + +/** Wrapper implementation of unique-lock data-object */ +template +class unique_lock +{ +public: + typedef Mutex mutex_type; + +public: + unique_lock() noexcept : m(nullptr) + { + } + explicit unique_lock(mutex_type &m) + : m(&m) + { + } + unique_lock(const unique_lock &) = delete; + unique_lock(unique_lock &&) = default; + unique_lock &operator=(const unique_lock &) = delete; + unique_lock &operator=(unique_lock &&) = default; + ~unique_lock() = default; + void lock() + { + } + bool try_lock() + { + return true; + } + void unlock() + { + } + +private: + mutex_type *m; +}; #endif /* NO_MULTI_THREADING */ } #endif /* __ARM_COMPUTE_MUTEX_H__ */ -- cgit v1.2.1