You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
clang format apply
This commit is contained in:
@ -44,31 +44,31 @@ using namespace boost;
|
||||
|
||||
#ifdef DEBUG
|
||||
using namespace std;
|
||||
#define PRINTSTATE() \
|
||||
cerr << " reading = " << state.reading << endl \
|
||||
<< " writing = " << state.writing << endl \
|
||||
<< " readerswaiting = " << state.readerswaiting << endl \
|
||||
<< " writerswaiting = " << state.writerswaiting << endl;
|
||||
#define PRINTSTATE() \
|
||||
cerr << " reading = " << state.reading << endl \
|
||||
<< " writing = " << state.writing << endl \
|
||||
<< " readerswaiting = " << state.readerswaiting << endl \
|
||||
<< " writerswaiting = " << state.writerswaiting << endl;
|
||||
|
||||
#define CHECKSAFETY() \
|
||||
if (!((state.reading == 0 && (state.writing == 0 || state.writing == 1)) || \
|
||||
(state.reading > 0 && state.writing == 0))) { \
|
||||
cerr << "RWLock_local::" << __func__ << ": safety invariant violation" << endl; \
|
||||
PRINTSTATE(); \
|
||||
throw std::logic_error("RWLock_local: safety invariant violation"); \
|
||||
}
|
||||
#define CHECKSAFETY() \
|
||||
if (!((state.reading == 0 && (state.writing == 0 || state.writing == 1)) || \
|
||||
(state.reading > 0 && state.writing == 0))) \
|
||||
{ \
|
||||
cerr << "RWLock_local::" << __func__ << ": safety invariant violation" << endl; \
|
||||
PRINTSTATE(); \
|
||||
throw std::logic_error("RWLock_local: safety invariant violation"); \
|
||||
}
|
||||
|
||||
#define CHECKLIVENESS() \
|
||||
if (!( \
|
||||
(!(state.readerswaiting > 0 || state.writerswaiting > 0) || \
|
||||
(state.reading > 0 || state.writing > 0)) || \
|
||||
(!(state.reading == 0 && state.writing == 0) || \
|
||||
(state.readerswaiting == 0 && state.writerswaiting == 0)) \
|
||||
)) { \
|
||||
cerr << "RWLock_local::" << __func__ << ": liveness invariant violation" << endl; \
|
||||
PRINTSTATE(); \
|
||||
throw std::logic_error("RWLock_local: liveness invariant violation"); \
|
||||
}
|
||||
#define CHECKLIVENESS() \
|
||||
if (!((!(state.readerswaiting > 0 || state.writerswaiting > 0) || \
|
||||
(state.reading > 0 || state.writing > 0)) || \
|
||||
(!(state.reading == 0 && state.writing == 0) || \
|
||||
(state.readerswaiting == 0 && state.writerswaiting == 0)))) \
|
||||
{ \
|
||||
cerr << "RWLock_local::" << __func__ << ": liveness invariant violation" << endl; \
|
||||
PRINTSTATE(); \
|
||||
throw std::logic_error("RWLock_local: liveness invariant violation"); \
|
||||
}
|
||||
|
||||
#undef CHECKLIVENESS
|
||||
#define CHECKLIVENESS()
|
||||
@ -77,13 +77,12 @@ using namespace std;
|
||||
|
||||
namespace rwlock
|
||||
{
|
||||
|
||||
RWLock_local::RWLock_local()
|
||||
{
|
||||
state.reading = 0;
|
||||
state.readerswaiting = 0;
|
||||
state.writing = 0;
|
||||
state.writerswaiting = 0;
|
||||
state.reading = 0;
|
||||
state.readerswaiting = 0;
|
||||
state.writing = 0;
|
||||
state.writerswaiting = 0;
|
||||
}
|
||||
|
||||
RWLock_local::~RWLock_local()
|
||||
@ -92,147 +91,145 @@ RWLock_local::~RWLock_local()
|
||||
|
||||
void RWLock_local::read_lock()
|
||||
{
|
||||
mutex.lock();
|
||||
mutex.lock();
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
if (state.writerswaiting > 0 || state.writing > 0)
|
||||
{
|
||||
state.readerswaiting++;
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
if (state.writerswaiting > 0 || state.writing > 0)
|
||||
{
|
||||
state.readerswaiting++;
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
while (state.writerswaiting > 0 || state.writing > 0)
|
||||
okToRead.wait(mutex);
|
||||
|
||||
while (state.writerswaiting > 0 || state.writing > 0)
|
||||
okToRead.wait(mutex);
|
||||
state.readerswaiting--;
|
||||
}
|
||||
|
||||
state.readerswaiting--;
|
||||
}
|
||||
|
||||
state.reading++;
|
||||
state.reading++;
|
||||
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
mutex.unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void RWLock_local::read_unlock()
|
||||
{
|
||||
mutex.lock();
|
||||
mutex.lock();
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
state.reading--;
|
||||
state.reading--;
|
||||
|
||||
if (state.writerswaiting > 0 && state.reading == 0)
|
||||
okToWrite.notify_one();
|
||||
if (state.writerswaiting > 0 && state.reading == 0)
|
||||
okToWrite.notify_one();
|
||||
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
mutex.unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void RWLock_local::write_lock()
|
||||
{
|
||||
mutex.lock();
|
||||
mutex.lock();
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
if (state.writing > 0 || state.reading > 0)
|
||||
{
|
||||
state.writerswaiting++;
|
||||
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
while (state.writing > 0 || state.reading > 0)
|
||||
okToWrite.wait(mutex);
|
||||
|
||||
state.writerswaiting--;
|
||||
}
|
||||
|
||||
state.writing++;
|
||||
if (state.writing > 0 || state.reading > 0)
|
||||
{
|
||||
state.writerswaiting++;
|
||||
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
while (state.writing > 0 || state.reading > 0)
|
||||
okToWrite.wait(mutex);
|
||||
|
||||
state.writerswaiting--;
|
||||
}
|
||||
|
||||
state.writing++;
|
||||
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
}
|
||||
|
||||
void RWLock_local::write_unlock()
|
||||
{
|
||||
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
state.writing--;
|
||||
state.writing--;
|
||||
|
||||
if (state.writerswaiting > 0)
|
||||
okToWrite.notify_one();
|
||||
else if (state.readerswaiting > 0)
|
||||
okToRead.notify_all();
|
||||
if (state.writerswaiting > 0)
|
||||
okToWrite.notify_one();
|
||||
else if (state.readerswaiting > 0)
|
||||
okToRead.notify_all();
|
||||
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
mutex.unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void RWLock_local::upgrade_to_write()
|
||||
{
|
||||
mutex.lock();
|
||||
mutex.lock();
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
state.reading--;
|
||||
|
||||
// try to cut in line
|
||||
if (state.reading == 0)
|
||||
{
|
||||
state.writing++;
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
state.reading--;
|
||||
return;
|
||||
}
|
||||
|
||||
// try to cut in line
|
||||
if (state.reading == 0)
|
||||
{
|
||||
state.writing++;
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
// cut & paste from write_lock()
|
||||
if (state.writing > 0 || state.reading > 0)
|
||||
{
|
||||
state.writerswaiting++;
|
||||
// cut & paste from write_lock()
|
||||
if (state.writing > 0 || state.reading > 0)
|
||||
{
|
||||
state.writerswaiting++;
|
||||
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
while (state.writing > 0 || state.reading > 0)
|
||||
okToWrite.wait(mutex);
|
||||
while (state.writing > 0 || state.reading > 0)
|
||||
okToWrite.wait(mutex);
|
||||
|
||||
state.writerswaiting--;
|
||||
}
|
||||
state.writerswaiting--;
|
||||
}
|
||||
|
||||
state.writing++;
|
||||
state.writing++;
|
||||
}
|
||||
|
||||
/* It's safe (and necessary) to simply convert this writer to a reader without
|
||||
@ -240,88 +237,87 @@ void RWLock_local::upgrade_to_write()
|
||||
void RWLock_local::downgrade_to_read()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
|
||||
state.writing--;
|
||||
state.writing--;
|
||||
|
||||
if (state.readerswaiting > 0)
|
||||
okToRead.notify_all();
|
||||
if (state.readerswaiting > 0)
|
||||
okToRead.notify_all();
|
||||
|
||||
state.reading++;
|
||||
state.reading++;
|
||||
|
||||
#ifdef DEBUG
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
CHECKSAFETY();
|
||||
CHECKLIVENESS();
|
||||
#endif
|
||||
mutex.unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void RWLock_local::lock()
|
||||
{
|
||||
mutex.lock();
|
||||
mutex.lock();
|
||||
}
|
||||
|
||||
void RWLock_local::unlock()
|
||||
{
|
||||
mutex.unlock();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
int RWLock_local::getWriting()
|
||||
{
|
||||
return state.writing;
|
||||
return state.writing;
|
||||
}
|
||||
|
||||
int RWLock_local::getReading()
|
||||
{
|
||||
return state.reading;
|
||||
return state.reading;
|
||||
}
|
||||
|
||||
int RWLock_local::getWritersWaiting()
|
||||
{
|
||||
return state.writerswaiting;
|
||||
return state.writerswaiting;
|
||||
}
|
||||
|
||||
int RWLock_local::getReadersWaiting()
|
||||
{
|
||||
return state.readerswaiting;
|
||||
return state.readerswaiting;
|
||||
}
|
||||
|
||||
ScopedRWLock_local::ScopedRWLock_local(RWLock_local* l, rwlock_mode m)
|
||||
{
|
||||
thelock = l;
|
||||
mode = m;
|
||||
assert(m == R || m == W);
|
||||
locked = false;
|
||||
lock();
|
||||
thelock = l;
|
||||
mode = m;
|
||||
assert(m == R || m == W);
|
||||
locked = false;
|
||||
lock();
|
||||
}
|
||||
|
||||
ScopedRWLock_local::~ScopedRWLock_local()
|
||||
{
|
||||
if (locked)
|
||||
unlock();
|
||||
if (locked)
|
||||
unlock();
|
||||
}
|
||||
|
||||
void ScopedRWLock_local::lock()
|
||||
{
|
||||
if (mode == R)
|
||||
thelock->read_lock();
|
||||
else
|
||||
thelock->write_lock();
|
||||
if (mode == R)
|
||||
thelock->read_lock();
|
||||
else
|
||||
thelock->write_lock();
|
||||
|
||||
locked = true;
|
||||
locked = true;
|
||||
}
|
||||
|
||||
void ScopedRWLock_local::unlock()
|
||||
{
|
||||
if (mode == R)
|
||||
thelock->read_unlock();
|
||||
else
|
||||
thelock->write_unlock();
|
||||
|
||||
locked = false;
|
||||
}
|
||||
if (mode == R)
|
||||
thelock->read_unlock();
|
||||
else
|
||||
thelock->write_unlock();
|
||||
|
||||
locked = false;
|
||||
}
|
||||
|
||||
} // namespace rwlock
|
||||
|
Reference in New Issue
Block a user