1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +03:00

clang format apply

This commit is contained in:
Leonid Fedorov
2022-01-21 16:43:49 +00:00
parent 6b6411229f
commit 04752ec546
1376 changed files with 393460 additions and 412662 deletions

View File

@ -16,8 +16,8 @@
MA 02110-1301, USA. */
/*
* $Id: threadsafequeue.h 9655 2013-06-25 23:08:13Z xlou $
*/
* $Id: threadsafequeue.h 9655 2013-06-25 23:08:13Z xlou $
*/
/** @file */
#pragma once
@ -30,19 +30,18 @@
#include <boost/shared_array.hpp>
#if defined(_MSC_VER) && !defined(_WIN64)
# ifndef InterlockedAdd
# define InterlockedAdd64 InterlockedAdd
# define InterlockedAdd(x, y) ((x) + (y))
# endif
#ifndef InterlockedAdd
#define InterlockedAdd64 InterlockedAdd
#define InterlockedAdd(x, y) ((x) + (y))
#endif
#endif
namespace joblist
{
struct TSQSize_t
{
size_t size;
uint32_t count;
size_t size;
uint32_t count;
};
/** @brief A thread-safe queue class
@ -56,24 +55,24 @@ struct TSQSize_t
template <typename T>
class ThreadSafeQueue
{
public:
typedef T value_type;
public:
typedef T value_type;
/** @brief constructor
*
* @warning this class takes ownership of the passed-in pointers.
*/
ThreadSafeQueue(boost::mutex* pimplLock = 0, boost::condition* pimplCond = 0) :
fShutdown(false), bytes(0), zeroCount(0)
{
fPimplLock.reset(pimplLock);
fPimplCond.reset(pimplCond);
}
/** @brief destructor
*
*/
~ThreadSafeQueue()
{
/** @brief constructor
*
* @warning this class takes ownership of the passed-in pointers.
*/
ThreadSafeQueue(boost::mutex* pimplLock = 0, boost::condition* pimplCond = 0)
: fShutdown(false), bytes(0), zeroCount(0)
{
fPimplLock.reset(pimplLock);
fPimplCond.reset(pimplCond);
}
/** @brief destructor
*
*/
~ThreadSafeQueue()
{
#if 0
try
@ -85,7 +84,7 @@ public:
}
#endif
}
}
#if 0
/** @brief get the head of the queue
*
@ -113,241 +112,238 @@ public:
return fImpl.front();
}
#endif
/** @brief get the head of the queue
*
* Return a read/write reference to the head of the queue, leaving it there. This method will block
* until there is something to return.
*/
T& front()
/** @brief get the head of the queue
*
* Return a read/write reference to the head of the queue, leaving it there. This method will block
* until there is something to return.
*/
T& front()
{
if (fPimplLock == 0 || fPimplCond == 0)
throw std::runtime_error("TSQ: front(): no sync!");
boost::mutex::scoped_lock lk(*fPimplLock);
if (fImpl.empty())
{
if (fPimplLock == 0 || fPimplCond == 0)
throw std::runtime_error("TSQ: front(): no sync!");
boost::mutex::scoped_lock lk(*fPimplLock);
if (fImpl.empty())
{
do
{
fPimplCond->wait(lk);
if (fShutdown) return fBs0;
}
while (fImpl.empty());
}
return fImpl.front();
}
/** @brief put an item on the end of the queue
*
* Signals all threads waiting in front() to continue.
*/
TSQSize_t push(const T& v)
{
TSQSize_t ret = {0, 0};
if (fPimplLock == 0 || fPimplCond == 0)
throw std::runtime_error("TSQ: push(): no sync!");
do
{
fPimplCond->wait(lk);
if (fShutdown)
return ret;
boost::mutex::scoped_lock lk(*fPimplLock);
fImpl.push(v);
bytes += v->lengthWithHdrOverhead();
fPimplCond->notify_one();
ret.size = bytes;
ret.count = static_cast<uint32_t>(fImpl.size());
return ret;
return fBs0;
} while (fImpl.empty());
}
/** @brief remove the front item in the queue
*
*/
TSQSize_t pop(T* out = NULL)
return fImpl.front();
}
/** @brief put an item on the end of the queue
*
* Signals all threads waiting in front() to continue.
*/
TSQSize_t push(const T& v)
{
TSQSize_t ret = {0, 0};
if (fPimplLock == 0 || fPimplCond == 0)
throw std::runtime_error("TSQ: push(): no sync!");
if (fShutdown)
return ret;
boost::mutex::scoped_lock lk(*fPimplLock);
fImpl.push(v);
bytes += v->lengthWithHdrOverhead();
fPimplCond->notify_one();
ret.size = bytes;
ret.count = static_cast<uint32_t>(fImpl.size());
return ret;
}
/** @brief remove the front item in the queue
*
*/
TSQSize_t pop(T* out = NULL)
{
TSQSize_t ret = {0, 0};
if (fPimplLock == 0)
throw std::runtime_error("TSQ: pop(): no sync!");
if (fShutdown)
{
TSQSize_t ret = {0, 0};
*out = fBs0;
return ret;
}
if (fPimplLock == 0)
throw std::runtime_error("TSQ: pop(): no sync!");
boost::mutex::scoped_lock lk(*fPimplLock);
if (fShutdown)
if (out != NULL)
{
if (fImpl.empty())
{
do
{
if (fShutdown)
{
*out = fBs0;
return ret;
}
}
boost::mutex::scoped_lock lk(*fPimplLock);
fPimplCond->wait(lk);
if (out != NULL)
{
if (fImpl.empty())
{
do
{
if (fShutdown)
{
*out = fBs0;
return ret;
}
fPimplCond->wait(lk);
if (fShutdown)
{
*out = fBs0;
return ret;
}
}
while (fImpl.empty());
}
*out = fImpl.front();
bytes -= (*out)->lengthWithHdrOverhead();
}
fImpl.pop();
ret.size = bytes;
ret.count = static_cast<uint32_t>(fImpl.size());
return ret;
}
/* If there are less than min elements in the queue, this fcn will return nothing
* for up to 10 consecutive calls (poor man's timer). On the 11th, it will return
* the entire queue. Note, the zeroCount var is non-critical. Not a big deal if
* it gets fudged now and then. */
TSQSize_t pop_some(uint32_t divisor, std::vector<T>& t, uint32_t min = 1)
{
uint32_t curSize, workSize;
TSQSize_t ret = {0, 0};
if (fPimplLock == 0)
throw std::runtime_error("TSQ: pop_some(): no sync!");
t.clear();
if (fShutdown)
if (fShutdown)
{
*out = fBs0;
return ret;
}
} while (fImpl.empty());
}
boost::mutex::scoped_lock lk(*fPimplLock);
curSize = fImpl.size();
if (curSize < min)
{
workSize = 0;
zeroCount++;
}
else if (curSize / divisor <= min)
{
workSize = min;
zeroCount = 0;
}
else
{
workSize = curSize / divisor;
zeroCount = 0;
}
if (zeroCount > 10)
{
workSize = curSize;
zeroCount = 0;
}
for (uint32_t i = 0; i < workSize; ++i)
{
t.push_back(fImpl.front());
bytes -= fImpl.front()->lengthWithHdrOverhead();
fImpl.pop();
}
ret.count = fImpl.size();
ret.size = bytes;
return ret;
*out = fImpl.front();
bytes -= (*out)->lengthWithHdrOverhead();
}
inline void pop_all(std::vector<T>& t)
fImpl.pop();
ret.size = bytes;
ret.count = static_cast<uint32_t>(fImpl.size());
return ret;
}
/* If there are less than min elements in the queue, this fcn will return nothing
* for up to 10 consecutive calls (poor man's timer). On the 11th, it will return
* the entire queue. Note, the zeroCount var is non-critical. Not a big deal if
* it gets fudged now and then. */
TSQSize_t pop_some(uint32_t divisor, std::vector<T>& t, uint32_t min = 1)
{
uint32_t curSize, workSize;
TSQSize_t ret = {0, 0};
if (fPimplLock == 0)
throw std::runtime_error("TSQ: pop_some(): no sync!");
t.clear();
if (fShutdown)
return ret;
boost::mutex::scoped_lock lk(*fPimplLock);
curSize = fImpl.size();
if (curSize < min)
{
pop_some(1, t);
workSize = 0;
zeroCount++;
}
/** @brief is the queue empty
*
*/
bool empty() const
else if (curSize / divisor <= min)
{
if (fPimplLock == 0)
throw std::runtime_error("TSQ: empty(): no sync!");
boost::mutex::scoped_lock lk(*fPimplLock);
return fImpl.empty();
workSize = min;
zeroCount = 0;
}
/** @brief how many items are in the queue
*
*/
TSQSize_t size() const
else
{
TSQSize_t ret;
if (fPimplLock == 0)
throw std::runtime_error("TSQ: size(): no sync!");
boost::mutex::scoped_lock lk(*fPimplLock);
ret.size = bytes;
ret.count = fImpl.size();
return ret;
workSize = curSize / divisor;
zeroCount = 0;
}
/** @brief shutdown the queue
*
* cause all readers blocked in front() to return a default-constructed T
*/
void shutdown()
if (zeroCount > 10)
{
fShutdown = true;
if (fPimplCond != 0)
fPimplCond->notify_all();
return;
workSize = curSize;
zeroCount = 0;
}
void clear()
for (uint32_t i = 0; i < workSize; ++i)
{
if (fPimplLock == 0)
throw std::runtime_error("TSQ: clear(): no sync!");
boost::mutex::scoped_lock lk(*fPimplLock);
while ( !fImpl.empty() )
fImpl.pop();
bytes = 0;
return;
t.push_back(fImpl.front());
bytes -= fImpl.front()->lengthWithHdrOverhead();
fImpl.pop();
}
private:
typedef std::queue<T> impl_type;
typedef boost::shared_ptr<boost::mutex> SPBM;
typedef boost::shared_ptr<boost::condition> SPBC;
ret.count = fImpl.size();
ret.size = bytes;
return ret;
}
//defaults okay
//ThreadSafeQueue<T>(const ThreadSafeQueue<T>& rhs);
//ThreadSafeQueue<T>& operator=(const ThreadSafeQueue<T>& rhs);
inline void pop_all(std::vector<T>& t)
{
pop_some(1, t);
}
impl_type fImpl;
SPBM fPimplLock;
SPBC fPimplCond;
volatile bool fShutdown;
T fBs0;
/** @brief is the queue empty
*
*/
bool empty() const
{
if (fPimplLock == 0)
throw std::runtime_error("TSQ: empty(): no sync!");
boost::mutex::scoped_lock lk(*fPimplLock);
return fImpl.empty();
}
/** @brief how many items are in the queue
*
*/
TSQSize_t size() const
{
TSQSize_t ret;
if (fPimplLock == 0)
throw std::runtime_error("TSQ: size(): no sync!");
boost::mutex::scoped_lock lk(*fPimplLock);
ret.size = bytes;
ret.count = fImpl.size();
return ret;
}
/** @brief shutdown the queue
*
* cause all readers blocked in front() to return a default-constructed T
*/
void shutdown()
{
fShutdown = true;
if (fPimplCond != 0)
fPimplCond->notify_all();
return;
}
void clear()
{
if (fPimplLock == 0)
throw std::runtime_error("TSQ: clear(): no sync!");
boost::mutex::scoped_lock lk(*fPimplLock);
while (!fImpl.empty())
fImpl.pop();
bytes = 0;
return;
}
private:
typedef std::queue<T> impl_type;
typedef boost::shared_ptr<boost::mutex> SPBM;
typedef boost::shared_ptr<boost::condition> SPBC;
// defaults okay
// ThreadSafeQueue<T>(const ThreadSafeQueue<T>& rhs);
// ThreadSafeQueue<T>& operator=(const ThreadSafeQueue<T>& rhs);
impl_type fImpl;
SPBM fPimplLock;
SPBC fPimplCond;
volatile bool fShutdown;
T fBs0;
#ifdef _MSC_VER
volatile LONG bytes;
volatile LONG bytes;
#else
size_t bytes;
size_t bytes;
#endif
uint32_t zeroCount; // counts the # of times read_some returned 0
uint32_t zeroCount; // counts the # of times read_some returned 0
};
}
} // namespace joblist