00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "ocilib_internal.h"
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 OCI_ThreadKey * OCI_ThreadKeyCreateInternal(POCI_THREADKEYDEST destfunc)
00046 {
00047 boolean res = TRUE;
00048 OCI_ThreadKey *key = NULL;
00049
00050
00051
00052 key = (OCI_ThreadKey *) OCI_MemAlloc(OCI_IPC_THREADKEY, sizeof(*key), 1, TRUE);
00053
00054 if (key != NULL)
00055 {
00056
00057
00058 res = (OCI_SUCCESS == OCI_HandleAlloc(OCILib.env,
00059 (dvoid **) (void *) &key->err,
00060 OCI_HTYPE_ERROR, 0,
00061 (dvoid **) NULL));
00062
00063
00064
00065 OCI_CALL3
00066 (
00067 res, key->err,
00068
00069 OCIThreadKeyInit(OCILib.env, key->err, &key->handle, destfunc)
00070 )
00071 }
00072 else
00073 res = FALSE;
00074
00075
00076
00077 if (res == FALSE)
00078 {
00079 OCI_ThreadKeyFree(key);
00080 key = NULL;
00081 }
00082
00083 return key;
00084 }
00085
00086
00087
00088
00089 boolean OCI_ThreadKeyFree(OCI_ThreadKey *key)
00090 {
00091 boolean res = TRUE;
00092
00093 OCI_CHECK(key == NULL, FALSE);
00094
00095
00096
00097 if (key->handle != NULL)
00098 {
00099 OCI_CALL0
00100 (
00101 res, key->err,
00102
00103 OCIThreadKeyDestroy(OCILib.env, key->err, &key->handle)
00104 )
00105 }
00106
00107
00108
00109 if (key->err != NULL)
00110 {
00111 OCI_HandleFree(key->err, OCI_HTYPE_ERROR);
00112 }
00113
00114
00115
00116 OCI_FREE(key);
00117
00118 OCI_RESULT(res);
00119
00120 return res;
00121 }
00122
00123
00124
00125
00126
00127 boolean OCI_ThreadKeySet(OCI_ThreadKey *key, void *value)
00128 {
00129 boolean res = TRUE;
00130
00131 OCI_CHECK(key == NULL, FALSE);
00132
00133 OCI_CALL3
00134 (
00135 res, key->err,
00136
00137 OCIThreadKeySet(OCILib.env, key->err, key->handle, value)
00138 )
00139
00140 return res;
00141 }
00142
00143
00144
00145
00146
00147 boolean OCI_ThreadKeyGet(OCI_ThreadKey* key, void **value)
00148 {
00149 boolean res = TRUE;
00150
00151 OCI_CHECK(key == NULL, FALSE);
00152
00153 OCI_CALL3
00154 (
00155 res, key->err,
00156
00157 OCIThreadKeyGet(OCILib.env, key->err, key->handle, value)
00158 )
00159
00160 return res;
00161 }
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 boolean OCI_API OCI_ThreadKeyCreate(const mtext *name, POCI_THREADKEYDEST destfunc)
00172 {
00173 OCI_ThreadKey *key = NULL;
00174 boolean res = TRUE;
00175
00176 OCI_CHECK_PTR(OCI_IPC_STRING, name, FALSE);
00177
00178 OCI_CHECK_INITIALIZED(FALSE);
00179
00180 if (OCILib.key_map == NULL)
00181 {
00182
00183
00184
00185 OCILib.key_map = OCI_HashCreate(OCI_HASH_DEFAULT_SIZE, OCI_HASH_POINTER);
00186
00187 }
00188
00189 res = (OCILib.key_map != NULL);
00190
00191
00192
00193 if (res == TRUE)
00194 {
00195 key = OCI_ThreadKeyCreateInternal(destfunc);
00196
00197
00198
00199 if (key != NULL)
00200 res = OCI_HashAddPointer(OCILib.key_map, name, key);
00201 else
00202 res = FALSE;
00203 }
00204
00205
00206
00207 if (res == FALSE)
00208 OCI_ThreadKeyFree(key);
00209
00210 OCI_RESULT(res);
00211
00212 return res;
00213 }
00214
00215
00216
00217
00218
00219 boolean OCI_API OCI_ThreadKeySetValue(const mtext *name, void *value)
00220 {
00221 boolean res = TRUE;
00222 OCI_ThreadKey *key = NULL;
00223
00224 OCI_CHECK_PTR(OCI_IPC_STRING, name, FALSE);
00225
00226 key = (OCI_ThreadKey *) OCI_HashGetPointer(OCILib.key_map, name);
00227
00228 res = OCI_ThreadKeySet(key, value);
00229
00230 OCI_RESULT(res);
00231
00232 return TRUE;
00233 }
00234
00235
00236
00237
00238
00239 void * OCI_API OCI_ThreadKeyGetValue(const mtext *name)
00240 {
00241 boolean res = TRUE;
00242 void * value = NULL;
00243 OCI_ThreadKey* key = NULL;
00244
00245 OCI_CHECK_PTR(OCI_IPC_STRING, name, FALSE);
00246
00247 key = (OCI_ThreadKey *) OCI_HashGetPointer(OCILib.key_map, name);
00248
00249 res = OCI_ThreadKeyGet(key, &value);
00250
00251 OCI_RESULT(res);
00252
00253 return value;
00254 }