home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Magazine / HomeAutomation / Apache / include / php / TSRM / TSRM.h < prev   
Encoding:
C/C++ Source or Header  |  2000-06-16  |  3.2 KB  |  112 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | Thread Safe Resource Manager                                         |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1998, 1999 Zeev Suraski                                |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to the Zend license, that is bundled     |
  8.    | with this package in the file LICENSE.  If you did not receive a     |
  9.    | copy of the Zend license, please mail us at zend@zend.com so we can  |
  10.    | send you a copy immediately.                                         |
  11.    +----------------------------------------------------------------------+
  12.    | Author:  Zeev Suraski <zeev@zend.com>                                |
  13.    +----------------------------------------------------------------------+
  14. */
  15.  
  16.  
  17. #ifndef _TSRM_H
  18. #define _TSRM_H
  19.  
  20. #ifdef HAVE_CONFIG_H
  21. # undef PACKAGE
  22. # undef VERSION
  23. # include "tsrm_config.h"
  24. # undef PACKAGE
  25. # undef VERSION
  26. #endif
  27.  
  28. #if WIN32||WINNT
  29. # include <windows.h>
  30. #elif defined(GNUPTH)
  31. # include <pth.h>
  32. #elif defined(PTHREADS)
  33. # include <pthread.h>
  34. #endif
  35.  
  36. typedef int ts_rsrc_id;
  37.  
  38. #if WIN32||WINNT
  39. #    ifdef TSRM_EXPORTS
  40. #    define TSRM_API __declspec(dllexport)
  41. #    else
  42. #    define TSRM_API __declspec(dllimport)
  43. #    endif
  44. #else
  45. #    define TSRM_API
  46. #endif
  47.  
  48.  
  49. /* Define THREAD_T and MUTEX_T */
  50. #if defined(WIN32)
  51. # define THREAD_T DWORD
  52. # define MUTEX_T CRITICAL_SECTION *
  53. #elif defined(GNUPTH)
  54. # define THREAD_T pth_t
  55. # define MUTEX_T pth_mutex_t *
  56. #elif defined(PTHREADS)
  57. # define THREAD_T pthread_t
  58. # define MUTEX_T pthread_mutex_t *
  59. #elif defined(NSAPI)
  60. # define THREAD_T SYS_THREAD
  61. # define MUTEX_T CRITICAL
  62. #elif defined(PI3WEB)
  63. # define THREAD_T PIThread *
  64. # define MUTEX_T PISync *
  65. #endif
  66.  
  67. typedef void (*ts_allocate_ctor)(void *);
  68. typedef void (*ts_allocate_dtor)(void *);
  69.  
  70. #define THREAD_HASH_OF(thr,ts)  (unsigned long)thr%(unsigned long)ts
  71.  
  72. #ifdef __cplusplus
  73. extern "C" {
  74. #endif
  75.  
  76. /* startup/shutdown */
  77. TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_status);
  78. TSRM_API void tsrm_shutdown(void);
  79.  
  80. /* allocates a new thread-safe-resource id */
  81. TSRM_API ts_rsrc_id ts_allocate_id(size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor);
  82.  
  83. /* fetches the requested resource for the current thread */
  84. TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id);
  85. #define ts_resource(id)            ts_resource_ex(id, NULL)
  86.  
  87. /* frees all resources allocated for the current thread */
  88. TSRM_API void ts_free_thread(void);
  89.  
  90. /* deallocates all occurrences of a given id */
  91. TSRM_API void ts_free_id(ts_rsrc_id id);
  92.  
  93.  
  94. /* Debug support */
  95. TSRM_API void tsrm_debug_set(int status);
  96.  
  97. /* utility functions */
  98. TSRM_API THREAD_T tsrm_thread_id(void);
  99. TSRM_API MUTEX_T tsrm_mutex_alloc(void);
  100. TSRM_API void tsrm_mutex_free(MUTEX_T mutexp);
  101. TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp);
  102. TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp);
  103.  
  104. TSRM_API void *tsrm_set_new_thread_begin_handler(void (*new_thread_begin_handler)(THREAD_T thread_id));
  105. TSRM_API void *tsrm_set_new_thread_end_handler(void (*new_thread_end_handler)(THREAD_T thread_id));
  106.  
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110.  
  111. #endif /* _TSRM_H */
  112.