-
Notifications
You must be signed in to change notification settings - Fork 1
/
SafeEnvThread.h
72 lines (62 loc) · 1.41 KB
/
SafeEnvThread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#if !defined(_SafeEnvThread__INCLUDED_)
#define _SafeEnvThread__INCLUDED_
#if(DRIVER_LOCKED_LEVEL == DRIVER_LOCKED_LEVEL_ENV || DRIVER_LOCKED_LEVEL == DRIVER_LOCKED_LEVEL_CONNECT)
#ifdef _PTHREADS
#include <pthread.h>
#endif
namespace OdbcJdbcLibrary {
class MutexEnvThread
{
public:
#ifdef _WINDOWS
static void * mutexLockedLevelDll;
#endif
#ifdef _PTHREADS
static pthread_mutex_t mutexLockedLevelDll;
#endif
public:
MutexEnvThread()
{
#ifdef _WINDOWS
mutexLockedLevelDll = CreateMutex (NULL, false, NULL);
#endif
#ifdef _PTHREADS
int ret = pthread_mutex_init (&mutexLockedLevelDll, NULL);
#endif
}
~MutexEnvThread()
{
#ifdef _WINDOWS
if(mutexLockedLevelDll)
CloseHandle (mutexLockedLevelDll);
#endif
#ifdef _PTHREADS
int ret = pthread_mutex_destroy (&mutexLockedLevelDll);
#endif
}
};
class SafeDllThread
{
public:
SafeDllThread()
{
#ifdef _WINDOWS
WaitForSingleObject (MutexEnvThread::mutexLockedLevelDll, INFINITE);
#endif
#ifdef _PTHREADS
pthread_mutex_lock (&MutexEnvThread::mutexLockedLevelDll);
#endif
}
~SafeDllThread()
{
#ifdef _WINDOWS
ReleaseMutex (MutexEnvThread::mutexLockedLevelDll);
#endif
#ifdef _PTHREADS
pthread_mutex_unlock (&MutexEnvThread::mutexLockedLevelDll);
#endif
}
};
}; // end namespace OdbcJdbcLibrary
#endif // #if(DRIVER_LOCKED_LEVEL == DRIVER_LOCKED_LEVEL_ENV || DRIVER_LOCKED_LEVEL == DRIVER_LOCKED_LEVEL_CONNECT)
#endif // !defined(_SafeEnvThread__INCLUDED_)