thread_wrapper.h 819 B

1234567891011121314151617181920212223242526
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /* Simple wrapper for unit test threads */
  5. #ifndef WIN32
  6. #include <pthread.h>
  7. #define THREAD_HANDLE pthread_t
  8. #define THREAD_CREATE(handle, callback) pthread_create(&handle, NULL, callback, NULL)
  9. #define THREAD_JOIN(handle) pthread_join(handle, NULL)
  10. #define THREAD_CALLBACK(name) static void * name(void *_)
  11. #else
  12. #include <windows.h>
  13. #define THREAD_HANDLE HANDLE
  14. #define THREAD_CREATE(handle, callback) { handle = CreateThread( NULL, 0, callback, NULL, 0, NULL); }
  15. #define THREAD_JOIN(handle) WaitForSingleObject(handle, INFINITE)
  16. #define THREAD_CALLBACK(name) DWORD WINAPI name( LPVOID lpParam )
  17. #endif