2 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All rights reserved.
5 * Vyacheslav Cherkashin <v.cherkashin@samsung.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 * - Samsung RnD Institute Russia
25 #ifndef EVLOOP_REQUEST_H
26 #define EVLOOP_REQUEST_H
31 #include <swap_debug.h>
44 } catch (const std::runtime_error &e) {
45 LOGE("%s\n", e.what());
47 LOGE("Unknown error\n");
52 virtual void do_execute() = 0;
58 void push(std::unique_ptr<Request> &req)
60 std::lock_guard<std::mutex> lock(req_queue_mutex_);
61 req_queue_.push(std::move(req));
66 req_queue_mutex_.lock();
67 while (!req_queue_.empty()) {
68 auto req = std::move(req_queue_.front());
70 req_queue_mutex_.unlock();
74 req_queue_mutex_.lock();
76 req_queue_mutex_.unlock();
81 std::lock_guard<std::mutex> lock(req_queue_mutex_);
82 return req_queue_.empty();
86 std::queue<std::unique_ptr<Request>> req_queue_;
87 std::mutex req_queue_mutex_;
93 #endif // EVLOOP_REQUEST_H