win.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef _TOOLKIT_WIN_HEADER_H_
  2. #define _TOOLKIT_WIN_HEADER_H_
  3. #ifdef _WIN32
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. typedef struct {
  8. DWORD tls_index;
  9. } toolkit_key_t;
  10. typedef CRITICAL_SECTION toolkit_mutex_t;
  11. typedef struct toolkit_once_s {
  12. unsigned char ran;
  13. HANDLE event;
  14. } toolkit_once_t;
  15. #define TOOLKIT_ONCE_INIT { 0, NULL }
  16. typedef HANDLE toolkit_thread_t;
  17. typedef struct {
  18. HMODULE handle;
  19. char* errmsg;
  20. } toolkit_lib_t;
  21. typedef HANDLE toolkit_sem_t;
  22. typedef int toolkit_pid_t;
  23. /* This condition variable implementation is based on the SetEvent solution
  24. * (section 3.2) at http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
  25. * We could not use the SignalObjectAndWait solution (section 3.4) because
  26. * it want the 2nd argument (type toolkit_mutex_t) of toolkit_cond_wait() and
  27. * toolkit_cond_timedwait() to be HANDLEs, but we use CRITICAL_SECTIONs.
  28. */
  29. typedef union {
  30. CONDITION_VARIABLE cond_var;
  31. struct {
  32. unsigned int waiters_count;
  33. CRITICAL_SECTION waiters_count_lock;
  34. HANDLE signal_event;
  35. HANDLE broadcast_event;
  36. } unused_; /* TODO: retained for ABI compatibility; remove me in v2.x. */
  37. } toolkit_cond_t;
  38. typedef union {
  39. struct {
  40. unsigned int num_readers_;
  41. CRITICAL_SECTION num_readers_lock_;
  42. HANDLE write_semaphore_;
  43. } state_;
  44. /* TODO: remove me in v2.x. */
  45. struct {
  46. SRWLOCK unused_;
  47. } unused1_;
  48. /* TODO: remove me in v2.x. */
  49. struct {
  50. toolkit_mutex_t unused1_;
  51. toolkit_mutex_t unused2_;
  52. } unused2_;
  53. } toolkit_rwlock_t;
  54. typedef struct {
  55. unsigned int n;
  56. unsigned int count;
  57. toolkit_mutex_t mutex;
  58. toolkit_sem_t turnstile1;
  59. toolkit_sem_t turnstile2;
  60. } toolkit_barrier_t;
  61. int snprintf(char* buf, size_t len, const char* fmt, ...);
  62. #ifdef __cplusplus
  63. } // extern "C" {
  64. #endif
  65. #endif //_WIN32
  66. #endif //_TOOLKIT_WIN_HEADER_H_