• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025-2025 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 MOCK_FFRT_API_CPP_CONDITION_VARIABLE_H
16 #define MOCK_FFRT_API_CPP_CONDITION_VARIABLE_H
17 
18 #include <chrono>
19 #include <mutex>
20 #include "mutex.h"
21 #include "c/condition_variable.h"
22 
23 namespace ffrt {
24 
25 enum class cv_status { no_timeout, timeout };
26 
27 class condition_variable : public ffrt_cond_t {
28 public:
condition_variable()29     condition_variable()
30     {}
31 
~condition_variable()32     ~condition_variable() noexcept
33     {
34     }
35 
36     condition_variable(const condition_variable &) = delete;
37 
38     condition_variable &operator=(const condition_variable &) = delete;
39 
40     template <typename Clock, typename Duration, typename Pred>
wait_until(std::unique_lock<mutex> & lk,const std::chrono::time_point<Clock,Duration> & tp,Pred && pred)41     bool wait_until(
42         std::unique_lock<mutex> &lk, const std::chrono::time_point<Clock, Duration> &tp, Pred &&pred) noexcept
43     {
44         return true;
45     }
46 
47     template <typename Clock, typename Duration>
wait_until(std::unique_lock<mutex> & lk,const std::chrono::time_point<Clock,Duration> & tp)48     cv_status wait_until(std::unique_lock<mutex> &lk, const std::chrono::time_point<Clock, Duration> &tp) noexcept
49     {
50         return cv_status::timeout;
51     }
52 
53     template <typename Rep, typename Period>
wait_for(std::unique_lock<mutex> & lk,const std::chrono::duration<Rep,Period> & sleep_time)54     cv_status wait_for(std::unique_lock<mutex> &lk, const std::chrono::duration<Rep, Period> &sleep_time) noexcept
55     {
56         return cv_status::timeout;
57     }
58 
59     template <typename Rep, typename Period, typename Pred>
wait_for(std::unique_lock<mutex> & lk,const std::chrono::duration<Rep,Period> & sleepTime,Pred && pred)60     bool wait_for(
61         std::unique_lock<mutex> &lk, const std::chrono::duration<Rep, Period> &sleepTime, Pred &&pred) noexcept
62     {
63         return true;
64     }
65 
66     template <typename Pred>
wait(std::unique_lock<mutex> & lk,Pred && pred)67     void wait(std::unique_lock<mutex> &lk, Pred &&pred)
68     {
69     }
70 
wait(std::unique_lock<mutex> & lk)71     void wait(std::unique_lock<mutex> &lk)
72     {}
73 
notify_one()74     void notify_one() noexcept
75     {}
76 
notify_all()77     void notify_all() noexcept
78     {}
79 
80 private:
81     template <typename Rep, typename Period>
_wait_for(std::unique_lock<mutex> & lk,const std::chrono::duration<Rep,Period> & dur)82     cv_status _wait_for(std::unique_lock<mutex> &lk, const std::chrono::duration<Rep, Period> &dur) noexcept
83     {
84         return cv_status::timeout;
85     }
86 };
87 }  // namespace ffrt
88 
89 #endif