refactor(Core/Common): restyle common lib with astyle (#3461)

This commit is contained in:
Kargatum
2020-09-12 03:50:48 +07:00
committed by GitHub
parent e15a493927
commit 3a0b0356ac
101 changed files with 4524 additions and 4418 deletions

View File

@@ -23,277 +23,277 @@ typedef ACE_Future<PreparedQueryResult> PreparedQueryResultFuture;
template <typename Result, typename ParamType, bool chain = false>
class QueryCallback
{
public:
QueryCallback() : _param(), _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {}
public:
QueryCallback() : _param(), _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {}
//! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery
void SetFutureResult(ACE_Future<Result> value)
{
_result = value;
}
//! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery
void SetFutureResult(ACE_Future<Result> value)
{
_result = value;
}
ACE_Future<Result> GetFutureResult()
{
return _result;
}
ACE_Future<Result> GetFutureResult()
{
return _result;
}
int IsReady()
{
return _result.ready();
}
int IsReady()
{
return _result.ready();
}
void GetResult(Result& res)
{
_result.get(res);
}
void GetResult(Result& res)
{
_result.get(res);
}
void FreeResult()
{
_result.cancel();
}
void FreeResult()
{
_result.cancel();
}
void SetParam(ParamType value)
{
_param = value;
}
void SetParam(ParamType value)
{
_param = value;
}
ParamType GetParam()
{
return _param;
}
ParamType GetParam()
{
return _param;
}
//! Resets the stage of the callback chain
void ResetStage()
{
if (!chain)
return;
//! Resets the stage of the callback chain
void ResetStage()
{
if (!chain)
return;
_stage = 0;
}
_stage = 0;
}
//! Advances the callback chain to the next stage, so upper level code can act on its results accordingly
void NextStage()
{
if (!chain)
return;
//! Advances the callback chain to the next stage, so upper level code can act on its results accordingly
void NextStage()
{
if (!chain)
return;
++_stage;
}
++_stage;
}
//! Returns the callback stage (or CALLBACK_STAGE_INVALID if invalid)
uint8 GetStage()
{
return _stage;
}
//! Returns the callback stage (or CALLBACK_STAGE_INVALID if invalid)
uint8 GetStage()
{
return _stage;
}
//! Resets all underlying variables (param, result and stage)
void Reset()
{
SetParam(NULL);
FreeResult();
ResetStage();
}
//! Resets all underlying variables (param, result and stage)
void Reset()
{
SetParam(NULL);
FreeResult();
ResetStage();
}
private:
ACE_Future<Result> _result;
ParamType _param;
uint8 _stage;
private:
ACE_Future<Result> _result;
ParamType _param;
uint8 _stage;
};
template <typename Result, typename ParamType1, typename ParamType2, bool chain = false>
class QueryCallback_2
{
public:
QueryCallback_2() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {}
public:
QueryCallback_2() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {}
//! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery
void SetFutureResult(ACE_Future<Result> value)
{
_result = value;
}
//! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery
void SetFutureResult(ACE_Future<Result> value)
{
_result = value;
}
ACE_Future<Result> GetFutureResult()
{
return _result;
}
ACE_Future<Result> GetFutureResult()
{
return _result;
}
int IsReady()
{
return _result.ready();
}
int IsReady()
{
return _result.ready();
}
void GetResult(Result& res)
{
_result.get(res);
}
void GetResult(Result& res)
{
_result.get(res);
}
void FreeResult()
{
_result.cancel();
}
void FreeResult()
{
_result.cancel();
}
void SetFirstParam(ParamType1 value)
{
_param_1 = value;
}
void SetFirstParam(ParamType1 value)
{
_param_1 = value;
}
void SetSecondParam(ParamType2 value)
{
_param_2 = value;
}
void SetSecondParam(ParamType2 value)
{
_param_2 = value;
}
ParamType1 GetFirstParam()
{
return _param_1;
}
ParamType1 GetFirstParam()
{
return _param_1;
}
ParamType2 GetSecondParam()
{
return _param_2;
}
ParamType2 GetSecondParam()
{
return _param_2;
}
//! Resets the stage of the callback chain
void ResetStage()
{
if (!chain)
return;
//! Resets the stage of the callback chain
void ResetStage()
{
if (!chain)
return;
_stage = 0;
}
_stage = 0;
}
//! Advances the callback chain to the next stage, so upper level code can act on its results accordingly
void NextStage()
{
if (!chain)
return;
//! Advances the callback chain to the next stage, so upper level code can act on its results accordingly
void NextStage()
{
if (!chain)
return;
++_stage;
}
++_stage;
}
//! Returns the callback stage (or CALLBACK_STAGE_INVALID if invalid)
uint8 GetStage()
{
return _stage;
}
//! Returns the callback stage (or CALLBACK_STAGE_INVALID if invalid)
uint8 GetStage()
{
return _stage;
}
//! Resets all underlying variables (param, result and stage)
void Reset()
{
SetFirstParam(0);
SetSecondParam(NULL);
FreeResult();
ResetStage();
}
//! Resets all underlying variables (param, result and stage)
void Reset()
{
SetFirstParam(0);
SetSecondParam(NULL);
FreeResult();
ResetStage();
}
private:
ACE_Future<Result> _result;
ParamType1 _param_1;
ParamType2 _param_2;
uint8 _stage;
private:
ACE_Future<Result> _result;
ParamType1 _param_1;
ParamType2 _param_2;
uint8 _stage;
};
template <typename Result, typename ParamType1, typename ParamType2, typename ParamType3, bool chain = false>
class QueryCallback_3
{
public:
QueryCallback_3() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {}
public:
QueryCallback_3() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {}
//! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery
void SetFutureResult(ACE_Future<Result> value)
{
_result = value;
}
//! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery
void SetFutureResult(ACE_Future<Result> value)
{
_result = value;
}
ACE_Future<Result> GetFutureResult()
{
return _result;
}
ACE_Future<Result> GetFutureResult()
{
return _result;
}
int IsReady()
{
return _result.ready();
}
int IsReady()
{
return _result.ready();
}
void GetResult(Result& res)
{
_result.get(res);
}
void GetResult(Result& res)
{
_result.get(res);
}
void FreeResult()
{
_result.cancel();
}
void FreeResult()
{
_result.cancel();
}
void SetFirstParam(ParamType1 value)
{
_param_1 = value;
}
void SetFirstParam(ParamType1 value)
{
_param_1 = value;
}
void SetSecondParam(ParamType2 value)
{
_param_2 = value;
}
void SetSecondParam(ParamType2 value)
{
_param_2 = value;
}
void SetThirdParam(ParamType3 value)
{
_param_3 = value;
}
void SetThirdParam(ParamType3 value)
{
_param_3 = value;
}
ParamType1 GetFirstParam()
{
return _param_1;
}
ParamType1 GetFirstParam()
{
return _param_1;
}
ParamType2 GetSecondParam()
{
return _param_2;
}
ParamType2 GetSecondParam()
{
return _param_2;
}
ParamType3 GetThirdParam()
{
return _param_3;
}
ParamType3 GetThirdParam()
{
return _param_3;
}
//! Resets the stage of the callback chain
void ResetStage()
{
if (!chain)
return;
//! Resets the stage of the callback chain
void ResetStage()
{
if (!chain)
return;
_stage = 0;
}
_stage = 0;
}
//! Advances the callback chain to the next stage, so upper level code can act on its results accordingly
void NextStage()
{
if (!chain)
return;
//! Advances the callback chain to the next stage, so upper level code can act on its results accordingly
void NextStage()
{
if (!chain)
return;
++_stage;
}
++_stage;
}
//! Returns the callback stage (or CALLBACK_STAGE_INVALID if invalid)
uint8 GetStage()
{
return _stage;
}
//! Returns the callback stage (or CALLBACK_STAGE_INVALID if invalid)
uint8 GetStage()
{
return _stage;
}
//! Resets all underlying variables (param, result and stage)
void Reset()
{
SetFirstParam(NULL);
SetSecondParam(NULL);
SetThirdParam(NULL);
FreeResult();
ResetStage();
}
//! Resets all underlying variables (param, result and stage)
void Reset()
{
SetFirstParam(NULL);
SetSecondParam(NULL);
SetThirdParam(NULL);
FreeResult();
ResetStage();
}
private:
ACE_Future<Result> _result;
ParamType1 _param_1;
ParamType2 _param_2;
ParamType3 _param_3;
uint8 _stage;
private:
ACE_Future<Result> _result;
ParamType1 _param_1;
ParamType2 _param_2;
ParamType3 _param_3;
uint8 _stage;
};
#endif

View File

@@ -10,7 +10,7 @@ DelayExecutor* DelayExecutor::instance()
}
DelayExecutor::DelayExecutor()
: pre_svc_hook_(0), post_svc_hook_(0), activated_(false), mqueue_(1*1024*1024, 1*1024*1024), queue_(&mqueue_)
: pre_svc_hook_(0), post_svc_hook_(0), activated_(false), mqueue_(1 * 1024 * 1024, 1 * 1024 * 1024), queue_(&mqueue_)
{
}

View File

@@ -7,33 +7,33 @@
class DelayExecutor : protected ACE_Task_Base
{
public:
public:
DelayExecutor();
virtual ~DelayExecutor();
DelayExecutor();
virtual ~DelayExecutor();
static DelayExecutor* instance();
static DelayExecutor* instance();
int execute(ACE_Method_Request* new_req);
int execute(ACE_Method_Request* new_req);
int start(int num_threads = 1, ACE_Method_Request* pre_svc_hook = NULL, ACE_Method_Request* post_svc_hook = NULL);
int start(int num_threads = 1, ACE_Method_Request* pre_svc_hook = NULL, ACE_Method_Request* post_svc_hook = NULL);
int deactivate();
int deactivate();
bool activated();
bool activated();
virtual int svc();
virtual int svc();
private:
private:
ACE_Method_Request* pre_svc_hook_;
ACE_Method_Request* post_svc_hook_;
bool activated_;
ACE_Message_Queue<ACE_SYNCH> mqueue_;
ACE_Activation_Queue queue_;
ACE_Method_Request* pre_svc_hook_;
ACE_Method_Request* post_svc_hook_;
bool activated_;
ACE_Message_Queue<ACE_SYNCH> mqueue_;
ACE_Activation_Queue queue_;
void activated(bool s);
void activated(bool s);
};
#endif // _M_DELAY_EXECUTOR_H

View File

@@ -15,8 +15,8 @@
namespace ACE_Based
{
template <class T, class LockType, typename StorageType=std::deque<T> >
class LockedQueue
template <class T, class LockType, typename StorageType = std::deque<T> >
class LockedQueue
{
//! Lock access to the queue.
LockType _lock;
@@ -27,120 +27,120 @@ namespace ACE_Based
//! Cancellation flag.
volatile bool _canceled;
public:
public:
//! Create a LockedQueue.
LockedQueue()
: _canceled(false)
{
}
//! Create a LockedQueue.
LockedQueue()
: _canceled(false)
{
}
//! Destroy a LockedQueue.
virtual ~LockedQueue()
{
}
//! Destroy a LockedQueue.
virtual ~LockedQueue()
{
}
//! Adds an item to the queue.
void add(const T& item)
{
lock();
//! Adds an item to the queue.
void add(const T& item)
{
lock();
//ASSERT(!this->_canceled);
// throw Cancellation_Exception();
//ASSERT(!this->_canceled);
// throw Cancellation_Exception();
_queue.push_back(item);
_queue.push_back(item);
unlock();
}
//! Gets the next result in the queue, if any.
bool next(T& result)
{
// ACE_Guard<LockType> g(this->_lock);
ACE_GUARD_RETURN (LockType, g, this->_lock, false);
if (_queue.empty())
return false;
//ASSERT (!_queue.empty() || !this->_canceled);
// throw Cancellation_Exception();
result = _queue.front();
_queue.pop_front();
return true;
}
template<class Checker>
bool next(T& result, Checker& check)
{
ACE_Guard<LockType> g(this->_lock);
if (_queue.empty())
return false;
result = _queue.front();
if (!check.Process(result))
return false;
_queue.pop_front();
return true;
}
//! Peeks at the top of the queue. Check if the queue is empty before calling! Remember to unlock after use if autoUnlock == false.
T& peek(bool autoUnlock = false)
{
lock();
T& result = _queue.front();
if (autoUnlock)
unlock();
}
//! Gets the next result in the queue, if any.
bool next(T& result)
{
// ACE_Guard<LockType> g(this->_lock);
ACE_GUARD_RETURN (LockType, g, this->_lock, false);
return result;
}
if (_queue.empty())
return false;
//! Cancels the queue.
void cancel()
{
lock();
//ASSERT (!_queue.empty() || !this->_canceled);
// throw Cancellation_Exception();
result = _queue.front();
_queue.pop_front();
_canceled = true;
return true;
}
unlock();
}
template<class Checker>
bool next(T& result, Checker& check)
{
ACE_Guard<LockType> g(this->_lock);
//! Checks if the queue is cancelled.
bool cancelled()
{
ACE_Guard<LockType> g(this->_lock);
return _canceled;
}
if (_queue.empty())
return false;
//! Locks the queue for access.
void lock()
{
this->_lock.acquire();
}
result = _queue.front();
if (!check.Process(result))
return false;
//! Unlocks the queue.
void unlock()
{
this->_lock.release();
}
_queue.pop_front();
return true;
}
///! Calls pop_front of the queue
void pop_front()
{
ACE_GUARD (LockType, g, this->_lock);
_queue.pop_front();
}
//! Peeks at the top of the queue. Check if the queue is empty before calling! Remember to unlock after use if autoUnlock == false.
T& peek(bool autoUnlock = false)
{
lock();
T& result = _queue.front();
if (autoUnlock)
unlock();
return result;
}
//! Cancels the queue.
void cancel()
{
lock();
_canceled = true;
unlock();
}
//! Checks if the queue is cancelled.
bool cancelled()
{
ACE_Guard<LockType> g(this->_lock);
return _canceled;
}
//! Locks the queue for access.
void lock()
{
this->_lock.acquire();
}
//! Unlocks the queue.
void unlock()
{
this->_lock.release();
}
///! Calls pop_front of the queue
void pop_front()
{
ACE_GUARD (LockType, g, this->_lock);
_queue.pop_front();
}
///! Checks if we're empty or not with locks held
bool empty()
{
ACE_GUARD_RETURN (LockType, g, this->_lock, false);
return _queue.empty();
}
///! Checks if we're empty or not with locks held
bool empty()
{
ACE_GUARD_RETURN (LockType, g, this->_lock, false);
return _queue.empty();
}
};
}
#endif

View File

@@ -95,7 +95,7 @@ private:
typename std::enable_if<std::is_pointer<E>::value>::type DeleteQueuedObject(E& obj) { delete obj; }
template<typename E = T>
typename std::enable_if<!std::is_pointer<E>::value>::type DeleteQueuedObject(E const& /*packet*/) { }
typename std::enable_if < !std::is_pointer<E>::value >::type DeleteQueuedObject(E const& /*packet*/) { }
};
#endif

View File

@@ -88,13 +88,27 @@ void Thread::setPriority(Priority priority)
switch (priority)
{
#ifdef WIN32
case Priority_Realtime: _ok = SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL); break;
case Priority_Highest: _ok = SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST); break;
case Priority_High: _ok = SetThreadPriority(handle, THREAD_PRIORITY_ABOVE_NORMAL); break;
case Priority_Normal: _ok = SetThreadPriority(handle, THREAD_PRIORITY_NORMAL); break;
case Priority_Low: _ok = SetThreadPriority(handle, THREAD_PRIORITY_BELOW_NORMAL); break;
case Priority_Lowest: _ok = SetThreadPriority(handle, THREAD_PRIORITY_LOWEST); break;
case Priority_Idle: _ok = SetThreadPriority(handle, THREAD_PRIORITY_IDLE); break;
case Priority_Realtime:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
break;
case Priority_Highest:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST);
break;
case Priority_High:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_ABOVE_NORMAL);
break;
case Priority_Normal:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_NORMAL);
break;
case Priority_Low:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_BELOW_NORMAL);
break;
case Priority_Lowest:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_LOWEST);
break;
case Priority_Idle:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_IDLE);
break;
#endif
default:
break;

View File

@@ -17,18 +17,18 @@ namespace acore
{
class Runnable
{
public:
virtual ~Runnable() {}
virtual void run() = 0;
public:
virtual ~Runnable() {}
virtual void run() = 0;
void incReference() { ++m_refs; }
void decReference()
{
if (!--m_refs)
delete this;
}
private:
std::atomic_long m_refs;
void incReference() { ++m_refs; }
void decReference()
{
if (!--m_refs)
delete this;
}
private:
std::atomic_long m_refs;
};
enum Priority
@@ -44,28 +44,28 @@ namespace acore
class Thread
{
public:
Thread();
explicit Thread(Runnable* instance);
~Thread();
public:
Thread();
explicit Thread(Runnable* instance);
~Thread();
bool wait();
void destroy();
bool wait();
void destroy();
void setPriority(Priority type);
void setPriority(Priority type);
static void Sleep(unsigned long msecs);
static std::thread::id currentId();
static void Sleep(unsigned long msecs);
static std::thread::id currentId();
private:
Thread(const Thread&);
Thread& operator=(const Thread&);
private:
Thread(const Thread&);
Thread& operator=(const Thread&);
static void ThreadTask(void* param);
static void ThreadTask(void* param);
Runnable* const m_task;
std::thread::id m_iThreadId;
std::thread m_ThreadImp;
Runnable* const m_task;
std::thread::id m_iThreadId;
std::thread m_ThreadImp;
};
}
#endif

View File

@@ -19,120 +19,120 @@ namespace acore
template<typename MUTEX>
class GeneralLock
{
public:
public:
GeneralLock(MUTEX& m)
: i_mutex(m)
{
i_mutex.lock();
}
GeneralLock(MUTEX& m)
: i_mutex(m)
{
i_mutex.lock();
}
~GeneralLock()
{
i_mutex.unlock();
}
~GeneralLock()
{
i_mutex.unlock();
}
private:
private:
GeneralLock(const GeneralLock&);
GeneralLock& operator=(const GeneralLock&);
MUTEX& i_mutex;
GeneralLock(const GeneralLock&);
GeneralLock& operator=(const GeneralLock&);
MUTEX& i_mutex;
};
template<class T>
class SingleThreaded
{
public:
public:
struct Lock // empty object
struct Lock // empty object
{
Lock()
{
Lock()
{
}
Lock(const T&)
{
}
}
Lock(const T&)
{
}
Lock(const SingleThreaded<T>&) // for single threaded we ignore this
{
}
};
Lock(const SingleThreaded<T>&) // for single threaded we ignore this
{
}
};
};
template<class T, class MUTEX>
class ObjectLevelLockable
{
public:
ObjectLevelLockable()
: i_mtx()
{
}
friend class Lock;
class Lock
{
public:
ObjectLevelLockable()
: i_mtx()
Lock(ObjectLevelLockable<T, MUTEX>& host)
: i_lock(host.i_mtx)
{
}
friend class Lock;
class Lock
{
public:
Lock(ObjectLevelLockable<T, MUTEX>& host)
: i_lock(host.i_mtx)
{
}
private:
GeneralLock<MUTEX> i_lock;
};
private:
// prevent the compiler creating a copy construct
ObjectLevelLockable(const ObjectLevelLockable<T, MUTEX>&);
ObjectLevelLockable<T, MUTEX>& operator=(const ObjectLevelLockable<T, MUTEX>&);
GeneralLock<MUTEX> i_lock;
};
MUTEX i_mtx;
private:
// prevent the compiler creating a copy construct
ObjectLevelLockable(const ObjectLevelLockable<T, MUTEX>&);
ObjectLevelLockable<T, MUTEX>& operator=(const ObjectLevelLockable<T, MUTEX>&);
MUTEX i_mtx;
};
template<class T, class MUTEX>
class ClassLevelLockable
{
public:
ClassLevelLockable()
{
}
friend class Lock;
class Lock
{
public:
ClassLevelLockable()
Lock(const T& /*host*/)
{
ClassLevelLockable<T, MUTEX>::si_mtx.lock();
}
friend class Lock;
class Lock
Lock(const ClassLevelLockable<T, MUTEX>&)
{
public:
ClassLevelLockable<T, MUTEX>::si_mtx.lock();
}
Lock(const T& /*host*/)
{
ClassLevelLockable<T, MUTEX>::si_mtx.lock();
}
Lock()
{
ClassLevelLockable<T, MUTEX>::si_mtx.lock();
}
Lock(const ClassLevelLockable<T, MUTEX>&)
{
ClassLevelLockable<T, MUTEX>::si_mtx.lock();
}
~Lock()
{
ClassLevelLockable<T, MUTEX>::si_mtx.unlock();
}
};
Lock()
{
ClassLevelLockable<T, MUTEX>::si_mtx.lock();
}
private:
~Lock()
{
ClassLevelLockable<T, MUTEX>::si_mtx.unlock();
}
};
private:
static MUTEX si_mtx;
static MUTEX si_mtx;
};
}