jemalloc_test.h.in 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * This header should be included by tests, rather than directly including
  3. * jemalloc/jemalloc.h, because --with-install-suffix may cause the header to
  4. * have a different name.
  5. */
  6. #include "jemalloc/jemalloc@install_suffix@.h"
  7. #include "jemalloc/internal/jemalloc_internal.h"
  8. /* Abstraction layer for threading in tests */
  9. #ifdef _WIN32
  10. #include <windows.h>
  11. typedef HANDLE je_thread_t;
  12. void
  13. je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg)
  14. {
  15. LPTHREAD_START_ROUTINE routine = (LPTHREAD_START_ROUTINE)proc;
  16. *thread = CreateThread(NULL, 0, routine, arg, 0, NULL);
  17. if (*thread == NULL) {
  18. malloc_printf("Error in CreateThread()\n");
  19. exit(1);
  20. }
  21. }
  22. void
  23. je_thread_join(je_thread_t thread, void **ret)
  24. {
  25. WaitForSingleObject(thread, INFINITE);
  26. }
  27. #else
  28. #include <pthread.h>
  29. typedef pthread_t je_thread_t;
  30. void
  31. je_thread_create(je_thread_t *thread, void *(*proc)(void *), void *arg)
  32. {
  33. if (pthread_create(thread, NULL, proc, arg) != 0) {
  34. malloc_printf("Error in pthread_create()\n");
  35. exit(1);
  36. }
  37. }
  38. void
  39. je_thread_join(je_thread_t thread, void **ret)
  40. {
  41. pthread_join(thread, ret);
  42. }
  43. #endif