thread.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* libanode: the Anode C reference implementation
  2. * Copyright (C) 2009-2010 Adam Ierymenko <[email protected]>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #ifndef _ANODE_THREAD_H
  17. #define _ANODE_THREAD_H
  18. #ifdef WINDOWS
  19. #include <windows.h>
  20. #include <thread.h>
  21. typedef DWORD AnodeThreadId;
  22. #else /* not WINDOWS */
  23. #include <pthread.h>
  24. typedef pthread_t AnodeThreadId;
  25. #define AnodeThread_self() pthread_self()
  26. #define AnodeThreadId_equal(a,b) pthread_equal((pthread_t)(a),(pthread_t)(b))
  27. #endif
  28. typedef void AnodeThread;
  29. /**
  30. * Create and launch a new thread
  31. *
  32. * If wait_for_join is true (nonzero), the thread can and must be joined. The
  33. * thread object won't be freed until join is called and returns. If
  34. * wait_for_join is false, the thread object frees itself automatically on
  35. * termination.
  36. *
  37. * If wait_for_join is false (zero), there is really no need to keep track of
  38. * the thread object.
  39. *
  40. * @param func Function to call as thread main
  41. * @param arg Argument to pass to function
  42. * @param wait_for_join If false, thread deletes itself when it terminates
  43. */
  44. AnodeThread *AnodeThread_create(void (*func)(void *),void *arg,int wait_for_join);
  45. /**
  46. * Wait for a thread to terminate and delete thread object
  47. *
  48. * This can only be used for threads created with wait_for_join set to true.
  49. * The thread object is no longer valid after this call.
  50. *
  51. * @param thread Thread to wait for termination and delete
  52. */
  53. void AnodeThread_join(AnodeThread *thread);
  54. #endif