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_impl.h" 17 #include "db_errno.h" 18 19 #ifdef EVENT_LOOP_USE_EPOLL 20 #include "event_loop_epoll.h" 21 using EventLoop = DistributedDB::EventLoopEpoll; 22 #else 23 #include "event_loop_select.h" 24 using EventLoop = DistributedDB::EventLoopSelect; 25 #endif 26 27 namespace DistributedDB { CreateEventLoop(int & errCode)28IEventLoop *IEventLoop::CreateEventLoop(int &errCode) 29 { 30 EventLoopImpl *loop = new (std::nothrow) EventLoop; 31 if (loop == nullptr) { 32 errCode = -E_OUT_OF_MEMORY; 33 return nullptr; 34 } 35 36 errCode = loop->Initialize(); 37 if (errCode != E_OK) { 38 delete loop; 39 loop = nullptr; 40 } 41 return loop; 42 } 43 } 44