Commit c9161a19 by Elvin Sindrilaru

COMMON: Refactor the RWMutex so that we benefit from the instrumentation also…

COMMON: Refactor the RWMutex so that we benefit from the instrumentation also when using std::shared_timed_mutex
parent 9d3c3e1e
......@@ -221,11 +221,8 @@ endif()
#-------------------------------------------------------------------------------
if(NOT CLIENT AND Linux)
add_executable(dbmaptestburn dbmaptest/DbMapTestBurn.cc)
add_executable(mutextest
mutextest/RWMutexTest.cc
RWMutex.cc
SharedMutex.cc
PthreadRWMutex.cc)
add_executable(mutextest mutextest/RWMutexTest.cc RWMutex.cc)
add_executable(dbmaptestfunc
dbmaptest/DbMapTestFunc.cc
${DBMAPTEST_SRCS}
......@@ -237,8 +234,7 @@ if(NOT CLIENT AND Linux)
${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(mutextest PRIVATE
eosCommon
eosCommonServer
eosCommon-Static
${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(dbmaptestfunc PRIVATE
......
......@@ -40,59 +40,42 @@ public:
virtual ~IRWMutex() = default;
//----------------------------------------------------------------------------
//! Set the write lock to blocking or not blocking
//!
//! @param block blocking mode
//----------------------------------------------------------------------------
virtual void SetBlocking(bool block) = 0;
//----------------------------------------------------------------------------
//! Lock for read
//----------------------------------------------------------------------------
virtual void LockRead() = 0;
virtual int LockRead() = 0;
//----------------------------------------------------------------------------
//! Unlock a read lock
//----------------------------------------------------------------------------
virtual void UnLockRead() = 0;
virtual int UnLockRead() = 0;
//----------------------------------------------------------------------------
//! Try to read lock the mutex within the timeout
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return true if lock acquired successfully, otherwise false
//! @return 0 if successful, otherwise error number
//----------------------------------------------------------------------------
virtual bool TimedRdLock(uint64_t timeout_ns) = 0;
virtual int TimedRdLock(uint64_t timeout_ns) = 0;
//----------------------------------------------------------------------------
//! Lock for write
//----------------------------------------------------------------------------
virtual void LockWrite() = 0;
virtual int LockWrite() = 0;
//----------------------------------------------------------------------------
//! Unlock a write lock
//----------------------------------------------------------------------------
virtual void UnLockWrite() = 0;
virtual int UnLockWrite() = 0;
//----------------------------------------------------------------------------
//! Try to write lock the mutex within the timeout
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return true if lock acquired successfully, otherwise false
//----------------------------------------------------------------------------
virtual bool TimedWrLock(uint64_t timeout_ns) = 0;
//----------------------------------------------------------------------------
//! Get read lock counter
//----------------------------------------------------------------------------
virtual uint64_t GetReadLockCounter() = 0;
//----------------------------------------------------------------------------
//! Get write lock counter
//! @return 0 if successful, otherwise error number
//----------------------------------------------------------------------------
virtual uint64_t GetWriteLockCounter() = 0;
virtual int TimedWrLock(uint64_t timeout_ns) = 0;
};
EOSCOMMONNAMESPACE_END
......@@ -27,61 +27,71 @@ EOSCOMMONNAMESPACE_BEGIN
//------------------------------------------------------------------------------
// Lock for read
//------------------------------------------------------------------------------
void
int
SharedMutex::LockRead()
{
++mRdLockCounter;
mSharedMutex.lock_shared();
return 0;
}
//------------------------------------------------------------------------------
// Unlock a read lock
//-----------------------------------------------------------------------------
void
int
SharedMutex::UnLockRead()
{
mSharedMutex.unlock_shared();
return 0;
}
//------------------------------------------------------------------------------
// Try to read lock the mutex within the timeout
//------------------------------------------------------------------------------
bool
int
SharedMutex::TimedRdLock(uint64_t timeout_ns)
{
std::chrono::nanoseconds ns(timeout_ns);
++mRdLockCounter;
return mSharedMutex.try_lock_shared_for(ns);
if (mSharedMutex.try_lock_shared_for(ns)) {
return 0;
} else {
return ETIMEDOUT;
}
}
//------------------------------------------------------------------------------
// Lock for write
//------------------------------------------------------------------------------
void
int
SharedMutex::LockWrite()
{
++mWrLockCounter;
mSharedMutex.lock();
return 0;
}
//------------------------------------------------------------------------------
// Unlock a write lock
//------------------------------------------------------------------------------
void
int
SharedMutex::UnLockWrite()
{
mSharedMutex.unlock();
return 0;
}
//------------------------------------------------------------------------------
// Try to write lock the mutex within the timeout
//------------------------------------------------------------------------------
bool
int
SharedMutex::TimedWrLock(uint64_t timeout_ns)
{
std::chrono::nanoseconds ns(timeout_ns);
++mWrLockCounter;
return mSharedMutex.try_lock_for(ns);
if (mSharedMutex.try_lock_for(ns)) {
return 0;
} else {
return ETIMEDOUT;
}
}
EOSCOMMONNAMESPACE_END
......@@ -24,7 +24,6 @@
#include "common/Namespace.hh"
#include "common/IRWMutex.hh"
#include <shared_mutex>
#include <atomic>
EOSCOMMONNAMESPACE_BEGIN
......@@ -67,71 +66,43 @@ public:
//----------------------------------------------------------------------------
//! Lock for read
//----------------------------------------------------------------------------
void LockRead() override;
int LockRead() override;
//----------------------------------------------------------------------------
//! Unlock a read lock
//----------------------------------------------------------------------------
void UnLockRead() override;
int UnLockRead() override;
//----------------------------------------------------------------------------
//! Try to read lock the mutex within the timeout
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return true if lock acquired successfully, otherwise false
//! @return 0 if successful, otherwise error number
//----------------------------------------------------------------------------
bool TimedRdLock(uint64_t timeout_ns) override;
int TimedRdLock(uint64_t timeout_ns) override;
//----------------------------------------------------------------------------
//! Lock for write
//----------------------------------------------------------------------------
void LockWrite() override;
int LockWrite() override;
//----------------------------------------------------------------------------
//! Unlock a write lock
//----------------------------------------------------------------------------
void UnLockWrite() override;
int UnLockWrite() override;
//----------------------------------------------------------------------------
//! Try to write lock the mutex within the timeout
//!
//! @param timeout_ns nano seconds timeout
//!
//! @return true if lock acquired successfully, otherwise false
//! @return 0 if successful, otherwise error number
//----------------------------------------------------------------------------
bool TimedWrLock(uint64_t timeout_ns) override;
//----------------------------------------------------------------------------
//! Get Readlock Counter
//----------------------------------------------------------------------------
inline uint64_t GetReadLockCounter() override
{
return mRdLockCounter.load();
}
//----------------------------------------------------------------------------
//! Get Writelock Counter
//----------------------------------------------------------------------------
uint64_t GetWriteLockCounter() override
{
return mWrLockCounter.load();
}
int TimedWrLock(uint64_t timeout_ns) override;
private:
//----------------------------------------------------------------------------
//! Set the write lock to blocking or not blocking
//!
//! @param block blocking mode
//----------------------------------------------------------------------------
inline void SetBlocking(bool block)
{
return; // no supported
}
std::shared_timed_mutex mSharedMutex;
std::atomic<uint64_t> mRdLockCounter; ///< Number of read lock operations
std::atomic<uint64_t> mWrLockCounter; ///< Number of write lock operations
};
EOSCOMMONNAMESPACE_END
......@@ -24,17 +24,16 @@
//----------------------------------------------------------------------------
// Program demonstrating the timing facilities of the RWMutex class
//----------------------------------------------------------------------------
#include <iostream>
#include "common/PthreadRWMutex.hh"
#include "common/RWMutex.hh"
#include <iostream>
using namespace eos::common;
const int loopsize = 10e6;
const unsigned long int NNUM_THREADS = 10;
pthread_t threads[NNUM_THREADS];
unsigned long int NUM_THREADS = NNUM_THREADS;
PthreadRWMutex globmutex;
PthreadRWMutex gm1, gm2, gm3;
RWMutex globmutex;
RWMutex gm1, gm2, gm3;
//----------------------------------------------------------------------------
//! Output to stream operator for TimingStats structure
......@@ -45,12 +44,12 @@ PthreadRWMutex gm1, gm2, gm3;
//! @return reference to output stream
//----------------------------------------------------------------------------
inline std::ostream& operator << (std::ostream& os,
const PthreadRWMutex::TimingStats& stats)
const RWMutex::TimingStats& stats)
{
os << "\t" << "PthreadRWMutex Read Wait (number : min , avg , max)" << " = "
os << "\t" << "RWMutex Read Wait (number : min , avg , max)" << " = "
<< stats.readLockCounterSample << " : " << stats.minwaitread << " , "
<< stats.averagewaitread << " , " << stats.maxwaitread << std::endl
<< "\t" << "PthreadRWMutex Write Wait (number : min , avg , max)" << " = "
<< "\t" << "RWMutex Write Wait (number : min , avg , max)" << " = "
<< stats.writeLockCounterSample << " : " << stats.minwaitwrite << " , "
<< stats.averagewaitwrite << " , " << stats.maxwaitwrite << std::endl;
return os;
......@@ -142,9 +141,9 @@ TestThread2(void* threadid)
int
main()
{
PthreadRWMutex::SetOrderCheckingGlobal(false);
std::cout << " Using Instrumented Version of PthreadRWMutex class" << std::endl;
PthreadRWMutex::EstimateLatenciesAndCompensation();
RWMutex::SetOrderCheckingGlobal(false);
std::cout << " Using Instrumented Version of RWMutex class" << std::endl;
RWMutex::EstimateLatenciesAndCompensation();
size_t t = Timing::GetNowInNs();
for (int k = 0; k < loopsize; ++k) {
......@@ -160,8 +159,8 @@ main()
1.0e9 << " sec" << " (" << double(loopsize) / (t / 1.0e9) << "Hz" << ")" <<
std::endl;
std::cout << " ------------------------- " << std::endl << std::endl;
PthreadRWMutex::SetTimingGlobal(true);
PthreadRWMutex mutex, mutex2;
RWMutex::SetTimingGlobal(true);
RWMutex mutex, mutex2;
mutex.SetTiming(true);
t = Timing::GetNowInNs();
......@@ -171,7 +170,7 @@ main()
}
t = Timing::GetNowInNs() - t;
PthreadRWMutex::TimingStats stats;
RWMutex::TimingStats stats;
mutex.GetTimingStatistics(stats);
std::cout << " ------------------------- " << std::endl;
std::cout << " Monothreaded Loop of size " << double(loopsize) << " took " <<
......@@ -180,7 +179,7 @@ main()
std::endl;
std::cout << stats;
std::cout << " ------------------------- " << std::endl << std::endl;
float rate = PthreadRWMutex::GetSamplingRateFromCPUOverhead(0.033);
float rate = RWMutex::GetSamplingRateFromCPUOverhead(0.033);
std::cout << " suggested sample rate is " << rate << std::endl << std::endl;
mutex2.SetTiming(true);
mutex2.SetSampling(true);
......@@ -199,9 +198,9 @@ main()
double(loopsize) / (t / 1.0e9) << "Hz" << ")" << std::endl;
std::cout << stats;
std::cout << " ------------------------- " << std::endl << std::endl;
PthreadRWMutex mutex3;
RWMutex mutex3;
// By default no local timing, but global timing with samplerate of 1
PthreadRWMutex::SetTimingGlobal(false);
RWMutex::SetTimingGlobal(false);
t = Timing::GetNowInNs();
for (int k = 0; k < loopsize; ++k) {
......@@ -217,7 +216,7 @@ main()
std::cout << " no stats available" << std::endl;
std::cout << " ------------------------- " << std::endl << std::endl;
globmutex.SetBlocking(true);
PthreadRWMutex::SetTimingGlobal(false);
RWMutex::SetTimingGlobal(false);
t = Timing::GetNowInNs();
RunThreads(&TestThread);
t = Timing::GetNowInNs() - t;
......@@ -232,7 +231,7 @@ main()
sleep(1);
//----------------------------------------------------------------------------
globmutex.SetBlocking(false);
PthreadRWMutex::SetTimingGlobal(false);
RWMutex::SetTimingGlobal(false);
t = Timing::GetNowInNs();
RunThreads(&TestThread);
t = Timing::GetNowInNs() - t;
......@@ -248,7 +247,7 @@ main()
//----------------------------------------------------------------------------
globmutex.SetBlocking(true);
globmutex.SetDeadlockCheck(true);
PthreadRWMutex::SetTimingGlobal(false);
RWMutex::SetTimingGlobal(false);
t = Timing::GetNowInNs();
RunThreads(&TestThread);
t = Timing::GetNowInNs() - t;
......@@ -273,7 +272,7 @@ main()
globmutex.SetTiming(true);
globmutex.SetSampling(true);
globmutex.ResetTimingStatistics();
PthreadRWMutex::SetTimingGlobal(true);
RWMutex::SetTimingGlobal(true);
t = Timing::GetNowInNs();
RunThreads(&TestThread);
t = Timing::GetNowInNs() - t;
......@@ -291,7 +290,7 @@ main()
globmutex.SetTiming(true);
globmutex.SetSampling(true);
globmutex.ResetTimingStatistics();
PthreadRWMutex::SetTimingGlobal(true);
RWMutex::SetTimingGlobal(true);
t = Timing::GetNowInNs();
RunThreads(&TestThread);
t = Timing::GetNowInNs() - t;
......@@ -306,26 +305,26 @@ main()
std::cout << " ------------------------- " << std::endl << std::endl;
std::cout << " ------------------------- " << std::endl;
std::cout << " Global statistics" << std::endl;
PthreadRWMutex::GetTimingStatisticsGlobal(stats);
RWMutex::GetTimingStatisticsGlobal(stats);
std::cout << stats;
std::cout << " ------------------------- " << std::endl << std::endl;
std::cout << "#################################################" << std::endl;
std::cout << "######## MONOTHREADED ORDER CHECKING TESTS ######" << std::endl;
std::cout << "#################################################" << std::endl;
PthreadRWMutex::SetTimingGlobal(false);
PthreadRWMutex::SetOrderCheckingGlobal(true);
vector<IRWMutex*> order;
RWMutex::SetTimingGlobal(false);
RWMutex::SetOrderCheckingGlobal(true);
vector<RWMutex*> order;
order.push_back(&gm1);
gm1.SetDebugName("mutex1");
order.push_back(&gm2);
gm2.SetDebugName("mutex2");
order.push_back(&gm3);
gm3.SetDebugName("mutex3");
PthreadRWMutex::AddOrderRule("rule1", order);
RWMutex::AddOrderRule("rule1", order);
order.clear();
order.push_back(&gm2);
order.push_back(&gm3);
PthreadRWMutex::AddOrderRule("rule2", order);
RWMutex::AddOrderRule("rule2", order);
std::cout << "==== Trying lock/unlock mutex in proper order... ====" <<
std::endl;
std::cout.flush();
......@@ -348,7 +347,7 @@ main()
gm1.UnLockWrite();
std::cout << "======== ... done ========" << std::endl << std::endl;
std::cout.flush();
PthreadRWMutex::SetOrderCheckingGlobal(false);
RWMutex::SetOrderCheckingGlobal(false);
t = Timing::GetNowInNs();
for (int k = 0; k < loopsize; ++k) {
......@@ -367,7 +366,7 @@ main()
<< double(loopsize) / (t / 1.0e9) << "Hz" << ")" << std::endl;
std::cout << " no stats available" << std::endl;
std::cout << " ------------------------- " << std::endl << std::endl;
PthreadRWMutex::SetOrderCheckingGlobal(true);
RWMutex::SetOrderCheckingGlobal(true);
t = Timing::GetNowInNs();
for (int k = 0; k < loopsize; ++k) {
......@@ -397,8 +396,8 @@ main()
int
main()
{
std::cout << " Using NON-Instrumented Version of PthreadRWMutex class" << std::endl;
PthreadRWMutex mutex3;
std::cout << " Using NON-Instrumented Version of RWMutex class" << std::endl;
RWMutex mutex3;
size_t t = Timing::GetNowInNs();
for (int k = 0; k < loopsize; ++k) {
......
......@@ -1172,7 +1172,7 @@ Stat::Circulate()
unsigned long long ns2 = 0;
unsigned long long view1 = 0;
unsigned long long view2 = 0;
eos::common::PthreadRWMutex::TimingStats qu12stmp, ns12stmp, view12stmp;
eos::common::RWMutex::TimingStats qu12stmp, ns12stmp, view12stmp;
unsigned long long ns1tmp = 0ull, ns2tmp = 0ull, view1tmp = 0ull,
view2tmp = 0ull, qu1tmp = 0ull, qu2tmp = 0ull;
#endif
......@@ -1187,32 +1187,24 @@ Stat::Circulate()
l2tmp = XrdMqSharedHash::sSetNLCounter.load();
l3tmp = XrdMqSharedHash::sGetCounter.load();
#ifdef EOS_INSTRUMENTED_RWMUTEX
eos::common::PthreadRWMutex* fs_mtx =
dynamic_cast<eos::common::PthreadRWMutex*>
(FsView::gFsView.ViewMutex.GetRawPtr());
eos::common::PthreadRWMutex* quota_mtx =
dynamic_cast<eos::common::PthreadRWMutex*>(Quota::pMapMutex.GetRawPtr());
eos::common::PthreadRWMutex* ns_mtx =
dynamic_cast<eos::common::PthreadRWMutex*>(gOFS->eosViewRWMutex.GetRawPtr());
if (fs_mtx && quota_mtx && ns_mtx) {
// fsview statistics extraction
view1tmp = fs_mtx->GetReadLockCounter();
view2tmp = fs_mtx->GetWriteLockCounter();
fs_mtx->GetTimingStatistics(view12stmp);
fs_mtx->ResetTimingStatistics();
// namespace lock statistics extraction
ns1tmp = ns_mtx->GetReadLockCounter();
ns2tmp = ns_mtx->GetWriteLockCounter();
ns_mtx->GetTimingStatistics(ns12stmp);
ns_mtx->ResetTimingStatistics();
// quota lock statistics extraction
qu1tmp = quota_mtx->GetReadLockCounter();
qu2tmp = quota_mtx->GetWriteLockCounter();
quota_mtx->GetTimingStatistics(qu12stmp);
quota_mtx->ResetTimingStatistics();
}
eos::common::RWMutex* fs_mtx = &FsView::gFsView.ViewMutex;
eos::common::RWMutex* quota_mtx = &Quota::pMapMutex;
eos::common::RWMutex* ns_mtx = &gOFS->eosViewRWMutex;
// fsview statistics extraction
view1tmp = fs_mtx->GetReadLockCounter();
view2tmp = fs_mtx->GetWriteLockCounter();
fs_mtx->GetTimingStatistics(view12stmp);
fs_mtx->ResetTimingStatistics();
// namespace lock statistics extraction
ns1tmp = ns_mtx->GetReadLockCounter();
ns2tmp = ns_mtx->GetWriteLockCounter();
ns_mtx->GetTimingStatistics(ns12stmp);
ns_mtx->ResetTimingStatistics();
// quota lock statistics extraction
qu1tmp = quota_mtx->GetReadLockCounter();
qu2tmp = quota_mtx->GetWriteLockCounter();
quota_mtx->GetTimingStatistics(qu12stmp);
quota_mtx->ResetTimingStatistics();
#endif
Add("HashSet", 0, 0, l1tmp - l1);
Add("HashSetNoLock", 0, 0, l2tmp - l2);
......
......@@ -1839,32 +1839,24 @@ XrdMgmOfs::Configure(XrdSysError& Eroute)
// default.eoscf in which it only holds a few entries.
FsView::gFsView.SetConfigEngine(ConfEngine);
#ifdef EOS_INSTRUMENTED_RWMUTEX
eos::common::PthreadRWMutex* fs_mtx =
dynamic_cast<eos::common::PthreadRWMutex*>
(FsView::gFsView.ViewMutex.GetRawPtr());
eos::common::PthreadRWMutex* quota_mtx =
dynamic_cast<eos::common::PthreadRWMutex*>(Quota::pMapMutex.GetRawPtr());
eos::common::PthreadRWMutex* ns_mtx =
dynamic_cast<eos::common::PthreadRWMutex*>(eosViewRWMutex.GetRawPtr());
if (fs_mtx && quota_mtx && ns_mtx) {
eos::common::PthreadRWMutex::EstimateLatenciesAndCompensation();
fs_mtx->SetDebugName("FsView");
fs_mtx->SetTiming(false);
fs_mtx->SetSampling(true, 0.01);
quota_mtx->SetDebugName("QuotaView");
quota_mtx->SetTiming(false);
quota_mtx->SetSampling(true, 0.01);
ns_mtx->SetDebugName("eosView");
ns_mtx->SetTiming(false);
ns_mtx->SetSampling(true, 0.01);
std::vector<eos::common::IRWMutex*> order;
order.push_back(FsView::gFsView.ViewMutex.GetRawPtr());
order.push_back(eosViewRWMutex.GetRawPtr());
order.push_back(Quota::pMapMutex.GetRawPtr());
eos::common::PthreadRWMutex::AddOrderRule("Eos Mgm Mutexes", order);
}
eos::common::RWMutex* fs_mtx = &FsView::gFsView.ViewMutex;
eos::common::RWMutex* quota_mtx = &Quota::pMapMutex;
eos::common::RWMutex* ns_mtx = &eosViewRWMutex;
eos::common::RWMutex::EstimateLatenciesAndCompensation();
fs_mtx->SetDebugName("FsView");
fs_mtx->SetTiming(false);
fs_mtx->SetSampling(true, 0.01);
quota_mtx->SetDebugName("QuotaView");
quota_mtx->SetTiming(false);
quota_mtx->SetSampling(true, 0.01);
ns_mtx->SetDebugName("eosView");
ns_mtx->SetTiming(false);
ns_mtx->SetSampling(true, 0.01);
std::vector<eos::common::RWMutex*> order;
order.push_back(fs_mtx);
order.push_back(ns_mtx);
order.push_back(quota_mtx);
eos::common::RWMutex::AddOrderRule("Eos Mgm Mutexes", order);
#endif
eos_info("starting statistics thread");
......
......@@ -83,41 +83,31 @@ NsCmd::MutexSubcmd(const eos::console::NsProto_MutexProto& mutex,
no_option = false;
}
eos::common::PthreadRWMutex* fs_mtx =
dynamic_cast<eos::common::PthreadRWMutex*>
(FsView::gFsView.ViewMutex.GetRawPtr());
eos::common::PthreadRWMutex* quota_mtx =
dynamic_cast<eos::common::PthreadRWMutex*>(Quota::pMapMutex.GetRawPtr());
eos::common::PthreadRWMutex* ns_mtx =
dynamic_cast<eos::common::PthreadRWMutex*>(gOFS->eosViewRWMutex.GetRawPtr());
if ((fs_mtx == nullptr) || (quota_mtx == nullptr) || (ns_mtx == nullptr)) {
reply.set_std_err("error: mutex type does not support such options");
reply.set_retc(EINVAL);
return;
}
eos::common::RWMutex* fs_mtx = &FsView::gFsView.ViewMutex;
eos::common::RWMutex* quota_mtx = &Quota::pMapMutex;
eos::common::RWMutex* ns_mtx = &gOFS->eosViewRWMutex;
if (no_option) {
size_t cycleperiod = eos::common::PthreadRWMutex::GetLockUnlockDuration();
size_t cycleperiod = eos::common::RWMutex::GetLockUnlockDuration();
std::string line = "# ------------------------------------------------------"
"------------------------------";
oss << line << std::endl
<< "# Mutex Monitoring Management" << std::endl
<< line << std::endl
<< "order checking is : "
<< (eos::common::PthreadRWMutex::GetOrderCheckingGlobal() ? "on " : "off")
<< (eos::common::RWMutex::GetOrderCheckingGlobal() ? "on " : "off")
<< " (estimated order checking latency for 1 rule ";
size_t orderlatency = eos::common::PthreadRWMutex::GetOrderCheckingLatency();
size_t orderlatency = eos::common::RWMutex::GetOrderCheckingLatency();
oss << orderlatency << " nsec / "
<< int(double(orderlatency) / cycleperiod * 100)
<< "% of the mutex lock/unlock cycle duration)" << std::endl
<< "deadlock checking is : "
<< (eos::common::PthreadRWMutex::GetDeadlockCheckingGlobal() ? "on" : "off")
<< (eos::common::RWMutex::GetDeadlockCheckingGlobal() ? "on" : "off")
<< std::endl
<< "timing is : "
<< (fs_mtx->GetTiming() ? "on " : "off")
<< " (estimated timing latency for 1 lock ";
size_t timinglatency = eos::common::PthreadRWMutex::GetTimingLatency();
size_t timinglatency = eos::common::RWMutex::GetTimingLatency();
oss << timinglatency << " nsec / "
<< int(double(timinglatency) / cycleperiod * 100)
<< "% of the mutex lock/unlock cycle duration)" << std::endl
......@@ -152,21 +142,21 @@ NsCmd::MutexSubcmd(const eos::console::NsProto_MutexProto& mutex,
}
if (mutex.toggle_order()) {
if (eos::common::PthreadRWMutex::GetOrderCheckingGlobal()) {
eos::common::PthreadRWMutex::SetOrderCheckingGlobal(false);
if (eos::common::RWMutex::GetOrderCheckingGlobal()) {
eos::common::RWMutex::SetOrderCheckingGlobal(false);
oss << "mutex order checking is off" << std::endl;
} else {
eos::common::PthreadRWMutex::SetOrderCheckingGlobal(true);
eos::common::RWMutex::SetOrderCheckingGlobal(true);
oss << "mutex order checking is on" << std::endl;
}
}
if (mutex.toggle_deadlock()) {
if (eos::common::PthreadRWMutex::GetDeadlockCheckingGlobal()) {
eos::common::PthreadRWMutex::SetDeadlockCheckingGlobal(false);
if (eos::common::RWMutex::GetDeadlockCheckingGlobal()) {
eos::common::RWMutex::SetDeadlockCheckingGlobal(false);
oss << "mutex deadlock checking is off" << std::endl;
} else {
eos::common::PthreadRWMutex::SetDeadlockCheckingGlobal(true);
eos::common::RWMutex::SetDeadlockCheckingGlobal(true);
oss << "mutex deadlock checking is on" << std::endl;
}
}
......
......@@ -23,14 +23,13 @@
#include "gtest/gtest.h"
#include "common/RWMutex.hh"
#include "common/PthreadRWMutex.hh"
//------------------------------------------------------------------------------
// Double write lock
//------------------------------------------------------------------------------
TEST(RWMutex, WriteDeadlockTest)
{
eos::common::PthreadRWMutex mutex;
eos::common::RWMutex mutex;
mutex.SetBlocking(true);
mutex.SetDeadlockCheck(true);
mutex.LockWrite();
......@@ -43,7 +42,7 @@ TEST(RWMutex, WriteDeadlockTest)
//------------------------------------------------------------------------------
TEST(RWMutex, RdWrRdDeadlockTest)
{
eos::common::PthreadRWMutex mutex(false);
eos::common::RWMutex mutex(false);
mutex.SetBlocking(true);
mutex.SetDeadlockCheck(true);
mutex.LockRead();
......@@ -64,7 +63,7 @@ TEST(RWMutex, RdWrRdDeadlockTest)
//------------------------------------------------------------------------------
TEST(RWMutex, RdWrRdNoDeadlockTest)
{
eos::common::PthreadRWMutex mutex(true);
eos::common::RWMutex mutex(true);
mutex.SetBlocking(true);
mutex.SetDeadlockCheck(true);
mutex.LockRead();
......@@ -86,7 +85,7 @@ TEST(RWMutex, RdWrRdNoDeadlockTest)
//------------------------------------------------------------------------------
TEST(RWMutex, MultiRdLockTest)
{
eos::common::PthreadRWMutex mutex(true);
eos::common::RWMutex mutex(true);
mutex.SetBlocking(true);
mutex.SetDeadlockCheck(true);
mutex.LockRead();
......@@ -108,7 +107,7 @@ TEST(RWMutex, MultiRdLockTest)
//------------------------------------------------------------------------------
TEST(RWMutex, MultiWrLockTest)
{
eos::common::PthreadRWMutex mutex(true);
eos::common::RWMutex mutex(true);
mutex.SetBlocking(true);
mutex.SetDeadlockCheck(true);
mutex.LockWrite();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment