hikyuu 2.7.0__py3-none-manylinux2014_aarch64.whl → 2.7.5__py3-none-manylinux2014_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hikyuu/__init__.py +28 -8
- hikyuu/__init__.pyi +26 -14
- hikyuu/analysis/__init__.pyi +7 -1
- hikyuu/analysis/analysis.pyi +8 -2
- hikyuu/core.pyi +9 -3
- hikyuu/cpp/core310.pyi +172 -68
- hikyuu/cpp/core310.so +0 -0
- hikyuu/cpp/core311.pyi +172 -68
- hikyuu/cpp/core311.so +0 -0
- hikyuu/cpp/core312.pyi +172 -68
- hikyuu/cpp/core312.so +0 -0
- hikyuu/cpp/core313.pyi +172 -68
- hikyuu/cpp/core313.so +0 -0
- hikyuu/cpp/i18n/zh_CN/hikyuu.mo +0 -0
- hikyuu/cpp/i18n/zh_CN/hikyuu_plugin.mo +0 -0
- hikyuu/cpp/libboost_atomic.so +0 -0
- hikyuu/cpp/libboost_atomic.so.1.90.0 +0 -0
- hikyuu/cpp/{libboost_charconv-mt.so → libboost_charconv.so} +0 -0
- hikyuu/cpp/{libboost_charconv-mt.so.1.88.0 → libboost_charconv.so.1.90.0} +0 -0
- hikyuu/cpp/libboost_chrono.so +0 -0
- hikyuu/cpp/libboost_chrono.so.1.90.0 +0 -0
- hikyuu/cpp/libboost_container.so +0 -0
- hikyuu/cpp/libboost_container.so.1.90.0 +0 -0
- hikyuu/cpp/libboost_date_time.so +0 -0
- hikyuu/cpp/libboost_date_time.so.1.90.0 +0 -0
- hikyuu/cpp/libboost_locale.so +0 -0
- hikyuu/cpp/libboost_locale.so.1.90.0 +0 -0
- hikyuu/cpp/libboost_random.so +0 -0
- hikyuu/cpp/libboost_random.so.1.90.0 +0 -0
- hikyuu/cpp/libboost_serialization.so +0 -0
- hikyuu/cpp/libboost_serialization.so.1.90.0 +0 -0
- hikyuu/cpp/libboost_thread.so +0 -0
- hikyuu/cpp/libboost_thread.so.1.90.0 +0 -0
- hikyuu/cpp/libboost_wserialization.so +0 -0
- hikyuu/cpp/libboost_wserialization.so.1.90.0 +0 -0
- hikyuu/cpp/libhikyuu.so +0 -0
- hikyuu/cpp/libmimalloc.so +0 -0
- hikyuu/cpp/libmimalloc.so.3 +0 -0
- hikyuu/cpp/libmimalloc.so.3.1 +0 -0
- hikyuu/cpp/libsqlite3.so +0 -0
- hikyuu/data/clickhouse_upgrade/0001.sql +2 -0
- hikyuu/data/clickhouse_upgrade/0002.sql +9 -0
- hikyuu/data/common_clickhouse.py +1 -3
- hikyuu/data/common_mysql.py +1 -1
- hikyuu/data/download_block.py +1 -1
- hikyuu/data/em_block_to_mysql.py +16 -4
- hikyuu/data/em_block_to_sqlite.py +16 -4
- hikyuu/data/hku_config_template.py +31 -4
- hikyuu/data/mysql_upgrade/0029.sql +2 -0
- hikyuu/data/mysql_upgrade/0030.sql +3 -0
- hikyuu/data/pytdx_to_clickhouse.py +86 -32
- hikyuu/data/pytdx_to_h5.py +73 -28
- hikyuu/data/pytdx_to_mysql.py +65 -21
- hikyuu/data/pytdx_weight_to_clickhouse.py +2 -0
- hikyuu/data/pytdx_weight_to_mysql.py +2 -0
- hikyuu/data/pytdx_weight_to_sqlite.py +2 -0
- hikyuu/data/sqlite_upgrade/0029.sql +4 -0
- hikyuu/data/sqlite_upgrade/0030.sql +5 -0
- hikyuu/data/tdx_to_clickhouse.py +2 -2
- hikyuu/data/tdx_to_h5.py +11 -11
- hikyuu/data/tdx_to_mysql.py +2 -2
- hikyuu/draw/__init__.pyi +1 -1
- hikyuu/draw/drawplot/__init__.pyi +1 -1
- hikyuu/draw/drawplot/bokeh_draw.pyi +17 -9
- hikyuu/draw/drawplot/echarts_draw.pyi +17 -9
- hikyuu/draw/drawplot/matplotlib_draw.py +23 -9
- hikyuu/draw/drawplot/matplotlib_draw.pyi +17 -9
- hikyuu/examples/notebook/001-overview.ipynb +112 -78
- hikyuu/examples/notebook/004-IndicatorOverview.ipynb +52 -65
- hikyuu/examples/notebook/006-TradeManager.ipynb +402 -291
- hikyuu/examples/notebook/008-Pickle.ipynb +25 -17
- hikyuu/examples/notebook/009-RealData.ipynb +36 -38
- hikyuu/examples/notebook/Demo/Demo2.ipynb +146 -116
- hikyuu/extend.pyi +10 -4
- hikyuu/gui/HikyuuTDX.py +42 -3
- hikyuu/gui/data/MainWindow.py +189 -129
- hikyuu/gui/data/UseTdxImportToH5Thread.py +4 -2
- hikyuu/gui/start_qmt.py +1 -1
- hikyuu/hub.pyi +6 -6
- hikyuu/include/hikyuu/Block.h +9 -9
- hikyuu/include/hikyuu/HistoryFinanceInfo.h +3 -3
- hikyuu/include/hikyuu/KData.h +51 -28
- hikyuu/include/hikyuu/KDataImp.h +12 -7
- hikyuu/include/hikyuu/KDataPrivatedBufferImp.h +13 -7
- hikyuu/include/hikyuu/KDataSharedBufferImp.h +8 -6
- hikyuu/include/hikyuu/KQuery.h +11 -11
- hikyuu/include/hikyuu/KRecord.h +1 -1
- hikyuu/include/hikyuu/MarketInfo.h +10 -10
- hikyuu/include/hikyuu/Stock.h +30 -30
- hikyuu/include/hikyuu/StockManager.h +28 -12
- hikyuu/include/hikyuu/StockTypeInfo.h +9 -9
- hikyuu/include/hikyuu/StockWeight.h +9 -9
- hikyuu/include/hikyuu/StrategyContext.h +4 -4
- hikyuu/include/hikyuu/TimeLineRecord.h +1 -1
- hikyuu/include/hikyuu/TransRecord.h +1 -1
- hikyuu/include/hikyuu/data_driver/BaseInfoDriver.h +2 -1
- hikyuu/include/hikyuu/data_driver/BlockInfoDriver.h +6 -0
- hikyuu/include/hikyuu/data_driver/KDataDriver.h +6 -7
- hikyuu/include/hikyuu/data_driver/kdata/mysql/MySQLKDataDriver.h +5 -1
- hikyuu/include/hikyuu/data_driver/kdata/sqlite/SQLiteKDataDriver.h +1 -1
- hikyuu/include/hikyuu/global/sysinfo.h +24 -5
- hikyuu/include/hikyuu/indicator/IndParam.h +1 -1
- hikyuu/include/hikyuu/indicator/Indicator.h +56 -27
- hikyuu/include/hikyuu/indicator/Indicator2InImp.h +0 -4
- hikyuu/include/hikyuu/indicator/IndicatorImp.h +147 -74
- hikyuu/include/hikyuu/indicator/crt/CONTEXT.h +11 -1
- hikyuu/include/hikyuu/indicator/crt/IC.h +19 -14
- hikyuu/include/hikyuu/indicator/crt/ICIR.h +4 -7
- hikyuu/include/hikyuu/indicator/imp/IAbs.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IAcos.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IAd.h +0 -2
- hikyuu/include/hikyuu/indicator/imp/IAdvance.h +3 -0
- hikyuu/include/hikyuu/indicator/imp/IAma.h +3 -0
- hikyuu/include/hikyuu/indicator/imp/IAsin.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IAtan.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IAtr.h +2 -3
- hikyuu/include/hikyuu/indicator/imp/IBackset.h +2 -4
- hikyuu/include/hikyuu/indicator/imp/IBlockSetNum.h +3 -0
- hikyuu/include/hikyuu/indicator/imp/ICeil.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IContext.h +0 -3
- hikyuu/include/hikyuu/indicator/imp/ICorr.h +3 -0
- hikyuu/include/hikyuu/indicator/imp/ICos.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/ICost.h +0 -2
- hikyuu/include/hikyuu/indicator/imp/ICount.h +2 -1
- hikyuu/include/hikyuu/indicator/imp/ICval.h +1 -4
- hikyuu/include/hikyuu/indicator/imp/ICycle.h +0 -2
- hikyuu/include/hikyuu/indicator/imp/IDecline.h +3 -0
- hikyuu/include/hikyuu/indicator/imp/IDevsq.h +4 -1
- hikyuu/include/hikyuu/indicator/imp/IDiff.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IDma.h +2 -0
- hikyuu/include/hikyuu/indicator/imp/IDropna.h +0 -4
- hikyuu/include/hikyuu/indicator/imp/IEma.h +3 -1
- hikyuu/include/hikyuu/indicator/imp/IEvery.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IExist.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IExp.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IFilter.h +4 -5
- hikyuu/include/hikyuu/indicator/imp/IFinance.h +1 -2
- hikyuu/include/hikyuu/indicator/imp/IFloor.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IHhvbars.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IHighLine.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IHsl.h +0 -2
- hikyuu/include/hikyuu/indicator/imp/IIc.h +3 -6
- hikyuu/include/hikyuu/indicator/imp/IInBlock.h +1 -2
- hikyuu/include/hikyuu/indicator/imp/IIntpart.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IIsInf.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IIsInfa.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IIsLastBar.h +0 -1
- hikyuu/include/hikyuu/indicator/imp/IIsNa.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IJumpDown.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IJumpUp.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IKData.h +1 -2
- hikyuu/include/hikyuu/indicator/imp/ILiuTongPan.h +0 -2
- hikyuu/include/hikyuu/indicator/imp/ILn.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/ILog.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/ILowLine.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/ILowLineBars.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IMa.h +6 -1
- hikyuu/include/hikyuu/indicator/imp/IMacd.h +2 -0
- hikyuu/include/hikyuu/indicator/imp/INot.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IPow.h +3 -1
- hikyuu/include/hikyuu/indicator/imp/IQuantileTrunc.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IRecover.h +3 -0
- hikyuu/include/hikyuu/indicator/imp/IRef.h +3 -1
- hikyuu/include/hikyuu/indicator/imp/IResult.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IReverse.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IRoc.h +6 -1
- hikyuu/include/hikyuu/indicator/imp/IRocp.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IRocr.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IRocr100.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IRound.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IRoundDown.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IRoundUp.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/ISaftyLoss.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/ISign.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/ISin.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/ISlope.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/ISma.h +2 -0
- hikyuu/include/hikyuu/indicator/imp/ISpearman.h +3 -0
- hikyuu/include/hikyuu/indicator/imp/ISqrt.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IStdev.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IStdp.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/ISum.h +6 -1
- hikyuu/include/hikyuu/indicator/imp/ITan.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/ITime.h +1 -2
- hikyuu/include/hikyuu/indicator/imp/ITimeLine.h +0 -2
- hikyuu/include/hikyuu/indicator/imp/ITr.h +1 -2
- hikyuu/include/hikyuu/indicator/imp/IVar.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IVarp.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IVigor.h +0 -2
- hikyuu/include/hikyuu/indicator/imp/IWma.h +5 -1
- hikyuu/include/hikyuu/indicator/imp/IZongGuBen.h +1 -2
- hikyuu/include/hikyuu/indicator_talib/imp/TaAdosc.h +0 -2
- hikyuu/include/hikyuu/indicator_talib/imp/TaSar.h +0 -2
- hikyuu/include/hikyuu/indicator_talib/imp/TaSarext.h +0 -4
- hikyuu/include/hikyuu/indicator_talib/imp/TaStoch.h +0 -3
- hikyuu/include/hikyuu/indicator_talib/imp/TaStochf.h +0 -2
- hikyuu/include/hikyuu/indicator_talib/imp/TaUltosc.h +0 -2
- hikyuu/include/hikyuu/indicator_talib/imp/ta_defines.h +2 -4
- hikyuu/include/hikyuu/indicator_talib/imp/ta_imp.h +70 -90
- hikyuu/include/hikyuu/plugin/KDataToClickHouseImporter.h +40 -0
- hikyuu/include/hikyuu/plugin/KDataToMySQLImporter.h +40 -0
- hikyuu/include/hikyuu/plugin/checkdata.h +20 -0
- hikyuu/include/hikyuu/plugin/extind.h +3 -0
- hikyuu/include/hikyuu/plugin/hkuextra.h +4 -0
- hikyuu/include/hikyuu/plugin/interface/CheckDataPluginInterface.h +25 -0
- hikyuu/include/hikyuu/plugin/interface/HkuExtraPluginInterface.h +4 -0
- hikyuu/include/hikyuu/plugin/interface/ImportKDataToClickHousePluginInterface.h +44 -0
- hikyuu/include/hikyuu/plugin/interface/ImportKDataToMySQLPluginInterface.h +42 -0
- hikyuu/include/hikyuu/plugin/interface/plugins.h +6 -0
- hikyuu/include/hikyuu/python/convert_any.h +9 -6
- hikyuu/include/hikyuu/python/pybind_utils.h +22 -5
- hikyuu/include/hikyuu/strategy/Strategy.h +1 -1
- hikyuu/include/hikyuu/trade_manage/TradeCostBase.h +5 -3
- hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +9 -3
- hikyuu/include/hikyuu/trade_manage/TradeRecord.h +2 -1
- hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +8 -4
- hikyuu/include/hikyuu/trade_sys/allocatefunds/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/allocatefunds/crt/AF_FixedAmount.h +26 -0
- hikyuu/include/hikyuu/trade_sys/allocatefunds/imp/FixAmountFunds.h +18 -0
- hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +5 -3
- hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +6 -3
- hikyuu/include/hikyuu/trade_sys/moneymanager/MoneyManagerBase.h +5 -3
- hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +23 -20
- hikyuu/include/hikyuu/trade_sys/multifactor/NormalizeBase.h +6 -4
- hikyuu/include/hikyuu/trade_sys/multifactor/ScoresFilterBase.h +5 -3
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_EqualWeight.h +3 -3
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICIRWeight.h +4 -4
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICWeight.h +4 -4
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_Weight.h +4 -4
- hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +16 -13
- hikyuu/include/hikyuu/trade_sys/profitgoal/ProfitGoalBase.h +13 -13
- hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +12 -3
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor.h +1 -1
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor2.h +1 -1
- hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector.h +1 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector2.h +1 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalSelectorBase.h +0 -2
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/PerformanceOptimalSelector.h +0 -4
- hikyuu/include/hikyuu/trade_sys/signal/SignalBase.h +5 -3
- hikyuu/include/hikyuu/trade_sys/slippage/SlippageBase.h +5 -3
- hikyuu/include/hikyuu/trade_sys/stoploss/StoplossBase.h +5 -3
- hikyuu/include/hikyuu/trade_sys/system/System.h +6 -4
- hikyuu/include/hikyuu/utilities/Log.h +6 -7
- hikyuu/include/hikyuu/utilities/LruCache.h +299 -0
- hikyuu/include/hikyuu/utilities/Parameter.h +17 -0
- hikyuu/include/hikyuu/utilities/arithmetic.h +2 -2
- hikyuu/include/hikyuu/utilities/config.h +28 -0
- hikyuu/include/hikyuu/utilities/omp_macro.h +25 -0
- hikyuu/include/hikyuu/utilities/plugin/PluginBase.h +17 -2
- hikyuu/include/hikyuu/utilities/plugin/PluginManager.h +46 -22
- hikyuu/include/hikyuu/utilities/thread/GlobalStealThreadPool.h +71 -19
- hikyuu/include/hikyuu/utilities/thread/GlobalThreadPool.h +1 -5
- hikyuu/include/hikyuu/utilities/thread/MQStealThreadPool.h +286 -0
- hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +1 -0
- hikyuu/include/hikyuu/utilities/thread/StealThreadPool.h +297 -0
- hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +1 -4
- hikyuu/include/hikyuu/utilities/thread/WorkStealQueue.h +9 -8
- hikyuu/include/hikyuu/utilities/thread/algorithm.h +350 -14
- hikyuu/include/hikyuu/version.h +4 -4
- hikyuu/plugin/libbacktest.so +0 -0
- hikyuu/plugin/libcheckdata.so +0 -0
- hikyuu/plugin/libclickhousedriver.so +0 -0
- hikyuu/plugin/libdataserver.so +0 -0
- hikyuu/plugin/libdataserver_parquet.so +0 -0
- hikyuu/plugin/libdevice.so +0 -0
- hikyuu/plugin/libextind.so +0 -0
- hikyuu/plugin/libhkuextra.so +0 -0
- hikyuu/plugin/libimport2ch.so +0 -0
- hikyuu/plugin/libimport2hdf5.so +0 -0
- hikyuu/plugin/libimport2mysql.so +0 -0
- hikyuu/plugin/libtmreport.so +0 -0
- hikyuu/test/Indicator.py +1 -2
- hikyuu/trade_manage/__init__.pyi +14 -8
- hikyuu/trade_manage/trade.pyi +14 -8
- hikyuu/trade_sys/trade_sys.py +54 -5
- hikyuu/util/__init__.pyi +2 -2
- hikyuu/util/singleton.pyi +1 -1
- {hikyuu-2.7.0.dist-info → hikyuu-2.7.5.dist-info}/METADATA +10 -4
- {hikyuu-2.7.0.dist-info → hikyuu-2.7.5.dist-info}/RECORD +282 -252
- hikyuu/cpp/libboost_chrono-mt.so +0 -0
- hikyuu/cpp/libboost_chrono-mt.so.1.88.0 +0 -0
- hikyuu/cpp/libboost_date_time-mt.so +0 -0
- hikyuu/cpp/libboost_date_time-mt.so.1.88.0 +0 -0
- hikyuu/cpp/libboost_serialization-mt.so +0 -0
- hikyuu/cpp/libboost_serialization-mt.so.1.88.0 +0 -0
- hikyuu/cpp/libboost_system-mt.so +0 -0
- hikyuu/cpp/libboost_system-mt.so.1.88.0 +0 -0
- hikyuu/cpp/libboost_thread-mt.so +0 -0
- hikyuu/cpp/libboost_thread-mt.so.1.88.0 +0 -0
- hikyuu/cpp/libboost_wserialization-mt.so +0 -0
- hikyuu/cpp/libboost_wserialization-mt.so.1.88.0 +0 -0
- hikyuu/data/pytdx_to_taos.py +0 -736
- {hikyuu-2.7.0.dist-info → hikyuu-2.7.5.dist-info}/WHEEL +0 -0
- {hikyuu-2.7.0.dist-info → hikyuu-2.7.5.dist-info}/entry_points.txt +0 -0
- {hikyuu-2.7.0.dist-info → hikyuu-2.7.5.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2026-01-18
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#include <unordered_map>
|
|
10
|
+
#include <list>
|
|
11
|
+
#include <mutex>
|
|
12
|
+
#include <shared_mutex>
|
|
13
|
+
#include <atomic>
|
|
14
|
+
#include <optional>
|
|
15
|
+
|
|
16
|
+
namespace hku {
|
|
17
|
+
|
|
18
|
+
class NullLock {
|
|
19
|
+
public:
|
|
20
|
+
void lock() noexcept {}
|
|
21
|
+
void unlock() noexcept {}
|
|
22
|
+
bool try_lock() noexcept {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
void lock_shared() noexcept {}
|
|
26
|
+
void unlock_shared() noexcept {}
|
|
27
|
+
bool try_lock_shared() noexcept {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @brief LRU (Least Recently Used)
|
|
34
|
+
* 缓存实现(非严格意义LRU以便提升并发读取性能)
|
|
35
|
+
* @tparam KeyType 键的类型,必须支持哈希和相等比较
|
|
36
|
+
* @tparam ValueType 值的类型,必须支持拷贝和移动操作
|
|
37
|
+
*/
|
|
38
|
+
template <typename KeyType, typename ValueType, class Lock = NullLock>
|
|
39
|
+
class LruCache final {
|
|
40
|
+
public:
|
|
41
|
+
using key_type = KeyType;
|
|
42
|
+
using value_type = ValueType;
|
|
43
|
+
using size_type = size_t;
|
|
44
|
+
typedef Lock lock_type;
|
|
45
|
+
using UniqueGuard = std::unique_lock<lock_type>;
|
|
46
|
+
using SharedGuard = std::shared_lock<lock_type>;
|
|
47
|
+
|
|
48
|
+
// 存储结构:值 + 原子脏标记(标记是否被get访问过,需要更新LRU顺序)
|
|
49
|
+
using CacheValue = std::pair<value_type, std::atomic<bool>>;
|
|
50
|
+
using LruList = std::list<key_type>;
|
|
51
|
+
using CacheMap =
|
|
52
|
+
std::unordered_map<key_type, std::pair<typename LruList::iterator, CacheValue>>;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @brief 构造函数
|
|
56
|
+
* @param capacity 缓存容量,默认为64,0表示无限制容量
|
|
57
|
+
* @param overflow 溢出容量,默认为8,允许缓存临时超出设定容量
|
|
58
|
+
* 仅当缓存大小 >= 容量+溢出容量时才触发淘汰机制
|
|
59
|
+
*/
|
|
60
|
+
explicit LruCache(size_type capacity = 64, size_type overflow = 8)
|
|
61
|
+
: m_capacity(capacity), m_overflow(overflow) {}
|
|
62
|
+
|
|
63
|
+
~LruCache() {
|
|
64
|
+
UniqueGuard lock(m_mutex);
|
|
65
|
+
m_cache.clear();
|
|
66
|
+
m_lru_list.clear();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @brief 插入键值对
|
|
71
|
+
* @param key 键
|
|
72
|
+
* @param value 值
|
|
73
|
+
*/
|
|
74
|
+
void insert(const key_type& key, const value_type& value) {
|
|
75
|
+
UniqueGuard lock(m_mutex);
|
|
76
|
+
_batch_update_dirty_nodes();
|
|
77
|
+
auto it = m_cache.find(key);
|
|
78
|
+
if (it != m_cache.end()) {
|
|
79
|
+
it->second.second.first = value;
|
|
80
|
+
it->second.second.second.store(false, std::memory_order_relaxed);
|
|
81
|
+
m_lru_list.splice(m_lru_list.begin(), m_lru_list, it->second.first);
|
|
82
|
+
} else {
|
|
83
|
+
m_lru_list.emplace_front(key);
|
|
84
|
+
m_cache.emplace(key, std::make_pair(m_lru_list.begin(),
|
|
85
|
+
std::make_pair(value, false) // 初始脏标记为false
|
|
86
|
+
));
|
|
87
|
+
_prune_if_needed();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @brief 插入键值对(移动版本)
|
|
93
|
+
* @param key 键
|
|
94
|
+
* @param value 值(右值引用)
|
|
95
|
+
*/
|
|
96
|
+
void insert(const key_type& key, value_type&& value) {
|
|
97
|
+
UniqueGuard lock(m_mutex);
|
|
98
|
+
_batch_update_dirty_nodes();
|
|
99
|
+
auto it = m_cache.find(key);
|
|
100
|
+
if (it != m_cache.end()) {
|
|
101
|
+
it->second.second.first = std::move(value);
|
|
102
|
+
it->second.second.second.store(false, std::memory_order_relaxed);
|
|
103
|
+
m_lru_list.splice(m_lru_list.begin(), m_lru_list, it->second.first);
|
|
104
|
+
} else {
|
|
105
|
+
m_lru_list.emplace_front(key);
|
|
106
|
+
m_cache.emplace(
|
|
107
|
+
key, std::make_pair(m_lru_list.begin(), std::make_pair(std::move(value), false)));
|
|
108
|
+
_prune_if_needed();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @brief 获取键对应的值
|
|
114
|
+
* @param key 键
|
|
115
|
+
* @return 存在则返回值,否则返回ValueType的默认构造值
|
|
116
|
+
*/
|
|
117
|
+
value_type get(const key_type& key) {
|
|
118
|
+
SharedGuard lock(m_mutex);
|
|
119
|
+
auto it = m_cache.find(key);
|
|
120
|
+
if (it != m_cache.end()) {
|
|
121
|
+
it->second.second.second.store(true, std::memory_order_relaxed);
|
|
122
|
+
return it->second.second.first;
|
|
123
|
+
}
|
|
124
|
+
return value_type{};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @brief 尝试获取键对应的值
|
|
129
|
+
* @param key 键
|
|
130
|
+
* @param value 用于接收值的引用参数
|
|
131
|
+
* @return 如果键存在返回true,否则返回false
|
|
132
|
+
*/
|
|
133
|
+
bool tryGet(const key_type& key, value_type& value) {
|
|
134
|
+
SharedGuard lock(m_mutex);
|
|
135
|
+
auto it = m_cache.find(key);
|
|
136
|
+
if (it != m_cache.end()) {
|
|
137
|
+
it->second.second.second.store(true, std::memory_order_relaxed);
|
|
138
|
+
value = it->second.second.first;
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @brief 检查是否包含指定键
|
|
146
|
+
* @param key 键
|
|
147
|
+
* @return 存在返回true,否则返回false
|
|
148
|
+
*/
|
|
149
|
+
bool contains(const key_type& key) {
|
|
150
|
+
SharedGuard lock(m_mutex);
|
|
151
|
+
return m_cache.find(key) != m_cache.end();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @brief 删除指定键
|
|
156
|
+
* @param key 要删除的键
|
|
157
|
+
* @return 成功删除返回true,不存在返回false
|
|
158
|
+
*/
|
|
159
|
+
bool remove(const key_type& key) {
|
|
160
|
+
UniqueGuard lock(m_mutex);
|
|
161
|
+
auto it = m_cache.find(key);
|
|
162
|
+
if (it != m_cache.end()) {
|
|
163
|
+
m_lru_list.erase(it->second.first);
|
|
164
|
+
m_cache.erase(it);
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @brief 清空缓存
|
|
172
|
+
*/
|
|
173
|
+
void clear() {
|
|
174
|
+
UniqueGuard lock(m_mutex);
|
|
175
|
+
m_cache.clear();
|
|
176
|
+
m_lru_list.clear();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @brief 获取缓存当前大小
|
|
181
|
+
* @return 当前缓存元素数量
|
|
182
|
+
*/
|
|
183
|
+
size_type size() const {
|
|
184
|
+
SharedGuard lock(m_mutex);
|
|
185
|
+
return m_cache.size();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @brief 检查缓存是否为空
|
|
190
|
+
* @return 空返回true,否则返回false
|
|
191
|
+
*/
|
|
192
|
+
bool empty() const {
|
|
193
|
+
SharedGuard lock(m_mutex);
|
|
194
|
+
return m_cache.empty();
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* @brief 获取缓存容量
|
|
199
|
+
* @return 缓存容量
|
|
200
|
+
*/
|
|
201
|
+
size_type capacity() const {
|
|
202
|
+
SharedGuard lock(m_mutex);
|
|
203
|
+
return m_capacity;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* @brief 获取缓存溢出容量
|
|
208
|
+
* @return 缓存溢出容量
|
|
209
|
+
*/
|
|
210
|
+
size_type overflow() const {
|
|
211
|
+
SharedGuard lock(m_mutex);
|
|
212
|
+
return m_overflow;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @brief 设置缓存容量
|
|
217
|
+
* @param capacity 新的容量,0表示不限制容量
|
|
218
|
+
*/
|
|
219
|
+
void resize(size_type capacity) {
|
|
220
|
+
UniqueGuard lock(m_mutex);
|
|
221
|
+
m_capacity = capacity;
|
|
222
|
+
_prune_if_needed();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @brief 设置缓存溢出容量
|
|
227
|
+
* @param overflow 新的溢出容量
|
|
228
|
+
*/
|
|
229
|
+
void setOverflow(size_type overflow) {
|
|
230
|
+
UniqueGuard lock(m_mutex);
|
|
231
|
+
m_overflow = overflow;
|
|
232
|
+
_prune_if_needed();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private:
|
|
236
|
+
// 如果缓存已满,移除最久未使用的项
|
|
237
|
+
size_t _prune_if_needed() {
|
|
238
|
+
size_t maxAllowed = m_capacity + m_overflow;
|
|
239
|
+
if (m_capacity == 0 || m_cache.size() <= maxAllowed) {
|
|
240
|
+
return 0;
|
|
241
|
+
}
|
|
242
|
+
size_t count = 0;
|
|
243
|
+
while (m_cache.size() > m_capacity) {
|
|
244
|
+
m_cache.erase(m_lru_list.back());
|
|
245
|
+
m_lru_list.pop_back();
|
|
246
|
+
++count;
|
|
247
|
+
}
|
|
248
|
+
return count;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// 批量更新所有脏节点:移到链表头部,清除脏标记
|
|
252
|
+
void _batch_update_dirty_nodes() {
|
|
253
|
+
// 修复点1:避免默认构造,改用指针/引用追踪最新脏节点
|
|
254
|
+
typename LruList::reverse_iterator latest_dirty_it;
|
|
255
|
+
bool has_dirty = false;
|
|
256
|
+
|
|
257
|
+
// 反向遍历链表:从尾部→头部,找第一个脏节点(最新访问的节点)
|
|
258
|
+
for (auto it = m_lru_list.rbegin(); it != m_lru_list.rend(); ++it) {
|
|
259
|
+
const key_type& key = *it;
|
|
260
|
+
auto cache_it = m_cache.find(key);
|
|
261
|
+
if (cache_it == m_cache.end()) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
auto& dirty_flag = cache_it->second.second.second;
|
|
266
|
+
// 修复点2:原子加载判断,避免未初始化访问
|
|
267
|
+
if (dirty_flag.load(std::memory_order_relaxed)) {
|
|
268
|
+
latest_dirty_it = it;
|
|
269
|
+
has_dirty = true;
|
|
270
|
+
break; // 仅处理最新访问的脏节点,保留1在尾部
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// 仅移动最新访问的脏节点到头部(修复点3:反向迭代器转正向迭代器)
|
|
275
|
+
if (has_dirty) {
|
|
276
|
+
// C++17:反向迭代器转正向迭代器(base()方法)
|
|
277
|
+
auto forward_it = latest_dirty_it.base();
|
|
278
|
+
--forward_it; // 反向迭代器base()返回的是下一个正向迭代器,需减1
|
|
279
|
+
|
|
280
|
+
const key_type& key = *forward_it;
|
|
281
|
+
auto cache_it = m_cache.find(key);
|
|
282
|
+
if (cache_it != m_cache.end()) {
|
|
283
|
+
// 清除脏标记
|
|
284
|
+
cache_it->second.second.second.store(false, std::memory_order_relaxed);
|
|
285
|
+
// 移动节点到链表头部(splice仅支持正向迭代器)
|
|
286
|
+
m_lru_list.splice(m_lru_list.begin(), m_lru_list, forward_it);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private:
|
|
292
|
+
size_type m_capacity;
|
|
293
|
+
size_type m_overflow;
|
|
294
|
+
LruList m_lru_list;
|
|
295
|
+
CacheMap m_cache;
|
|
296
|
+
mutable lock_type m_mutex;
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
} // namespace hku
|
|
@@ -503,6 +503,23 @@ inline void Parameter::set(const string& name, const boost::any& value) {
|
|
|
503
503
|
m_params[name] = value;
|
|
504
504
|
}
|
|
505
505
|
|
|
506
|
+
template <>
|
|
507
|
+
inline int64_t Parameter::get(const string& name) const {
|
|
508
|
+
param_map_t::const_iterator iter;
|
|
509
|
+
iter = m_params.find(name);
|
|
510
|
+
if (iter == m_params.end()) {
|
|
511
|
+
throw std::out_of_range("out_of_range in Parameter::get : " + name);
|
|
512
|
+
}
|
|
513
|
+
try {
|
|
514
|
+
if (iter->second.type() == typeid(int)) {
|
|
515
|
+
return boost::any_cast<int>(iter->second);
|
|
516
|
+
}
|
|
517
|
+
return boost::any_cast<int64_t>(iter->second);
|
|
518
|
+
} catch (...) {
|
|
519
|
+
throw std::runtime_error("failed conversion param: " + name);
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
506
523
|
HKU_API bool operator==(const Parameter&, const Parameter&);
|
|
507
524
|
HKU_API bool operator!=(const Parameter&, const Parameter&);
|
|
508
525
|
HKU_API bool operator<(const Parameter&, const Parameter&);
|
|
@@ -209,12 +209,12 @@ extern template float HKU_UTILS_API roundDown(float number, int ndigits);
|
|
|
209
209
|
#endif
|
|
210
210
|
|
|
211
211
|
/** 转小写字符串 */
|
|
212
|
-
inline void to_lower(std::string &s) {
|
|
212
|
+
inline void to_lower(std::string &s) noexcept {
|
|
213
213
|
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::tolower(c); });
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
/** 转大写字符串 */
|
|
217
|
-
inline void to_upper(std::string &s) {
|
|
217
|
+
inline void to_upper(std::string &s) noexcept {
|
|
218
218
|
std::transform(s.begin(), s.end(), s.begin(), [](unsigned char c) { return std::toupper(c); });
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -6,33 +6,61 @@
|
|
|
6
6
|
|
|
7
7
|
// clang-format off
|
|
8
8
|
|
|
9
|
+
#ifndef HKU_ENABLE_MYSQL
|
|
9
10
|
#define HKU_ENABLE_MYSQL 1
|
|
10
11
|
#if HKU_ENABLE_MYSQL && HKU_OS_WINDOWS
|
|
11
12
|
#ifndef NOMINMAX
|
|
12
13
|
#define NOMINMAX
|
|
13
14
|
#endif
|
|
14
15
|
#endif
|
|
16
|
+
#endif
|
|
15
17
|
|
|
18
|
+
#ifndef HKU_ENABLE_SQLITE
|
|
16
19
|
#define HKU_ENABLE_SQLITE 1
|
|
20
|
+
#endif
|
|
21
|
+
#ifndef HKU_ENABLE_SQLCIPHER
|
|
17
22
|
#define HKU_ENABLE_SQLCIPHER 0
|
|
23
|
+
#endif
|
|
24
|
+
#ifndef HKU_SQL_TRACE
|
|
18
25
|
/* #define HKU_SQL_TRACE 0 */
|
|
26
|
+
#endif
|
|
19
27
|
|
|
28
|
+
#ifndef HKU_SUPPORT_DATETIME
|
|
20
29
|
#define HKU_SUPPORT_DATETIME 1
|
|
30
|
+
#endif
|
|
21
31
|
|
|
32
|
+
#ifndef HKU_ENABLE_INI_PARSER
|
|
22
33
|
#define HKU_ENABLE_INI_PARSER 1
|
|
34
|
+
#endif
|
|
23
35
|
|
|
36
|
+
#ifndef HKU_ENABLE_STACK_TRACE
|
|
24
37
|
#define HKU_ENABLE_STACK_TRACE 0
|
|
38
|
+
#endif
|
|
25
39
|
|
|
40
|
+
#ifndef HKU_CLOSE_SPEND_TIME
|
|
26
41
|
#define HKU_CLOSE_SPEND_TIME 0
|
|
42
|
+
#endif
|
|
27
43
|
|
|
44
|
+
#ifndef HKU_USE_SPDLOG_ASYNC_LOGGER
|
|
28
45
|
#define HKU_USE_SPDLOG_ASYNC_LOGGER 0
|
|
46
|
+
#endif
|
|
47
|
+
#ifndef HKU_LOG_ACTIVE_LEVEL
|
|
29
48
|
#define HKU_LOG_ACTIVE_LEVEL 2
|
|
49
|
+
#endif
|
|
30
50
|
|
|
51
|
+
#ifndef HKU_ENABLE_HTTP_CLIENT
|
|
31
52
|
#define HKU_ENABLE_HTTP_CLIENT 1
|
|
53
|
+
#endif
|
|
54
|
+
#ifndef HKU_ENABLE_HTTP_CLIENT_SSL
|
|
32
55
|
#define HKU_ENABLE_HTTP_CLIENT_SSL 0
|
|
56
|
+
#endif
|
|
57
|
+
#ifndef HKU_ENABLE_HTTP_CLIENT_ZIP
|
|
33
58
|
#define HKU_ENABLE_HTTP_CLIENT_ZIP 0
|
|
59
|
+
#endif
|
|
34
60
|
|
|
61
|
+
#ifndef HKU_ENABLE_NODE
|
|
35
62
|
#define HKU_ENABLE_NODE 1
|
|
63
|
+
#endif
|
|
36
64
|
|
|
37
65
|
// clang-format on
|
|
38
66
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2026-01-16
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "hikyuu/utilities/config.h"
|
|
11
|
+
|
|
12
|
+
#if defined(_OPENMP)
|
|
13
|
+
#include <omp.h>
|
|
14
|
+
#define HKU_OMP_PARALLEL_FOR _Pragma("omp parallel for")
|
|
15
|
+
#define HKU_OMP_SAFETY_PARALLEL_FOR \
|
|
16
|
+
_Pragma("omp parallel for num_threads(omp_get_max_threads()) if (!omp_in_parallel())")
|
|
17
|
+
#define HKU_OMP_CHECK_THRESHOLD(guard, threshold) \
|
|
18
|
+
if ((guard) > (threshold) && !omp_in_parallel()) { \
|
|
19
|
+
omp_set_num_threads(omp_get_max_threads()); \
|
|
20
|
+
}
|
|
21
|
+
#else
|
|
22
|
+
#define HKU_OMP_PARALLEL_FOR
|
|
23
|
+
#define HKU_OMP_SAFETY_PARALLEL_FOR
|
|
24
|
+
#define HKU_OMP_CHECK_THRESHOLD(guard, threshold)
|
|
25
|
+
#endif
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
#include <string>
|
|
13
13
|
#include "hikyuu/utilities/config.h"
|
|
14
14
|
#include "hikyuu/utilities/osdef.h"
|
|
15
|
+
#include "hikyuu/utilities/Log.h"
|
|
15
16
|
|
|
16
17
|
namespace hku {
|
|
17
18
|
|
|
@@ -35,12 +36,26 @@ public:
|
|
|
35
36
|
#if HKU_OS_WINDOWS
|
|
36
37
|
#define HKU_PLUGIN_DEFINE(plugin) \
|
|
37
38
|
extern "C" __declspec(dllexport) hku::PluginBase* createPlugin() { \
|
|
38
|
-
|
|
39
|
+
try { \
|
|
40
|
+
return new plugin(); \
|
|
41
|
+
} catch (const std::exception& e) { \
|
|
42
|
+
HKU_ERROR("{}", e.what()); \
|
|
43
|
+
return nullptr; \
|
|
44
|
+
} catch (...) { \
|
|
45
|
+
return nullptr; \
|
|
46
|
+
} \
|
|
39
47
|
}
|
|
40
48
|
#else
|
|
41
49
|
#define HKU_PLUGIN_DEFINE(plugin) \
|
|
42
50
|
extern "C" hku::PluginBase* createPlugin() { \
|
|
43
|
-
|
|
51
|
+
try { \
|
|
52
|
+
return new plugin(); \
|
|
53
|
+
} catch (const std::exception& e) { \
|
|
54
|
+
HKU_ERROR("{}", e.what()); \
|
|
55
|
+
return nullptr; \
|
|
56
|
+
} catch (...) { \
|
|
57
|
+
return nullptr; \
|
|
58
|
+
} \
|
|
44
59
|
}
|
|
45
60
|
#endif
|
|
46
61
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
#include <string>
|
|
11
11
|
#include <memory>
|
|
12
12
|
#include <unordered_map>
|
|
13
|
-
#include <
|
|
13
|
+
#include <shared_mutex>
|
|
14
14
|
#include "hikyuu/utilities/Log.h"
|
|
15
15
|
#include "hikyuu/utilities/plugin/PluginLoader.h"
|
|
16
16
|
|
|
@@ -37,36 +37,60 @@ public:
|
|
|
37
37
|
m_plugin_path = plugin_path;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
void clear() noexcept {
|
|
41
|
+
std::unique_lock<std::shared_mutex> write_lock(m_mutex);
|
|
42
|
+
m_plugins.clear();
|
|
43
|
+
}
|
|
44
|
+
|
|
40
45
|
template <typename PluginInterfaceT>
|
|
41
|
-
PluginInterfaceT* getPlugin(const std::string& pluginname) noexcept
|
|
46
|
+
PluginInterfaceT* getPlugin(const std::string& pluginname) noexcept {
|
|
47
|
+
PluginInterfaceT* ret{nullptr};
|
|
48
|
+
try {
|
|
49
|
+
{
|
|
50
|
+
std::shared_lock<std::shared_mutex> read_lock(m_mutex);
|
|
51
|
+
auto it = m_plugins.find(pluginname);
|
|
52
|
+
if (it != m_plugins.end()) {
|
|
53
|
+
ret = it->second->instance<PluginInterfaceT>();
|
|
54
|
+
return ret;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
42
57
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
std::unique_ptr<PluginLoader> loader = std::make_unique<PluginLoader>(m_plugin_path);
|
|
48
|
-
if (loader->load(pluginname)) {
|
|
49
|
-
auto [it, success] = m_plugins.insert(std::make_pair(pluginname, std::move(loader)));
|
|
50
|
-
if (success) {
|
|
51
|
-
return it;
|
|
58
|
+
std::unique_ptr<PluginLoader> loader = std::make_unique<PluginLoader>(m_plugin_path);
|
|
59
|
+
if (!loader->load(pluginname)) {
|
|
60
|
+
HKU_DEBUG("Load plugin {} failed: {}", pluginname, loader->getFileName(pluginname));
|
|
61
|
+
return ret;
|
|
52
62
|
}
|
|
63
|
+
|
|
64
|
+
{
|
|
65
|
+
std::unique_lock<std::shared_mutex> write_lock(m_mutex);
|
|
66
|
+
auto it = m_plugins.find(pluginname);
|
|
67
|
+
if (it != m_plugins.end()) {
|
|
68
|
+
// 复用已插入的插件实例
|
|
69
|
+
ret = it->second->instance<PluginInterfaceT>();
|
|
70
|
+
} else {
|
|
71
|
+
// 插入新加载的插件
|
|
72
|
+
auto [it, success] =
|
|
73
|
+
m_plugins.insert(std::make_pair(pluginname, std::move(loader)));
|
|
74
|
+
if (success) {
|
|
75
|
+
ret = it->second->instance<PluginInterfaceT>();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return ret;
|
|
79
|
+
}
|
|
80
|
+
} catch (const std::exception& e) {
|
|
81
|
+
HKU_ERROR("Load plugin {} failed: {}", pluginname, e.what());
|
|
82
|
+
ret = nullptr;
|
|
83
|
+
} catch (...) {
|
|
84
|
+
HKU_ERROR("Load plugin {} failed: unknown exception", pluginname);
|
|
85
|
+
ret = nullptr;
|
|
53
86
|
}
|
|
54
|
-
return
|
|
87
|
+
return ret;
|
|
55
88
|
}
|
|
56
89
|
|
|
57
90
|
private:
|
|
58
91
|
std::string m_plugin_path;
|
|
59
92
|
std::unordered_map<std::string, std::unique_ptr<PluginLoader>> m_plugins;
|
|
60
|
-
std::
|
|
93
|
+
std::shared_mutex m_mutex;
|
|
61
94
|
};
|
|
62
95
|
|
|
63
|
-
template <typename PluginInterfaceT>
|
|
64
|
-
PluginInterfaceT* PluginManager::getPlugin(const std::string& pluginname) noexcept {
|
|
65
|
-
auto it = m_plugins.find(pluginname);
|
|
66
|
-
if (it == m_plugins.end()) {
|
|
67
|
-
it = load(pluginname);
|
|
68
|
-
}
|
|
69
|
-
return it != m_plugins.end() ? it->second->instance<PluginInterfaceT>() : nullptr;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
96
|
} // namespace hku
|