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