• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef FFRT_QUEUE_MONITOR_H
16 #define FFRT_QUEUE_MONITOR_H
17 
18 #include <mutex>
19 #include <shared_mutex>
20 #include <string>
21 #include <vector>
22 #include "sched/execute_ctx.h"
23 
24 namespace ffrt {
25 class QueueMonitor {
26 public:
27     static QueueMonitor &GetInstance();
28     void RegisterQueueId(uint32_t queueId);
29     void ResetQueueInfo(uint32_t queueId);
30     void UpdateQueueInfo(uint32_t queueId, const uint64_t &taskId);
31 
32 private:
33     QueueMonitor();
34     ~QueueMonitor() = default;
35     QueueMonitor(const QueueMonitor &) = delete;
36     QueueMonitor(QueueMonitor &&) = delete;
37     QueueMonitor &operator=(const QueueMonitor &) = delete;
38     QueueMonitor &operator=(QueueMonitor &&) = delete;
39 
40     void SendDelayedWorker(time_point_t delay);
41     void CheckQueuesStatus();
42     void ResetTaskTimestampAfterWarning(uint32_t queueId, const uint64_t &taskId);
43 
44     uint64_t timeoutUs_ = 0;
45     std::shared_mutex mutex_;
46     std::vector<std::pair<uint64_t, time_point_t>> QueuesRunningInfo;
47 };
48 } // namespace ffrt
49 
50 #endif // FFRT_QUEUE_MONITOR_H