1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-07 03:22:57 +03:00

Reformat all code to coding standard

This commit is contained in:
Andrew Hutchings
2017-10-26 17:18:17 +01:00
parent 4985f3456e
commit 01446d1e22
1296 changed files with 403852 additions and 353747 deletions

View File

@@ -20,7 +20,7 @@
*
*****************************************************************************/
/** @file
/** @file
* class RWLock interface
*/
@@ -45,80 +45,87 @@ namespace rwlock
{
/// the layout of the shmseg
struct State {
struct State
{
#ifdef _MSC_VER
volatile LONG writerswaiting;
volatile LONG writing;
volatile LONG readerswaiting;
volatile LONG reading;
volatile LONG writerswaiting;
volatile LONG writing;
volatile LONG readerswaiting;
volatile LONG reading;
#else
volatile int writerswaiting;
volatile int writing;
volatile int readerswaiting;
volatile int reading;
volatile int writerswaiting;
volatile int writing;
volatile int readerswaiting;
volatile int reading;
#endif
boost::interprocess::interprocess_semaphore sems[3];
boost::interprocess::interprocess_semaphore sems[3];
};
/* the lock state without the semaphores, passed out by timed_write_lock() for
class RWLockMonitor
*/
struct LockState {
struct LockState
{
#ifdef _MSC_VER
LONG writerswaiting;
LONG writing;
LONG readerswaiting;
LONG reading;
bool mutexLocked;
LONG writerswaiting;
LONG writing;
LONG readerswaiting;
LONG reading;
bool mutexLocked;
#else
int writerswaiting;
int writing;
int readerswaiting;
int reading;
bool mutexLocked;
int writerswaiting;
int writing;
int readerswaiting;
int reading;
bool mutexLocked;
#endif
};
class RWLockShmImpl
{
public:
static RWLockShmImpl* makeRWLockShmImpl(int key, bool* excl=0);
static RWLockShmImpl* makeRWLockShmImpl(int key, bool* excl = 0);
boost::interprocess::shared_memory_object fStateShm;
boost::interprocess::mapped_region fRegion;
State *fState;
boost::interprocess::shared_memory_object fStateShm;
boost::interprocess::mapped_region fRegion;
State* fState;
std::string keyString() { return fKeyString; }
std::string keyString()
{
return fKeyString;
}
private:
explicit RWLockShmImpl(int key, bool excl=false);
~RWLockShmImpl();
RWLockShmImpl(const RWLockShmImpl& rhs);
RWLockShmImpl& operator=(const RWLockShmImpl& rhs);
std::string fKeyString;
explicit RWLockShmImpl(int key, bool excl = false);
~RWLockShmImpl();
RWLockShmImpl(const RWLockShmImpl& rhs);
RWLockShmImpl& operator=(const RWLockShmImpl& rhs);
std::string fKeyString;
};
class not_excl : public std::exception
{
public:
virtual const char* what() const throw() {
return "not_excl";
}
public:
virtual const char* what() const throw()
{
return "not_excl";
}
};
class wouldblock : public std::exception
{
public:
virtual const char* what() const throw() {
return "wouldblock";
}
public:
virtual const char* what() const throw()
{
return "wouldblock";
}
};
/** @brief Implements RW locks for use across threads & processes
*
* Implements RW locks for use across threads & processes. Every
*
* Implements RW locks for use across threads & processes. Every
* instance that shares a lock must be instantiated using the same
* key. There is 'no limit' on the number of RW locks that can
* exist on the system at any one time.
* key. There is 'no limit' on the number of RW locks that can
* exist on the system at any one time.
*
* Summary of operation:
* - readers can work concurrently
@@ -130,119 +137,141 @@ class wouldblock : public std::exception
* up somewhere else. Crashes while holding a read or write lock will
* eventually deadlock the set of processes that share the same key obviously.
*/
class RWLock {
public:
class RWLock
{
public:
// semaphore numbers
static const int MUTEX=0;
static const int READERS=1;
static const int WRITERS=2;
// semaphore numbers
static const int MUTEX = 0;
static const int READERS = 1;
static const int WRITERS = 2;
/** @brief Keyed constructor.
*
* Instantiate an RWLock with the given key. All instances that
* share a key share the same lock.
*
* @param key The key
* @param excl If true and this is the first instance with the
* supplied key, it will return holding the write lock. If true and
* this is not the first instance, it will throw not_excl. The intent
* is similar to the IPC_EXCL flag in the sem/shm implementations.
*/
EXPORT explicit RWLock(int key, bool* excl = 0);
/** @brief Keyed constructor.
*
* Instantiate an RWLock with the given key. All instances that
* share a key share the same lock.
*
* @param key The key
* @param excl If true and this is the first instance with the
* supplied key, it will return holding the write lock. If true and
* this is not the first instance, it will throw not_excl. The intent
* is similar to the IPC_EXCL flag in the sem/shm implementations.
*/
EXPORT explicit RWLock(int key, bool* excl = 0);
EXPORT ~RWLock();
/** @brief Grab a read lock
*
* Grab a read lock. This will block iff writers are waiting or
* a writer is active. The version with priority ignores any
* waiting threads and grabs the lock.
*
* @param block (For testing only) If false, will throw
* wouldblock instead of blocking
*/
EXPORT void read_lock(bool block = true);
EXPORT ~RWLock();
EXPORT void read_lock_priority(bool block = true);
/** @brief Grab a read lock
*
* Grab a read lock. This will block iff writers are waiting or
* a writer is active. The version with priority ignores any
* waiting threads and grabs the lock.
*
* @param block (For testing only) If false, will throw
* wouldblock instead of blocking
*/
EXPORT void read_lock(bool block = true);
/** @brief Release a read lock.
*
* Release a read lock.
*/
EXPORT void read_unlock();
EXPORT void read_lock_priority(bool block = true);
/** @brief Grab a write lock
*
* Grab a write lock. This will block while another writer or reader is
* active and will have exclusive access on waking.
*
* @param block (For testing only) If false, will throw
* wouldblock instead of blocking
*/
EXPORT void write_lock(bool block = true);
/** @brief Release a read lock.
*
* Release a read lock.
*/
EXPORT void read_unlock();
/** @brief A timed write lock.
*
* Queues up for the write lock for a specified amount of time. Returns
* true if it got the lock, return false if it timed out first.
* If the timeout happens, it will also return the lock state if passed
* a non-NULL LockState struct. This is a specialization for supporting
* the RWLockMonitor class.
*/
EXPORT bool timed_write_lock(const struct timespec &ts,
struct LockState *state = 0);
/** @brief Grab a write lock
*
* Grab a write lock. This will block while another writer or reader is
* active and will have exclusive access on waking.
*
* @param block (For testing only) If false, will throw
* wouldblock instead of blocking
*/
EXPORT void write_lock(bool block = true);
/** @brief Release a write lock.
*
* Release a write lock.
*/
EXPORT void write_unlock();
/** @brief A timed write lock.
*
* Queues up for the write lock for a specified amount of time. Returns
* true if it got the lock, return false if it timed out first.
* If the timeout happens, it will also return the lock state if passed
* a non-NULL LockState struct. This is a specialization for supporting
* the RWLockMonitor class.
*/
EXPORT bool timed_write_lock(const struct timespec& ts,
struct LockState* state = 0);
/* note: these haven't been proven yet */
/** @brief Upgrade a read lock to a write lock
*
* Upgrade a read lock to a write lock. It may have to block
* if there are other readers currently reading. No guarantees of atomicity.
*/
EXPORT void upgrade_to_write();
/** @brief Downgrade a write lock to a read lock
*
* Downgrade a write lock to a read lock. The conversion happens
* atomically.
*/
EXPORT void downgrade_to_read();
/** @brief Reset the lock's state (Use with caution!)
*
* If the lock gets into a bad state in testing or something,
* this will reset the state.
* @warning This is safe only if there are no other threads using this
* lock.
*/
EXPORT void reset();
/** @brief Release a write lock.
*
* Release a write lock.
*/
EXPORT void write_unlock();
/* These are for white box testing only */
inline void lock() { down(MUTEX, true); }
inline void unlock() { up(MUTEX); }
inline int getWriting() const { return fPImpl->fState->writing; }
inline int getReading() const { return fPImpl->fState->reading; }
inline int getWritersWaiting() const { return fPImpl->fState->writerswaiting; }
inline int getReadersWaiting() const { return fPImpl->fState->readerswaiting; }
LockState getLockState();
private:
RWLock(const RWLock& rwl);
RWLock& operator=(const RWLock& rwl);
/* note: these haven't been proven yet */
inline int getSemval(int) const { return 0; }
void down(int num, bool block = true);
bool timed_down(int num, const boost::posix_time::ptime &ts); // to support timed_write_lock()
void up(int num);
/** @brief Upgrade a read lock to a write lock
*
* Upgrade a read lock to a write lock. It may have to block
* if there are other readers currently reading. No guarantees of atomicity.
*/
EXPORT void upgrade_to_write();
RWLockShmImpl* fPImpl;
/** @brief Downgrade a write lock to a read lock
*
* Downgrade a write lock to a read lock. The conversion happens
* atomically.
*/
EXPORT void downgrade_to_read();
/** @brief Reset the lock's state (Use with caution!)
*
* If the lock gets into a bad state in testing or something,
* this will reset the state.
* @warning This is safe only if there are no other threads using this
* lock.
*/
EXPORT void reset();
/* These are for white box testing only */
inline void lock()
{
down(MUTEX, true);
}
inline void unlock()
{
up(MUTEX);
}
inline int getWriting() const
{
return fPImpl->fState->writing;
}
inline int getReading() const
{
return fPImpl->fState->reading;
}
inline int getWritersWaiting() const
{
return fPImpl->fState->writerswaiting;
}
inline int getReadersWaiting() const
{
return fPImpl->fState->readerswaiting;
}
LockState getLockState();
private:
RWLock(const RWLock& rwl);
RWLock& operator=(const RWLock& rwl);
inline int getSemval(int) const
{
return 0;
}
void down(int num, bool block = true);
bool timed_down(int num, const boost::posix_time::ptime& ts); // to support timed_write_lock()
void up(int num);
RWLockShmImpl* fPImpl;
};
} //namespace rwlock