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/xvalue.h>
#include <a8/xobject.h> #include <a8/xobject.h>
#include <a8/timer_attacher.h> #include <a8/timer_attacher.h>
#include <a8/singleton.h>
#include <a8/strutils.h> #include <a8/strutils.h>
#include <a8/sysutils.h> #include <a8/sysutils.h>

View File

@ -3,12 +3,9 @@
namespace a8 namespace a8
{ {
class PerfMonitor : public a8::Singleton<PerfMonitor> class PerfMonitor
{ {
private: A8_DECLARE_SINGLETON(PerfMonitor);
PerfMonitor();
friend class a8::Singleton<PerfMonitor>;
public: public:
void Init(); void Init();
void UnInit(); 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 namespace f8
{ {
class BtMgr : public a8::Singleton<BtMgr> class BtMgr
{ {
private: A8_DECLARE_SINGLETON(BtMgr);
BtMgr() {};
friend class a8::Singleton<BtMgr>;
public: public:
void Init(const std::string& file_path); void Init(const std::string& file_path);
void UnInit(); 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<DbQueryResult>)> DbQueryResultCb;
typedef std::function<void(std::shared_ptr<DbExecResult>)> DbExecResultCb; typedef std::function<void(std::shared_ptr<DbExecResult>)> DbExecResultCb;
class DBPool : public a8::Singleton<DBPool> class DBPool
{ {
private: A8_DECLARE_SINGLETON(DBPool);
DBPool() {};
friend class a8::Singleton<DBPool>;
public: public:
void Init(); void Init();
void UnInit(); void UnInit();

View File

@ -428,6 +428,11 @@ namespace f8
size_t mutex_buf_size = 0; size_t mutex_buf_size = 0;
}; };
HttpClientPool::HttpClientPool()
{
}
void HttpClientPool::Init(int thread_num, int sys_num, int user_num) void HttpClientPool::Init(int thread_num, int sys_num, int user_num)
{ {
if (thread_num < 0 || sys_num < 0 || user_num < 0) { 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; typedef std::function<void(bool, a8::XObject*, f8::HttpContext*)> HttpProxyCb;
class HttpClientPoolImpl; class HttpClientPoolImpl;
class HttpClientPool : public a8::Singleton<HttpClientPool> class HttpClientPool
{ {
private: A8_DECLARE_SINGLETON(HttpClientPool);
HttpClientPool() {};
friend class a8::Singleton<HttpClientPool>;
public: public:
volatile long long max_sys_request_delay = 0; volatile long long max_sys_request_delay = 0;
volatile long long max_user_request_delay = 0; volatile long long max_user_request_delay = 0;

View File

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

View File

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

View File

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

View File

@ -7,12 +7,10 @@ namespace a8
namespace f8 namespace f8
{ {
class ScriptEngine : public a8::Singleton<ScriptEngine>
{
private:
ScriptEngine() {};
friend class a8::Singleton<ScriptEngine>;
class ScriptEngine
{
A8_DECLARE_SINGLETON(ScriptEngine);
public: public:
void Init(); void Init();
void UnInit(); 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) void TGLog::Init(const std::string& project_name, bool is_poly_log, int time_zone)
{ {
time_zone_ = time_zone; time_zone_ = time_zone;

View File

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

View File

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

View File

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

View File

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