Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
worker.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Piotr Bartosiewicz <p.bartosiewi@partner.samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 
25 #ifndef COMMON_UTILS_WORKER_HPP
26 #define COMMON_UTILS_WORKER_HPP
27 
28 #include <functional>
29 #include <memory>
30 
31 namespace utils {
32 
37 class Worker {
38 public:
39  typedef std::shared_ptr<Worker> Pointer;
40  typedef std::function<void()> Task;
41 
42  ~Worker();
43 
47  static Pointer create();
48 
53 
57  void addTask(const Task& task);
58  void addTaskAndWait(const Task& task);
59 
60 private:
61  typedef unsigned int GroupID;
62  class WorkerQueue;
63 
64  const std::shared_ptr<WorkerQueue> mWorkerQueue;
66 
67  Worker(const std::shared_ptr<WorkerQueue>& workerQueue);
68 };
69 
70 } // namespace utils
71 
72 
73 #endif // COMMON_UTILS_WORKER_HPP
const GroupID mGroupID
Definition: worker.hpp:65
Worker(const std::shared_ptr< WorkerQueue > &workerQueue)
Definition: worker.cpp:167
~Worker()
Definition: worker.cpp:172
Pointer createSubWorker()
Creates a worker that share a thread with its parent.
Definition: worker.cpp:177
const std::shared_ptr< WorkerQueue > mWorkerQueue
Definition: worker.hpp:62
void addTask(const Task &task)
Adds a task to the queue.
Definition: worker.cpp:182
void addTaskAndWait(const Task &task)
Definition: worker.cpp:187
std::function< void()> Task
Definition: worker.hpp:40
static Pointer create()
Creates a worker with its own thread.
Definition: worker.cpp:162
Definition: worker.cpp:42
A queue with tasks executed in a dedicated thread.
Definition: worker.hpp:37
unsigned int GroupID
Definition: worker.hpp:61
std::shared_ptr< Worker > Pointer
Definition: worker.hpp:39