Collage  1.1.2
High-performance C++ library for developing object-oriented distributed applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
worker.h
1 
2 /* Copyright (c) 2011-2014, Stefan Eilemann <eile@eyescale.ch>
3  *
4  * This file is part of Collage <https://github.com/Eyescale/Collage>
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 2.1 as published
8  * by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef CO_WORKER_H
21 #define CO_WORKER_H
22 
23 #include <co/api.h> // CO_API definition
24 #include <co/types.h>
25 #include <lunchbox/thread.h> // base class
26 #include <limits.h>
27 
28 #ifndef CO_WORKER_API
29 # define CO_WORKER_API CO_API
30 #endif
31 
32 namespace co
33 {
35 template< class Q > class WorkerThread : public lunchbox::Thread
36 {
37 public:
39  WorkerThread( const size_t maxSize = ULONG_MAX ) : _commands( maxSize ) {}
40 
42  virtual ~WorkerThread() {}
43 
45  Q* getWorkerQueue() { return &_commands; }
46 
47 protected:
49  CO_WORKER_API void run() override;
50 
52  virtual bool stopRunning() { return false; }
53 
55  virtual bool notifyIdle() { return false; }
56 
57 private:
59  Q _commands;
60 };
61 
62 typedef WorkerThread< CommandQueue > Worker; // instantiated in worker.cpp
63 }
64 #endif //CO_WORKER_H
Defines export visibility macros for Collage.
CO_WORKER_API void run() override
Definition: worker.ipp:25
WorkerThread(const size_t maxSize=ULONG_MAX)
Construct a new worker thread.
Definition: worker.h:39
virtual bool stopRunning()
Definition: worker.h:52
virtual bool notifyIdle()
Definition: worker.h:55
virtual ~WorkerThread()
Destruct the worker.
Definition: worker.h:42
Q * getWorkerQueue()
Definition: worker.h:45