1999-04-23 11:00:02 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Thread Safe Resource Manager |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Copyright (c) 1998, 1999 Zeev Suraski |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| This source file is subject to the Zend license, that is bundled |
|
|
|
|
| with this package in the file LICENSE. If you did not receive a |
|
|
|
|
| copy of the Zend license, please mail us at zend@zend.com so we can |
|
|
|
|
| send you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: Zeev Suraski <zeev@zend.com> |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1999-04-20 23:58:02 +00:00
|
|
|
#ifndef _TSRM_H
|
|
|
|
#define _TSRM_H
|
|
|
|
|
1999-04-24 16:14:18 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
1999-09-26 19:46:35 +00:00
|
|
|
# undef PACKAGE
|
|
|
|
# undef VERSION
|
1999-04-24 23:22:09 +00:00
|
|
|
# include "tsrm_config.h"
|
1999-09-26 19:47:35 +00:00
|
|
|
# undef PACKAGE
|
|
|
|
# undef VERSION
|
1999-04-24 09:01:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if WIN32||WINNT
|
|
|
|
# include <windows.h>
|
1999-12-05 21:55:43 +00:00
|
|
|
#elif defined(GNUPTH)
|
|
|
|
# include <pth.h>
|
1999-04-24 09:01:30 +00:00
|
|
|
#elif defined(PTHREADS)
|
|
|
|
# include <pthread.h>
|
|
|
|
#endif
|
1999-04-20 23:58:02 +00:00
|
|
|
|
|
|
|
typedef int ts_rsrc_id;
|
|
|
|
|
1999-04-28 18:35:42 +00:00
|
|
|
#if WIN32||WINNT
|
|
|
|
# ifdef TSRM_EXPORTS
|
|
|
|
# define TSRM_API __declspec(dllexport)
|
|
|
|
# else
|
|
|
|
# define TSRM_API __declspec(dllimport)
|
|
|
|
# endif
|
|
|
|
#else
|
|
|
|
# define TSRM_API
|
|
|
|
#endif
|
|
|
|
|
1999-04-20 23:58:02 +00:00
|
|
|
|
|
|
|
/* Define THREAD_T and MUTEX_T */
|
|
|
|
#if defined(WIN32)
|
|
|
|
# define THREAD_T DWORD
|
1999-12-20 20:02:25 +00:00
|
|
|
# define MUTEX_T CRITICAL_SECTION *
|
1999-12-05 21:55:43 +00:00
|
|
|
#elif defined(GNUPTH)
|
1999-12-30 15:52:08 +00:00
|
|
|
# define THREAD_T pth_t
|
1999-12-05 21:55:43 +00:00
|
|
|
# define MUTEX_T pth_mutex_t *
|
1999-04-20 23:58:02 +00:00
|
|
|
#elif defined(PTHREADS)
|
|
|
|
# define THREAD_T pthread_t
|
|
|
|
# define MUTEX_T pthread_mutex_t *
|
|
|
|
#elif defined(NSAPI)
|
|
|
|
# define THREAD_T SYS_THREAD
|
|
|
|
# define MUTEX_T CRITICAL
|
|
|
|
#elif defined(PI3WEB)
|
|
|
|
# define THREAD_T PIThread *
|
|
|
|
# define MUTEX_T PISync *
|
|
|
|
#endif
|
|
|
|
|
1999-10-04 15:21:39 +00:00
|
|
|
typedef void (*ts_allocate_ctor)(void *);
|
1999-12-05 16:21:37 +00:00
|
|
|
typedef void (*ts_allocate_dtor)(void *);
|
1999-04-20 23:58:02 +00:00
|
|
|
|
1999-10-05 15:15:01 +00:00
|
|
|
#define THREAD_HASH_OF(thr,ts) (unsigned long)thr%(unsigned long)ts
|
1999-04-20 23:58:02 +00:00
|
|
|
|
1999-08-14 09:35:52 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
1999-04-20 23:58:02 +00:00
|
|
|
|
|
|
|
/* startup/shutdown */
|
1999-08-14 09:35:52 +00:00
|
|
|
TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_status);
|
1999-12-05 16:21:37 +00:00
|
|
|
TSRM_API void tsrm_shutdown(void);
|
1999-04-20 23:58:02 +00:00
|
|
|
|
|
|
|
/* allocates a new thread-safe-resource id */
|
1999-12-05 16:21:37 +00:00
|
|
|
TSRM_API ts_rsrc_id ts_allocate_id(size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor);
|
1999-04-20 23:58:02 +00:00
|
|
|
|
|
|
|
/* fetches the requested resource for the current thread */
|
1999-08-14 09:35:52 +00:00
|
|
|
TSRM_API void *ts_resource(ts_rsrc_id id);
|
1999-04-20 23:58:02 +00:00
|
|
|
|
|
|
|
/* frees all resources allocated for the current thread */
|
1999-12-05 16:21:37 +00:00
|
|
|
TSRM_API void ts_free_thread(void);
|
1999-04-20 23:58:02 +00:00
|
|
|
|
|
|
|
/* deallocates all occurrences of a given id */
|
1999-08-14 09:35:52 +00:00
|
|
|
TSRM_API void ts_free_id(ts_rsrc_id id);
|
1999-04-20 23:58:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Debug support */
|
1999-08-14 09:35:52 +00:00
|
|
|
TSRM_API void tsrm_debug_set(int status);
|
1999-04-20 23:58:02 +00:00
|
|
|
|
|
|
|
/* utility functions */
|
1999-08-14 09:35:52 +00:00
|
|
|
TSRM_API THREAD_T tsrm_thread_id(void);
|
|
|
|
TSRM_API MUTEX_T tsrm_mutex_alloc(void);
|
|
|
|
TSRM_API void tsrm_mutex_free(MUTEX_T mutexp);
|
|
|
|
TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp);
|
|
|
|
TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp);
|
|
|
|
|
|
|
|
TSRM_API void *tsrm_set_new_thread_begin_handler(void (*new_thread_begin_handler)(THREAD_T thread_id));
|
|
|
|
TSRM_API void *tsrm_set_new_thread_end_handler(void (*new_thread_end_handler)(THREAD_T thread_id));
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
1999-04-20 23:58:02 +00:00
|
|
|
|
1999-04-24 09:01:30 +00:00
|
|
|
#endif /* _TSRM_H */
|