Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef HCCL_AICPU_DAEMON_SERVICE_H
12 : #define HCCL_AICPU_DAEMON_SERVICE_H
13 :
14 : #include <cstdint>
15 : #include <vector>
16 : #include <mutex>
17 : #include "daemon_func.h"
18 : #include "enum_factory_legacy.h"
19 :
20 : namespace Hccl {
21 :
22 : using Funcs = void (*)(void*);
23 : extern "C" {
24 : int32_t __attribute__((weak)) StartMC2MaintenanceThread(Funcs f1, void* p1, Funcs f2, void* p2);
25 : };
26 :
27 8 : MAKE_ENUM(CommandToBackGroud, Default, Stop)
28 :
29 : class AicpuDaemonService {
30 : public:
31 : static AicpuDaemonService& GetInstance();
32 : void ServiceRun(void* info);
33 : void ServiceStop(void* info) const;
34 : void Register(DaemonFunc* daemonFunc);
35 : void Unregister(DaemonFunc* daemonFunc);
36 : void Break(); // 强制停止
37 :
38 : private:
39 : std::vector<DaemonFunc*> daemonFuncs;
40 : bool needBreak{false};
41 : static std::mutex mutexForFuncs_;
42 : };
43 : } // namespace Hccl
44 : #endif // HCCL_AICPU_DAEMON_SERVICE_H
|