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 #include "event_loop_select.h"
17
18 #ifdef EVENT_LOOP_USE_SELECT
19 #include <chrono>
20 #include "db_errno.h"
21 #include "log_print.h"
22
23 namespace DistributedDB {
EventLoopSelect()24 EventLoopSelect::EventLoopSelect()
25 {
26 }
27
~EventLoopSelect()28 EventLoopSelect::~EventLoopSelect()
29 {
30 }
31
Initialize()32 int EventLoopSelect::Initialize()
33 {
34 return E_OK;
35 }
36
Prepare(const std::set<EventImpl * > & polling)37 int EventLoopSelect::Prepare(const std::set<EventImpl *> &polling)
38 {
39 (void)polling;
40 return E_OK;
41 }
42
Poll(EventTime sleepTime)43 int EventLoopSelect::Poll(EventTime sleepTime)
44 {
45 std::unique_lock<std::mutex> lockGuard(wakeUpMutex_);
46 auto now = std::chrono::system_clock::now();
47 auto to = now + std::chrono::milliseconds(sleepTime);
48 wakeUpCondition_.wait_until(lockGuard, to);
49 return E_OK;
50 }
51
WakeUp()52 int EventLoopSelect::WakeUp()
53 {
54 wakeUpCondition_.notify_one();
55 return E_OK;
56 }
57
Exit(const std::set<EventImpl * > & polling)58 int EventLoopSelect::Exit(const std::set<EventImpl *> &polling)
59 {
60 (void)polling;
61 return E_OK;
62 }
63
AddEvent(EventImpl * event)64 int EventLoopSelect::AddEvent(EventImpl *event)
65 {
66 (void)event;
67 return E_OK;
68 }
69
RemoveEvent(EventImpl * event)70 int EventLoopSelect::RemoveEvent(EventImpl *event)
71 {
72 (void)event;
73 return E_OK;
74 }
75
ModifyEvent(EventImpl * event,bool isAdd,EventsMask events)76 int EventLoopSelect::ModifyEvent(EventImpl *event, bool isAdd, EventsMask events)
77 {
78 (void)event;
79 (void)isAdd;
80 (void)events;
81 return E_OK;
82 }
83
84 DEFINE_OBJECT_TAG_FACILITIES(EventLoopSelect)
85 } // namespace DistributedDB
86
87 #endif // EVENT_LOOP_USE_SELECT
88