// eventpp library // Copyright (C) 2018 Wang Qi (wqking) // Github: https://github.com/wqking/eventpp // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #ifndef EVENTOPTIONS_H_730367862613 #define EVENTOPTIONS_H_730367862613 #include "internal/typeutil_i.h" #include #include #include #include #include namespace eventpp { struct TagHomo {}; struct TagCallbackList : public TagHomo {}; struct TagEventDispatcher : public TagHomo {}; struct TagEventQueue : public TagHomo {}; struct TagHeter {}; struct TagHeterCallbackList : public TagHeter {}; struct TagHeterEventDispatcher : public TagHeter {}; struct TagHeterEventQueue : public TagHeter {}; struct SpinLock { public: void lock() { while(locked.test_and_set(std::memory_order_acquire)) { } } void unlock() { locked.clear(std::memory_order_release); } private: std::atomic_flag locked = ATOMIC_FLAG_INIT; }; template < typename Mutex_, template class Atomic_ = std::atomic, typename ConditionVariable_ = std::condition_variable > struct GeneralThreading { using Mutex = Mutex_; template using Atomic = Atomic_; using ConditionVariable = ConditionVariable_; }; struct MultipleThreading { using Mutex = std::mutex; template using Atomic = std::atomic; using ConditionVariable = std::condition_variable; }; struct SingleThreading { struct Mutex { void lock() {} void unlock() {} }; template struct Atomic { Atomic() noexcept = default; constexpr Atomic(T desired) noexcept : value(desired) { } void store(T desired, std::memory_order /*order*/ = std::memory_order_seq_cst) noexcept { value = desired; } T load(std::memory_order /*order*/ = std::memory_order_seq_cst) const noexcept { return value; } T exchange(T desired, std::memory_order /*order*/ = std::memory_order_seq_cst) noexcept { const T previous = value; value = desired; return previous; } T operator ++ () noexcept { return ++value; } T operator -- () noexcept { return --value; } T value; }; struct ConditionVariable { void notify_one() noexcept { } template void wait(std::unique_lock & /*lock*/, Predicate /*pred*/) { } template bool wait_for(std::unique_lock & /*lock*/, const std::chrono::duration & /*rel_time*/, Predicate /*pred*/ ) { return true; } }; }; struct ArgumentPassingAutoDetect { enum { canIncludeEventType = true, canExcludeEventType = true }; }; struct ArgumentPassingIncludeEvent { enum { canIncludeEventType = true, canExcludeEventType = false }; }; struct ArgumentPassingExcludeEvent { enum { canIncludeEventType = false, canExcludeEventType = true }; }; struct DefaultPolicies { }; template