threads.hh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. /*
  9. Example ussage of threads :
  10. void test(void *arg)
  11. {
  12. .. do something..
  13. }
  14. my_main()
  15. {
  16. i4_add_thread(test,10*1024);
  17. }
  18. */
  19. #ifndef I4_THREADS_HH
  20. #define I4_THREADS_HH
  21. #include "arch.hh"
  22. typedef void (*i4_thread_func_type)(void *context);
  23. i4_bool i4_threads_supported();
  24. // this will start the thread right away, regardless of how many threads are running
  25. void i4_add_thread(i4_thread_func_type fun, w32 stack_size=50*1024, void *context=0);
  26. void i4_thread_yield();
  27. void i4_wait_threads(); // waits for all threads to terminate (don't call from a thread!)
  28. int i4_get_thread_id();
  29. int i4_get_main_thread_id();
  30. void i4_suspend_other_threads(); // stops all of threads from running
  31. void i4_resume_other_threads(); // resumes execution of other threads
  32. int i4_get_first_thread_id();
  33. i4_bool i4_get_next_thread_id(int last_id, int &id);
  34. void i4_get_thread_stack(int thread_id, void *&base, void *&top);
  35. enum i4_thread_priority_type { I4_THREAD_PRIORITY_HIGH,
  36. I4_THREAD_PRIORITY_NORMAL,
  37. I4_THREAD_PRIORITY_LOW };
  38. void i4_set_thread_priority(int thread_id, i4_thread_priority_type priority);
  39. class i4_critical_section_class
  40. {
  41. w32 data[6]; // to store operating system depandant data, enlarge if needed
  42. public:
  43. i4_critical_section_class();
  44. void I4_FAST_CALL lock();
  45. void I4_FAST_CALL unlock();
  46. ~i4_critical_section_class();
  47. };
  48. class i4_signal_object
  49. {
  50. w32 data[1]; // to store operating system depandant data, enlarge if needed
  51. public:
  52. i4_signal_object(char *name);
  53. void wait_signal();
  54. void signal();
  55. ~i4_signal_object();
  56. };
  57. #endif