migrated Mutex to Mutex.hpp

This commit is contained in:
hyung-hwan 2018-07-01 12:43:56 +00:00
parent 0cbdf10332
commit 3d5d9aebfb
4 changed files with 90 additions and 36 deletions

View File

@ -30,6 +30,7 @@ pkginclude_HEADERS = \
if ENABLE_CXX
pkginclude_HEADERS += \
AppRoot.hpp \
Mutex.hpp \
SocketAddress.hpp \
Socket.hpp \
SpinLock.hpp \

View File

@ -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/||"`;; \

View File

@ -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 <qse/Types.hpp>
#include <qse/Uncopyable.hpp>
#include <qse/si/mtx.h>
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

View File

@ -43,7 +43,6 @@
# include <atomic>
#endif
#include <qse/si/mtx.h>
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