1 /* thread.hh
2  * This file belongs to Worker, a file manager for UN*X/X11.
3  * Copyright (C) 2006,2016 Ralf Hoffmann.
4  * You can contact me at: ralf@boomerangsworld.de
5  *   or http://www.boomerangsworld.de/worker
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21 
22 #ifndef THREAD_HH
23 #define THREAD_HH
24 
25 #include "mutex.h"
26 #include <pthread.h>
27 
28 class Thread
29 {
30 public:
31     Thread();
32     virtual ~Thread();
33 
34     virtual int start();
35     virtual int join();
36     virtual int run() = 0;
37     virtual bool running();
38     virtual void signalCancel();
39 
40     virtual bool amIThisThread() const;
41 
42     virtual bool isCanceled();
43 private:
44     static void *thread_entry( void *me );
45     void thread_run();
46 
47     pthread_t _id;
48     MutEx _lock;
49     bool m_running;
50     bool m_cancel;
51 };
52 
53 #endif
54