mirror of
https://github.com/caozhiyi/CppNet.git
synced 2026-01-26 16:30:05 +08:00
Add annotations
This commit is contained in:
@@ -47,6 +47,7 @@ public:
|
||||
friend std::ostream& operator<<(std::ostream &out, const CBuffer &obj);
|
||||
|
||||
private:
|
||||
//modify cloopbuffer index for compare
|
||||
void _IncrefIndex(CLoopBuffer* start);
|
||||
void _DecrefIndex(CLoopBuffer* start);
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ public:
|
||||
void SetLogLevel(LogLevel level);
|
||||
LogLevel GetLogLevel();
|
||||
|
||||
//api for different level log
|
||||
void LogDebug(const char* file, int line, const char* log...);
|
||||
void LogInfo(const char* file, int line, const char* log...);
|
||||
void LogWarn(const char* file, int line, const char* log...);
|
||||
@@ -37,11 +38,13 @@ public:
|
||||
void LogFatal(const char* file, int line, const char* log...);
|
||||
|
||||
private:
|
||||
//format log and push to task queue
|
||||
void _PushFormatLog(const char* file, int line, const char* level, const char* log, va_list list);
|
||||
//check date and create new log file
|
||||
void _CheckDateFile();
|
||||
|
||||
private:
|
||||
CTimeTool _time;
|
||||
CTimeTool _time; //for now tile
|
||||
std::string _file_name;
|
||||
std::fstream _log_file;
|
||||
int _log_level;
|
||||
|
||||
@@ -103,7 +103,7 @@ void* CMemoryPool::ChunkAlloc(int size, int& nums, bool is_large) {
|
||||
int need_bytes = size * nums;
|
||||
int left_bytes = _pool_end - _pool_start;
|
||||
|
||||
//<EFBFBD>ڴ<EFBFBD><EFBFBD>ع<EFBFBD><EFBFBD><EFBFBD>
|
||||
//pool is enough
|
||||
if (left_bytes >= need_bytes) {
|
||||
res = _pool_start;
|
||||
_pool_start += need_bytes;
|
||||
@@ -133,7 +133,7 @@ void* CMemoryPool::ChunkAlloc(int size, int& nums, bool is_large) {
|
||||
}
|
||||
|
||||
_pool_start = (char*)malloc(bytes_to_get);
|
||||
//<EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><EFBFBD>
|
||||
//malloc failed
|
||||
if (0 == _pool_start) {
|
||||
throw std::exception(std::logic_error("There memary is not enough!"));
|
||||
cout << "There memary is not enough!" << endl;
|
||||
|
||||
@@ -54,6 +54,7 @@ inline void DoEnable(T1 *ptr, CEnableSharedFromThis<T2> *es, CRefCount *ref_ptr,
|
||||
es->_weak_ptr.Resetw(ptr, ref_ptr, pool, size, type);
|
||||
}
|
||||
|
||||
//not useful on gcc.
|
||||
//template<typename T>
|
||||
//struct has_member_weak_ptr {
|
||||
// template <typename _T>
|
||||
@@ -378,12 +379,12 @@ public:
|
||||
virtual ~CBasePtr() {}
|
||||
|
||||
protected:
|
||||
T *_ptr;
|
||||
T *_ptr; //real data ptr
|
||||
CRefCount *_ref_count;
|
||||
CMemoryPool *_pool;
|
||||
CMemoryPool *_pool; //base memory pool
|
||||
|
||||
int _malloc_size;
|
||||
MemoryType _memory_type;
|
||||
int _malloc_size; //if malloc large memory from pool. that use to free
|
||||
MemoryType _memory_type; //malloc memory type from pool
|
||||
|
||||
std::mutex _mutex;
|
||||
};
|
||||
@@ -493,6 +494,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//new object on pool
|
||||
template<typename T, typename... Args >
|
||||
CMemSharePtr<T> MakeNewSharedPtr(CMemoryPool* pool, Args&&... args) {
|
||||
T* o = pool->PoolNew<T>(std::forward<Args>(args)...);
|
||||
@@ -500,6 +502,7 @@ CMemSharePtr<T> MakeNewSharedPtr(CMemoryPool* pool, Args&&... args) {
|
||||
return CMemSharePtr<T>(o, ref, pool, TYPE_NEW);
|
||||
}
|
||||
|
||||
//malloc from pool
|
||||
template<typename T>
|
||||
CMemSharePtr<T> MakeMallocSharedPtr(CMemoryPool* pool, int size) {
|
||||
T* o = (T*)pool->PoolMalloc<T>(size);
|
||||
@@ -507,6 +510,7 @@ CMemSharePtr<T> MakeMallocSharedPtr(CMemoryPool* pool, int size) {
|
||||
return CMemSharePtr<T>(o, ref, pool, TYPE_MALLOC, size);
|
||||
}
|
||||
|
||||
//malloc large memory from pool
|
||||
template<typename T>
|
||||
CMemSharePtr<T> MakeLargeSharedPtr(CMemoryPool* pool) {
|
||||
T* o = pool->PoolLargeMalloc<T>();
|
||||
|
||||
@@ -9,7 +9,7 @@ public:
|
||||
CRunnable() : _stop(false) {}
|
||||
virtual ~CRunnable() {}
|
||||
|
||||
//<EFBFBD>̻߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//base option
|
||||
virtual void Start() {
|
||||
_stop = false;
|
||||
if (!_pthread) {
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
//<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//TO DO
|
||||
virtual void Run() = 0;
|
||||
|
||||
bool GetStop() {
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
return _task_list.Size();
|
||||
}
|
||||
|
||||
//<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>ϢͶ<EFBFBD><EFBFBD>
|
||||
//post task
|
||||
void Push(const T&& t) {
|
||||
_task_list.Push(t);
|
||||
}
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
_task_list.Push(t);
|
||||
}
|
||||
|
||||
//<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//TO DO
|
||||
virtual void Run() = 0;
|
||||
|
||||
protected:
|
||||
@@ -37,6 +37,6 @@ protected:
|
||||
CRunnableAloneTaskList& operator=(const CRunnableAloneTaskList&) = delete;
|
||||
|
||||
private:
|
||||
CTaskQueue<T> _task_list; //ÿ<EFBFBD><EFBFBD><EFBFBD>̶߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CTaskQueue<T> _task_list; //every thread have a task queue
|
||||
};
|
||||
#endif
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
virtual void Start();
|
||||
virtual void Stop();
|
||||
|
||||
//<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>ϢͶ<EFBFBD><EFBFBD>
|
||||
//post task
|
||||
void Push(const Task&& func) {
|
||||
_task_list.Push(func);
|
||||
}
|
||||
@@ -30,12 +30,12 @@ public:
|
||||
_task_list.Push(func);
|
||||
}
|
||||
|
||||
//<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//TO DO
|
||||
virtual void Run();
|
||||
|
||||
std::thread::id GetId()const { return _id; }
|
||||
|
||||
//<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//post task to the thread
|
||||
static bool PostTask(const std::thread::id& thread_id, const Task& func);
|
||||
|
||||
private:
|
||||
@@ -47,11 +47,11 @@ private:
|
||||
CRunnableAloneTaskListWithPost& operator=(const CRunnableAloneTaskListWithPost&) = delete;
|
||||
|
||||
private:
|
||||
CTaskQueue<Task> _task_list; //ÿ<><C3BF><EFBFBD>̶߳<DFB3><CCB6><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
CTaskQueue<Task> _task_list;
|
||||
std::thread::id _id;
|
||||
|
||||
static std::mutex _map_mutex; //_runnable_map<61><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
static std::map<std::thread::id, CRunnableAloneTaskListWithPost*> _runnable_map; //<2F><>¼<EFBFBD>̶߳<DFB3><CCB6><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><D6A7><EFBFBD>̼߳<DFB3><CCBC><EFBFBD>ϢͶ<CFA2><CDB6>
|
||||
static std::mutex _map_mutex;
|
||||
static std::map<std::thread::id, CRunnableAloneTaskListWithPost*> _runnable_map;
|
||||
};
|
||||
|
||||
std::mutex CRunnableAloneTaskListWithPost::_map_mutex;
|
||||
|
||||
@@ -20,7 +20,7 @@ public:
|
||||
return _task_list_map[_channel].first->Size();
|
||||
}
|
||||
|
||||
//<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD>ϢͶ<EFBFBD><EFBFBD>
|
||||
//post task
|
||||
void Push(const T&& func) {
|
||||
std::unique_lock<std::mutex> lock(_map_mutex);
|
||||
_task_list_map[_channel].first->Push(func);
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
_task_list_map[_channel].first->Push(func);
|
||||
}
|
||||
|
||||
//<EFBFBD>߳<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//TO DO
|
||||
virtual void Run() = 0;
|
||||
|
||||
private:
|
||||
@@ -47,8 +47,8 @@ private:
|
||||
bool _stop;
|
||||
std::shared_ptr<std::thread> _pthread;
|
||||
|
||||
static std::mutex _map_mutex; //_runnable_map<61><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
static std::map<int, std::pair<std::shared_ptr<CTaskQueue<T>>, int>> _task_list_map; //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> channel TaskQueue TaskQueue<EFBFBD>Ĺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
static std::mutex _map_mutex;
|
||||
static std::map<int, std::pair<std::shared_ptr<CTaskQueue<T>>, int>> _task_list_map; //shared task queue. channel. TaskQueue. TaskQueue num.
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
||||
Reference in New Issue
Block a user