ffead.server.doc
Thread.h
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * Thread.h
18  *
19  * Created on: 10-Aug-2012
20  * Author: sumeetc
21  */
22 
23 #ifndef THREAD_H_
24 #define THREAD_H_
25 #include <pthread.h>
26 #include <time.h>
27 #include <unistd.h>
28 typedef void* (*ThreadFunc)(void*);
29 
30 class Thread;
31 
33 {
34  friend class Thread;
35  ThreadFunc f;
36  void* arg;
37 };
38 
39 class Thread {
40  ThreadFunctor* threadFunctor;
41  pthread_t pthread;
42  pthread_cond_t cond;
43  pthread_mutex_t mut;
44  static void* _service(void* arg);
45 public:
46  Thread(ThreadFunc f, void* arg);
47  virtual ~Thread();
48  void execute();
49  void join();
50  static void nSleep(long nanos);
51  static void uSleep(long nanos);
52  static void mSleep(long nanos);
53  static void sSleep(long nanos);
54  void wait();
55  void interrupt();
56 };
57 
58 #endif /* THREAD_H_ */