• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2011 The Android Open Source Project
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 #ifndef _OSUTILS_THREAD_H
17 #define _OSUTILS_THREAD_H
18 
19 #ifdef _WIN32
20 #include <windows.h>
21 #else // !WIN32
22 #include <pthread.h>
23 #endif
24 
25 namespace osUtils {
26 
27 class Thread
28 {
29 public:
30     Thread();
31     virtual ~Thread();
32 
33     virtual int Main() = 0;
34 
35     bool start();
36     bool  wait(int *exitStatus);
37     bool trywait(int *exitStatus);
38 
39 private:
40 #ifdef _WIN32
41     static DWORD WINAPI thread_main(void *p_arg);
42 #else // !WIN32
43     static void* thread_main(void *p_arg);
44 #endif
45 
46 private:
47 #ifdef _WIN32
48     HANDLE m_thread;
49     DWORD m_threadId;
50 #else // !WIN32
51     pthread_t m_thread;
52     int       m_exitStatus;
53     pthread_mutex_t m_lock;
54 #endif
55     bool m_isRunning;
56 };
57 
58 } // of namespace osUtils
59 
60 #endif
61