1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +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_local interface
*/
@ -30,20 +30,21 @@
#include <boost/thread.hpp>
#include <boost/thread/condition.hpp>
#if defined(_MSC_VER) && defined(xxxRWLOCK_LOCAL_DLLEXPORT)
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#if defined(_MSC_VER) && defined(xxxRWLOCK_LOCAL_DLLEXPORT)
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
namespace rwlock {
namespace rwlock
{
/** @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
@ -57,130 +58,139 @@ namespace rwlock {
*/
class RWLock_local {
public:
class not_excl : public std::exception
{
public:
virtual const char* what() const throw() {
return "not_excl";
}
};
class wouldblock : public std::exception
{
public:
virtual const char* what() const throw() {
return "wouldblock";
}
};
/** @brief Keyed constructor.
*
* Instantiate an RWLock_local 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 RWLock_local();
class RWLock_local
{
public:
EXPORT ~RWLock_local();
/** @brief Grab a read lock
*
* Grab a read lock. This will block iff writers are waiting or
* a writer is active.
*
* @param block (For testing only) If false, will throw
* wouldblock instead of blocking
*/
EXPORT void read_lock();
/** @brief Release a read lock.
*
* Release a read lock.
*/
EXPORT void read_unlock();
/** @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();
/** @brief Release a write lock.
*
* Release a write lock.
*/
EXPORT void write_unlock();
/** @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();
class not_excl : public std::exception
{
public:
virtual const char* what() const throw()
{
return "not_excl";
}
};
/* These are for white box testing only */
EXPORT void lock();
EXPORT void unlock();
EXPORT int getWriting();
EXPORT int getReading();
EXPORT int getWritersWaiting();
EXPORT int getReadersWaiting();
private:
// Not copyable
RWLock_local(const RWLock_local& rwl);
RWLock_local& operator=(const RWLock_local& rwl);
class wouldblock : public std::exception
{
public:
virtual const char* what() const throw()
{
return "wouldblock";
}
};
/** @brief Keyed constructor.
*
* Instantiate an RWLock_local 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 RWLock_local();
EXPORT ~RWLock_local();
/** @brief Grab a read lock
*
* Grab a read lock. This will block iff writers are waiting or
* a writer is active.
*
* @param block (For testing only) If false, will throw
* wouldblock instead of blocking
*/
EXPORT void read_lock();
/** @brief Release a read lock.
*
* Release a read lock.
*/
EXPORT void read_unlock();
/** @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();
/** @brief Release a write lock.
*
* Release a write lock.
*/
EXPORT void write_unlock();
/** @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();
/* These are for white box testing only */
EXPORT void lock();
EXPORT void unlock();
EXPORT int getWriting();
EXPORT int getReading();
EXPORT int getWritersWaiting();
EXPORT int getReadersWaiting();
private:
// Not copyable
RWLock_local(const RWLock_local& rwl);
RWLock_local& operator=(const RWLock_local& rwl);
/// the layout of the shmseg
struct State
{
int writerswaiting, writing, readerswaiting, reading;
} state;
boost::mutex mutex;
boost::condition okToRead;
boost::condition okToWrite;
/// the layout of the shmseg
struct State {
int writerswaiting, writing, readerswaiting, reading;
} state;
boost::mutex mutex;
boost::condition okToRead;
boost::condition okToWrite;
};
enum rwlock_mode {
R,
W
enum rwlock_mode
{
R,
W
};
class ScopedRWLock_local {
public:
ScopedRWLock_local(RWLock_local *, rwlock_mode);
~ScopedRWLock_local();
class ScopedRWLock_local
{
public:
ScopedRWLock_local(RWLock_local*, rwlock_mode);
~ScopedRWLock_local();
void lock();
void unlock();
void lock();
void unlock();
private:
explicit ScopedRWLock_local() {}
explicit ScopedRWLock_local(const ScopedRWLock_local &) {}
ScopedRWLock_local& operator=(const ScopedRWLock_local &) { return *this; }
RWLock_local *thelock;
rwlock_mode mode;
bool locked;
private:
explicit ScopedRWLock_local() {}
explicit ScopedRWLock_local(const ScopedRWLock_local&) {}
ScopedRWLock_local& operator=(const ScopedRWLock_local&)
{
return *this;
}
RWLock_local* thelock;
rwlock_mode mode;
bool locked;
};