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 
16 #ifndef EVENT_LOOP_SELECT_H
17 #define EVENT_LOOP_SELECT_H
18 
19 #include "event_loop_impl.h"
20 
21 #ifdef EVENT_LOOP_USE_SELECT
22 #include <mutex>
23 #include <condition_variable>
24 
25 namespace DistributedDB {
26 class EventLoopSelect : public EventLoopImpl {
27 public:
28     EventLoopSelect();
29     ~EventLoopSelect();
30 
31     int Initialize() override;
32 
33 private:
34     int Prepare(const std::set<EventImpl *> &polling) override;
35     int Poll(EventTime sleepTime) override;
36     int WakeUp() override;
37     int Exit(const std::set<EventImpl *> &polling) override;
38     int AddEvent(EventImpl *event) override;
39     int RemoveEvent(EventImpl *event) override;
40     int ModifyEvent(EventImpl *event, bool isAdd, EventsMask events) override;
41 
42     DECLARE_OBJECT_TAG(EventLoopSelect);
43 
44     std::mutex wakeUpMutex_;
45     std::condition_variable wakeUpCondition_;
46 };
47 } // namespace DistributedDB
48 #endif // EVENT_LOOP_USE_SELECT
49 #endif // EVENT_LOOP_SELECT_H
50