• 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_SERIAL_QUEUE_H
16 #define FFRT_SERIAL_QUEUE_H
17 
18 #include <list>
19 #include <map>
20 #include <string>
21 #include "cpp/condition_variable.h"
22 #include "internal_inc/non_copyable.h"
23 #include "itask.h"
24 
25 namespace ffrt {
26 class SerialQueue : public NonCopyable {
27 public:
SerialQueue(const std::string & name)28     explicit SerialQueue(const std::string& name) : name_(name) {}
29     ~SerialQueue();
30 
31     ITask* Next();
32     int PushTask(ITask* task, uint64_t upTime);
33     int RemoveTask(const ITask* task);
34     void Quit();
35 
36 private:
37     ffrt::mutex mutex_;
38     ffrt::condition_variable cond_;
39     bool isExit_ = false;
40     std::string name_;
41     std::map<uint64_t, std::list<ITask*>> whenMap_;
42 };
43 } // namespace ffrt
44 
45 #endif // FFRT_SERIAL_QUEUE_H