OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 #ifndef CRASHPAD_UTIL_TEST_THREAD_H_ | |
16 #define CRASHPAD_UTIL_TEST_THREAD_H_ | |
17 | |
18 #include "base/basictypes.h" | |
19 #include "build/build_config.h" | |
20 | |
21 #if defined(OS_POSIX) | |
22 #include <pthread.h> | |
23 #elif defined(OS_WIN) | |
24 #include <windows.h> | |
25 #endif // OS_POSIX | |
26 | |
27 namespace crashpad { | |
28 namespace test { | |
29 | |
30 //! \brief Basic thread abstraction for testing. Users should derive from this | |
31 //! class and implement ThreadMain(). | |
32 class Thread { | |
33 public: | |
34 Thread(); | |
35 virtual ~Thread(); | |
36 | |
37 //! \brief Create a platform thread, and run ThreadMain() on that thread. Must | |
38 //! be paired with a call to Join(). | |
39 void Start(); | |
40 | |
41 //! \brief Block until ThreadMain() exits. This may be called from any thread. | |
42 //! Must paired with a call to Start(). | |
43 void Join(); | |
44 | |
45 private: | |
46 //! \brief The entry point to be overridden to implement the test-specific | |
47 //! functionality. | |
48 virtual void ThreadMain() = 0; | |
49 | |
50 static | |
51 #if defined(OS_POSIX) | |
52 void* | |
53 #elif defined(OS_WIN) | |
54 DWORD WINAPI | |
55 #endif // OS_POSIX | |
56 ThreadEntryThunk(void* argument); | |
57 | |
58 #if defined(OS_POSIX) | |
59 pthread_t platform_thread_; | |
60 #elif defined(OS_WIN) | |
61 HANDLE platform_thread_; | |
62 #endif | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(Thread); | |
65 }; | |
66 | |
67 } // namespace test | |
68 } // namespace crashpad | |
69 | |
70 #endif // CRASHPAD_UTIL_TEST_THREAD_H_ | |
OLD | NEW |