Merge commit 'origin/master'
[versaplex.git] / vxodbc / environ.h
blob5f673b46f647c12e56bc9dcddce49b764785f354
1 /*
3 * Description: See "environ.c"
5 * Comments: See "notice.txt" for copyright and license information.
7 */
9 #ifndef __ENVIRON_H__
10 #define __ENVIRON_H__
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
16 #include "psqlodbc.h"
18 #if defined (POSIX_MULTITHREAD_SUPPORT)
19 #include <pthread.h>
20 #endif
22 #define ENV_ALLOC_ERROR 1
24 /********** Environment Handle *************/
25 struct EnvironmentClass_
27 char *errormsg;
28 int errornumber;
29 Int4 flag;
30 #if defined(WIN_MULTITHREAD_SUPPORT)
31 CRITICAL_SECTION cs;
32 #elif defined(POSIX_MULTITHREAD_SUPPORT)
33 pthread_mutex_t cs;
34 #endif /* WIN_MULTITHREAD_SUPPORT */
37 /* Environment prototypes */
38 EnvironmentClass *EN_Constructor(void);
39 char EN_Destructor(EnvironmentClass *self);
40 char EN_get_error(EnvironmentClass *self, int *number, char **message);
41 char EN_add_connection(EnvironmentClass *self, ConnectionClass *conn);
42 char EN_remove_connection(EnvironmentClass *self, ConnectionClass *conn);
43 void EN_log_error(const char *func, char *desc, EnvironmentClass *self);
45 #define EN_OV_ODBC2 1L
46 #define EN_CONN_POOLING (1L<<1)
47 #define EN_is_odbc2(env) ((env->flag & EN_OV_ODBC2) != 0)
48 #define EN_is_odbc3(env) (env && (env->flag & EN_OV_ODBC2) == 0)
49 #define EN_set_odbc2(env) (env->flag |= EN_OV_ODBC2)
50 #define EN_set_odbc3(env) (env->flag &= ~EN_OV_ODBC2)
51 #define EN_is_pooling(env) (env && (env->flag & EN_CONN_POOLING) != 0)
52 #define EN_set_pooling(env) (env->flag |= EN_CONN_POOLING)
53 #define EN_unset_pooling(env) (env->flag &= ~EN_CONN_POOLING)
55 /* For Multi-thread */
56 #if defined( WIN_MULTITHREAD_SUPPORT)
57 #define INIT_CONNS_CS InitializeCriticalSection(&conns_cs)
58 #define ENTER_CONNS_CS EnterCriticalSection(&conns_cs)
59 #define LEAVE_CONNS_CS LeaveCriticalSection(&conns_cs)
60 #define DELETE_CONNS_CS DeleteCriticalSection(&conns_cs)
61 #define INIT_ENV_CS(x) InitializeCriticalSection(&((x)->cs))
62 #define ENTER_ENV_CS(x) EnterCriticalSection(&((x)->cs))
63 #define LEAVE_ENV_CS(x) LeaveCriticalSection(&((x)->cs))
64 #define DELETE_ENV_CS(x) DeleteCriticalSection(&((x)->cs))
65 #define INIT_COMMON_CS InitializeCriticalSection(&common_cs)
66 #define ENTER_COMMON_CS EnterCriticalSection(&common_cs)
67 #define LEAVE_COMMON_CS LeaveCriticalSection(&common_cs)
68 #define DELETE_COMMON_CS DeleteCriticalSection(&common_cs)
69 #elif defined(POSIX_MULTITHREAD_SUPPORT)
70 #define INIT_CONNS_CS pthread_mutex_init(&conns_cs,0)
71 #define ENTER_CONNS_CS pthread_mutex_lock(&conns_cs)
72 #define LEAVE_CONNS_CS pthread_mutex_unlock(&conns_cs)
73 #define DELETE_CONNS_CS pthread_mutex_destroy(&conns_cs)
74 #define INIT_ENV_CS(x) pthread_mutex_init(&((x)->cs),0)
75 #define ENTER_ENV_CS(x) pthread_mutex_lock(&((x)->cs))
76 #define LEAVE_ENV_CS(x) pthread_mutex_unlock(&((x)->cs))
77 #define DELETE_ENV_CS(x) pthread_mutex_destroy(&((x)->cs))
78 #define INIT_COMMON_CS pthread_mutex_init(&common_cs,0)
79 #define ENTER_COMMON_CS pthread_mutex_lock(&common_cs)
80 #define LEAVE_COMMON_CS pthread_mutex_unlock(&common_cs)
81 #define DELETE_COMMON_CS pthread_mutex_destroy(&common_cs)
82 #else
83 #define INIT_CONNS_CS
84 #define ENTER_CONNS_CS
85 #define LEAVE_CONNS_CS
86 #define DELETE_CONNS_CS
87 #define INIT_ENV_CS(x)
88 #define ENTER_ENV_CS(x)
89 #define LEAVE_ENV_CS(x)
90 #define DELETE_ENV_CS(x)
91 #define INIT_COMMON_CS
92 #define ENTER_COMMON_CS
93 #define LEAVE_COMMON_CS
94 #define DELETE_COMMON_CS
95 #endif /* WIN_MULTITHREAD_SUPPORT */
97 #ifdef __cplusplus
99 #endif
100 #endif /* __ENVIRON_H_ */