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 : /*!
12 : * \file kernel_raise_signal.h
13 : * \brief
14 : */
15 : #ifndef ASCENDC_KERNEL_RAISE_SIGNAL_H
16 : #define ASCENDC_KERNEL_RAISE_SIGNAL_H
17 : #include <csignal>
18 : #include <cstdint>
19 :
20 : namespace AscendC {
21 :
22 : class KernelRaise {
23 : public:
24 0 : static KernelRaise& GetInstance()
25 : {
26 : static KernelRaise instance;
27 0 : return instance;
28 : }
29 :
30 0 : void Raise(const int sig)
31 : {
32 0 : count += 1;
33 0 : if (status) {
34 0 : (void)raise(sig);
35 : }
36 0 : }
37 :
38 : uint64_t GetRaiseCount() const { return count; }
39 :
40 : void SetRaiseMode(const bool isRaise) { this->status = isRaise; }
41 :
42 : private:
43 : KernelRaise() = default;
44 : ~KernelRaise() = default;
45 : KernelRaise(const KernelRaise&) = delete;
46 : KernelRaise& operator=(const KernelRaise&) = delete;
47 :
48 : private:
49 : uint64_t count = 0;
50 : bool status = true;
51 : };
52 :
53 : } // namespace AscendC
54 :
55 : #endif // ASCENDC_KERNEL_RAISE_SIGNAL_H
|