This commit is contained in:
aozhiwei 2024-12-21 19:32:42 +08:00
parent 34f4f1f0cd
commit 1711af9db5
16 changed files with 41 additions and 87 deletions

View File

@ -19,7 +19,6 @@
#include <a8/xvalue.h>
#include <a8/xobject.h>
#include <a8/timer_attacher.h>
#include <a8/singleton.h>
#include <a8/strutils.h>
#include <a8/sysutils.h>

View File

@ -3,12 +3,9 @@
namespace a8
{
class PerfMonitor : public a8::Singleton<PerfMonitor>
class PerfMonitor
{
private:
PerfMonitor();
friend class a8::Singleton<PerfMonitor>;
A8_DECLARE_SINGLETON(PerfMonitor);
public:
void Init();
void UnInit();

View File

@ -1,35 +0,0 @@
#pragma once
#include <memory>
namespace a8
{
template<class T>
class Singleton
{
public:
static T* Instance()
{
if (!instance_) {
// 二次检查
if (!instance_) {
instance_ = std::shared_ptr<T> (new T());
}
}
return instance_.get();
}
protected:
Singleton() {} //防止实例
Singleton(const Singleton&) {} //防止拷贝构造一个实例
Singleton& operator=(const Singleton&){} //防止赋值出另一个实例
~Singleton() {}
private:
static inline std::shared_ptr<T> instance_;
};
}

View File

@ -12,12 +12,9 @@ namespace behaviac
namespace f8
{
class BtMgr : public a8::Singleton<BtMgr>
class BtMgr
{
private:
BtMgr() {};
friend class a8::Singleton<BtMgr>;
A8_DECLARE_SINGLETON(BtMgr);
public:
void Init(const std::string& file_path);
void UnInit();

View File

@ -28,12 +28,9 @@ namespace f8
typedef std::function<void(std::shared_ptr<DbQueryResult>)> DbQueryResultCb;
typedef std::function<void(std::shared_ptr<DbExecResult>)> DbExecResultCb;
class DBPool : public a8::Singleton<DBPool>
class DBPool
{
private:
DBPool() {};
friend class a8::Singleton<DBPool>;
A8_DECLARE_SINGLETON(DBPool);
public:
void Init();
void UnInit();

View File

@ -428,6 +428,11 @@ namespace f8
size_t mutex_buf_size = 0;
};
HttpClientPool::HttpClientPool()
{
}
void HttpClientPool::Init(int thread_num, int sys_num, int user_num)
{
if (thread_num < 0 || sys_num < 0 || user_num < 0) {

View File

@ -11,12 +11,9 @@ namespace f8
typedef std::function<void(bool, a8::XObject*, f8::HttpContext*)> HttpProxyCb;
class HttpClientPoolImpl;
class HttpClientPool : public a8::Singleton<HttpClientPool>
class HttpClientPool
{
private:
HttpClientPool() {};
friend class a8::Singleton<HttpClientPool>;
A8_DECLARE_SINGLETON(HttpClientPool);
public:
volatile long long max_sys_request_delay = 0;
volatile long long max_user_request_delay = 0;

View File

@ -3,12 +3,9 @@
namespace f8
{
class JsonLog : public a8::Singleton<JsonLog>
class JsonLog
{
private:
JsonLog();
friend class a8::Singleton<JsonLog>;
A8_DECLARE_SINGLETON(JsonLog);
public:
~JsonLog();

View File

@ -146,6 +146,11 @@ namespace f8
};
MsgQueue::MsgQueue()
{
}
void MsgQueue::Init()
{
imp_ = std::make_shared<MsgQueueImp>();

View File

@ -5,12 +5,9 @@ namespace f8
typedef std::function<void (const a8::Args&)> MsgHandleFunc;
typedef list_head* CallBackHandle;
class MsgQueue : public a8::Singleton<MsgQueue>
class MsgQueue
{
private:
MsgQueue() {};
friend class a8::Singleton<MsgQueue>;
A8_DECLARE_SINGLETON(MsgQueue);
public:
void Init();
void UnInit();

View File

@ -7,12 +7,10 @@ namespace a8
namespace f8
{
class ScriptEngine : public a8::Singleton<ScriptEngine>
{
private:
ScriptEngine() {};
friend class a8::Singleton<ScriptEngine>;
class ScriptEngine
{
A8_DECLARE_SINGLETON(ScriptEngine);
public:
void Init();
void UnInit();

View File

@ -78,6 +78,11 @@ namespace f8
}
};
TGLog::TGLog()
{
}
void TGLog::Init(const std::string& project_name, bool is_poly_log, int time_zone)
{
time_zone_ = time_zone;

View File

@ -3,12 +3,9 @@
namespace f8
{
struct TGLogImpl;
class TGLog : public a8::Singleton<TGLog>
class TGLog
{
private:
TGLog() {};
friend class a8::Singleton<TGLog>;
A8_DECLARE_SINGLETON(TGLog);
public:
void Init(const std::string& project_name, bool is_poly_log, int time_zone = 8);
void UnInit();

View File

@ -25,6 +25,11 @@ namespace f8
real_obj_.ClearTimerList();
}
Timer::Timer()
{
}
void Timer::Init()
{
impl_ = std::make_shared<TimerImpl>();

View File

@ -3,13 +3,9 @@
namespace f8
{
class Timer : public a8::Singleton<Timer>
class Timer
{
private:
Timer() {};
friend class a8::Singleton<Timer>;
A8_DECLARE_SINGLETON(Timer);
public:
void Init();
void UnInit();

View File

@ -3,12 +3,9 @@
namespace f8
{
class UdpLog : public a8::Singleton<UdpLog>
class UdpLog
{
private:
UdpLog();
friend class a8::Singleton<UdpLog>;
A8_DECLARE_SINGLETON(UdpLog);
public:
~UdpLog();