1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
9  * of the source code distribution tree; Copyright.html can be found at the  *
10  * root level of an installed copy of the electronic HDF5 document set and   *
11  * is linked from the top-level documents page.  It can also be found at     *
12  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
13  * access to either file, you may request a copy from help@hdfgroup.org.     *
14  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /*-------------------------------------------------------------------------
17  *
18  * Created:		H5TSprivate.h
19  *			May 2 2000
20  *			Chee Wai LEE
21  *
22  * Purpose:		Private non-prototype header.
23  *
24  * Modifications:
25  *
26  *-------------------------------------------------------------------------
27  */
28 #ifndef H5TSprivate_H_
29 #define H5TSprivate_H_
30 
31 /* Public headers needed by this file */
32 #ifdef LATER
33 #include "H5TSpublic.h"		/*Public API prototypes */
34 #endif /* LATER */
35 
36 #ifdef H5_HAVE_WIN_THREADS
37 
38 /* Library level data structures */
39 
40 /* Mutexes, Threads, and Attributes */
41 typedef struct H5TS_mutex_struct {
42 	CRITICAL_SECTION CriticalSection;
43 } H5TS_mutex_t;
44 typedef CRITICAL_SECTION H5TS_mutex_simple_t;
45 typedef HANDLE H5TS_thread_t;
46 typedef HANDLE H5TS_attr_t;
47 typedef DWORD H5TS_key_t;
48 typedef INIT_ONCE H5TS_once_t;
49 
50 /* Defines */
51 /* not used on windows side, but need to be defined to something */
52 #define H5TS_SCOPE_SYSTEM 0
53 #define H5TS_SCOPE_PROCESS 0
54 #define H5TS_CALL_CONV WINAPI
55 
56 /* Functions */
57 #define H5TS_get_thread_local_value(key)	TlsGetValue( key )
58 #define H5TS_set_thread_local_value(key, value)	TlsSetValue( key, value )
59 #define H5TS_attr_init(attr_ptr) 0
60 #define H5TS_attr_setscope(attr_ptr, scope) 0
61 #define H5TS_attr_destroy(attr_ptr) 0
62 #define H5TS_wait_for_thread(thread) WaitForSingleObject(thread, INFINITE)
63 #define H5TS_mutex_init(mutex) InitializeCriticalSection(mutex)
64 #define H5TS_mutex_lock_simple(mutex) EnterCriticalSection(mutex)
65 #define H5TS_mutex_unlock_simple(mutex) LeaveCriticalSection(mutex)
66 
67 /* Functions called from DllMain */
68 H5_DLL BOOL CALLBACK H5TS_win32_process_enter(PINIT_ONCE InitOnce, PVOID Parameter, PVOID *lpContex);
69 H5_DLL void H5TS_win32_process_exit(void);
70 H5_DLL herr_t H5TS_win32_thread_enter(void);
71 H5_DLL herr_t H5TS_win32_thread_exit(void);
72 
73 
74 
75 #else /* H5_HAVE_WIN_THREADS */
76 
77 /* Library level data structures */
78 
79 /* Mutexes, Threads, and Attributes */
80 typedef struct H5TS_mutex_struct {
81     pthread_t owner_thread;		/* current lock owner */
82     pthread_mutex_t atomic_lock;	/* lock for atomicity of new mechanism */
83     pthread_cond_t cond_var;		/* condition variable */
84     unsigned int lock_count;
85 } H5TS_mutex_t;
86 typedef pthread_t      H5TS_thread_t;
87 typedef pthread_attr_t H5TS_attr_t;
88 typedef pthread_mutex_t H5TS_mutex_simple_t;
89 typedef pthread_key_t  H5TS_key_t;
90 typedef pthread_once_t H5TS_once_t;
91 
92 /* Scope Definitions */
93 #define H5TS_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM
94 #define H5TS_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS
95 #define H5TS_CALL_CONV /* unused - Windows only */
96 
97 /* Functions */
98 #define H5TS_get_thread_local_value(key)	pthread_getspecific( key )
99 #define H5TS_set_thread_local_value(key, value)	pthread_setspecific( key, value )
100 #define H5TS_attr_init(attr_ptr) pthread_attr_init((attr_ptr))
101 #define H5TS_attr_setscope(attr_ptr, scope) pthread_attr_setscope(attr_ptr, scope)
102 #define H5TS_attr_destroy(attr_ptr) pthread_attr_destroy(attr_ptr)
103 #define H5TS_wait_for_thread(thread) pthread_join(thread, NULL)
104 #define H5TS_mutex_init(mutex) pthread_mutex_init(mutex, NULL)
105 #define H5TS_mutex_lock_simple(mutex) pthread_mutex_lock(mutex)
106 #define H5TS_mutex_unlock_simple(mutex) pthread_mutex_unlock(mutex)
107 
108 #endif /* H5_HAVE_WIN_THREADS */
109 
110 /* External global variables */
111 extern H5TS_once_t H5TS_first_init_g;
112 extern H5TS_key_t H5TS_errstk_key_g;
113 extern H5TS_key_t H5TS_funcstk_key_g;
114 
115 #if defined c_plusplus || defined __cplusplus
116 extern      "C"
117 {
118 #endif	/* c_plusplus || __cplusplus */
119 
120 H5_DLL void   H5TS_pthread_first_thread_init(void);
121 H5_DLL herr_t H5TS_mutex_lock(H5TS_mutex_t *mutex);
122 H5_DLL herr_t H5TS_mutex_unlock(H5TS_mutex_t *mutex);
123 H5_DLL herr_t H5TS_cancel_count_inc(void);
124 H5_DLL herr_t H5TS_cancel_count_dec(void);
125 H5_DLL H5TS_thread_t H5TS_create_thread(void * func, H5TS_attr_t * attr, void *udata);
126 
127 #if defined c_plusplus || defined __cplusplus
128 }
129 #endif	/* c_plusplus || __cplusplus */
130 
131 #endif	/* H5TSprivate_H_ */
132