• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 PROFILER_DATA_REPEATER_H
16 #define PROFILER_DATA_REPEATER_H
17 
18 #include <condition_variable>
19 #include <deque>
20 #include <memory>
21 #include <mutex>
22 #include "logging.h"
23 #include "nocopyable.h"
24 #include "profiler_service_types.pb.h"
25 
26 using ProfilerPluginDataPtr = STD_PTR(shared, ProfilerPluginData);
27 
28 class ProfilerDataRepeater {
29 public:
30     explicit ProfilerDataRepeater(size_t maxSize);
31     ~ProfilerDataRepeater();
32 
33     bool PutPluginData(const ProfilerPluginDataPtr& pluginData);
34 
35     ProfilerPluginDataPtr TakePluginData();
36 
37     int TakePluginData(std::vector<ProfilerPluginDataPtr>& pluginDataVec);
38 
39     void Close();
40 
41     void Reset();
42 
43     size_t Size();
44 
45     void ClearQueue();
46 
47 private:
48     std::mutex mutex_;
49     std::condition_variable slotCondVar_;
50     std::condition_variable itemCondVar_;
51     std::deque<ProfilerPluginDataPtr> dataQueue_;
52     size_t maxSize_;
53     bool closed_;
54 
55     DISALLOW_COPY_AND_MOVE(ProfilerDataRepeater);
56 };
57 
58 using ProfilerDataRepeaterPtr = STD_PTR(shared, ProfilerDataRepeater);
59 
60 #endif // PROFILER_DATA_REPEATER_H