X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Facess2.git;a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc%2B%2B.so_src%2Finclude_exp%2Fmutex;fp=Usermode%2FLibraries%2Flibc%2B%2B.so_src%2Finclude_exp%2Fmutex;h=d3d9ffd379f17c81c8cdadc922124b2925feaa62;hp=0000000000000000000000000000000000000000;hb=845b6f9d90bb87b5e760e4d49aa93b0e003ab750;hpb=67a7fe2bb79eceaf10c572a99bd8345c4e81cf5b diff --git a/Usermode/Libraries/libc++.so_src/include_exp/mutex b/Usermode/Libraries/libc++.so_src/include_exp/mutex new file mode 100644 index 00000000..d3d9ffd3 --- /dev/null +++ b/Usermode/Libraries/libc++.so_src/include_exp/mutex @@ -0,0 +1,76 @@ +/* + * Acess2 C++ Library + * - By John Hodge (thePowersGang) + * + * mutex (header) + * - C++11's tutex handling + */ +#ifndef _LIBCXX_MUTEX_ +#define _LIBCXX_MUTEX_ + +#include "_libcxx_helpers.h" + +#if !_CXX11_AVAIL +# error " requires C++11 support" +#endif + +namespace std { + +#if _CXX11_AVAIL + +class mutex +{ +public: + constexpr mutex() noexcept: + m_flag(false) + { + } + mutex(const mutex&) = delete; + mutex& operator=(const mutex&) = delete; + ~mutex(); + + void lock(); + bool try_lock(); + void unlock(); + + typedef void* native_handle; +private: + // TODO: Proper userland mutex support + bool m_flag; +}; + +struct defer_lock_t {}; +struct try_to_lock_t {}; +struct adopt_lock_t {}; + +template< class Mutex > +class lock_guard +{ +public: + typedef Mutex mutex_type; +private: + mutex_type& m_lock; +public: + lock_guard(mutex_type& m): + m_lock(m) + { + m_lock.lock(); + } + lock_guard(mutex_type& m, std::adopt_lock_t t): + m_lock(m) + { + // Adopted + } + ~lock_guard() { + m_lock.unlock(); + } +}; + +#endif + +}; // namespace std + +#endif + +// vim: ft=cpp +