From 3d5d9aebfb176fe3d81812f7d5d2b07dc5b44f52 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 1 Jul 2018 12:43:56 +0000 Subject: [PATCH] migrated Mutex to Mutex.hpp --- qse/include/qse/si/Makefile.am | 1 + qse/include/qse/si/Makefile.in | 5 +- qse/include/qse/si/Mutex.hpp | 86 +++++++++++++++++++++++++++++++++ qse/include/qse/si/SpinLock.hpp | 34 ------------- 4 files changed, 90 insertions(+), 36 deletions(-) create mode 100644 qse/include/qse/si/Mutex.hpp diff --git a/qse/include/qse/si/Makefile.am b/qse/include/qse/si/Makefile.am index 2e5dd16e..4e80e040 100644 --- a/qse/include/qse/si/Makefile.am +++ b/qse/include/qse/si/Makefile.am @@ -30,6 +30,7 @@ pkginclude_HEADERS = \ if ENABLE_CXX pkginclude_HEADERS += \ AppRoot.hpp \ + Mutex.hpp \ SocketAddress.hpp \ Socket.hpp \ SpinLock.hpp \ diff --git a/qse/include/qse/si/Makefile.in b/qse/include/qse/si/Makefile.in index d94f8c1b..e8f9b4b5 100644 --- a/qse/include/qse/si/Makefile.in +++ b/qse/include/qse/si/Makefile.in @@ -89,6 +89,7 @@ build_triplet = @build@ host_triplet = @host@ @ENABLE_CXX_TRUE@am__append_1 = \ @ENABLE_CXX_TRUE@ AppRoot.hpp \ +@ENABLE_CXX_TRUE@ Mutex.hpp \ @ENABLE_CXX_TRUE@ SocketAddress.hpp \ @ENABLE_CXX_TRUE@ Socket.hpp \ @ENABLE_CXX_TRUE@ SpinLock.hpp \ @@ -134,8 +135,8 @@ am__can_run_installinfo = \ am__pkginclude_HEADERS_DIST = aio.h aio-pro.h aio-sck.h cnd.h dir.h \ fio.h fs.h glob.h intr.h log.h mtx.h mux.h nwad.h nwif.h \ nwio.h os.h pio.h rwl.h sck.h sinfo.h sio.h spl.h task.h thr.h \ - tio.h AppRoot.hpp SocketAddress.hpp Socket.hpp SpinLock.hpp \ - TcpServer.hpp Thread.hpp + tio.h AppRoot.hpp Mutex.hpp SocketAddress.hpp Socket.hpp \ + SpinLock.hpp TcpServer.hpp Thread.hpp am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ diff --git a/qse/include/qse/si/Mutex.hpp b/qse/include/qse/si/Mutex.hpp new file mode 100644 index 00000000..1e37ce65 --- /dev/null +++ b/qse/include/qse/si/Mutex.hpp @@ -0,0 +1,86 @@ +/* + * $Id$ + * + Copyright (c) 2006-2014 Chung, Hyung-Hwan. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EQSERESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _QSE_SI_MUTEX_CLASS_ +#define _QSE_SI_MUTEX_CLASS_ + +#include +#include +#include + +QSE_BEGIN_NAMESPACE(QSE) + +class Mutex: public Uncopyable +{ +public: + Mutex() QSE_CPP_NOEXCEPT + { + qse_mtx_init (&this->mtx, QSE_NULL); + } + ~Mutex() QSE_CPP_NOEXCEPT + { + qse_mtx_fini (&this->mtx); + } + +#if 0 + bool tryock() QSE_CPP_NOEXCEPT + { + } +#endif + + void lock () QSE_CPP_NOEXCEPT + { + qse_mtx_lock (&this->mtx, QSE_NULL); + } + + void unlock () QSE_CPP_NOEXCEPT + { + qse_mtx_unlock (&this->mtx); + } + +protected: + qse_mtx_t mtx; +}; + +class ScopedMutexLocker: public Uncopyable +{ +public: + ScopedMutexLocker (Mutex& mtx) QSE_CPP_NOEXCEPT: mtx(mtx) + { + this->mtx.lock (); + } + + ~ScopedMutexLocker () QSE_CPP_NOEXCEPT + { + this->mtx.unlock (); + } + +protected: + Mutex& mtx; +}; +QSE_END_NAMESPACE(QSE) + +#endif diff --git a/qse/include/qse/si/SpinLock.hpp b/qse/include/qse/si/SpinLock.hpp index 723dfbba..9663fca0 100644 --- a/qse/include/qse/si/SpinLock.hpp +++ b/qse/include/qse/si/SpinLock.hpp @@ -43,7 +43,6 @@ # include #endif -#include QSE_BEGIN_NAMESPACE(QSE) class SpinLock: public Uncopyable @@ -115,39 +114,6 @@ protected: SpinLock& spl; }; - -class Mutex: public Uncopyable -{ -public: - Mutex() QSE_CPP_NOEXCEPT - { - qse_mtx_init (&this->mtx, QSE_NULL); - } - ~Mutex() QSE_CPP_NOEXCEPT - { - qse_mtx_fini (&this->mtx); - } - -#if 0 - bool tryock() QSE_CPP_NOEXCEPT - { - } -#endif - - void lock () QSE_CPP_NOEXCEPT - { - qse_mtx_lock (&this->mtx, QSE_NULL); - } - - void unlock () QSE_CPP_NOEXCEPT - { - qse_mtx_unlock (&this->mtx); - } - -protected: - qse_mtx_t mtx; -}; - QSE_END_NAMESPACE(QSE) #endif