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 void OCI_ThreadProc(dvoid *arg)
00046 {
00047 OCI_Thread *thread = (OCI_Thread *) arg;
00048
00049 if (thread != NULL)
00050 thread->proc(thread, thread->arg);
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 OCI_Thread * OCI_API OCI_ThreadCreate(void)
00062 {
00063 OCI_Thread *thread = NULL;
00064 boolean res = TRUE;
00065
00066 OCI_CHECK_INITIALIZED(NULL);
00067
00068 OCI_CHECK_THREAD_ENABLED(FALSE);
00069
00070
00071
00072 thread = (OCI_Thread *) OCI_MemAlloc(OCI_IPC_THREAD, sizeof(*thread), 1, TRUE);
00073
00074 if (thread != NULL)
00075 {
00076
00077
00078 res = (OCI_SUCCESS == OCI_HandleAlloc(OCILib.env,
00079 (dvoid **) (void *) &thread->err,
00080 OCI_HTYPE_ERROR, 0,
00081 (dvoid **) NULL));
00082
00083
00084
00085 OCI_CALL3
00086 (
00087 res, thread->err,
00088
00089 OCIThreadHndInit(OCILib.env, thread->err, &thread->handle)
00090 )
00091
00092
00093
00094 OCI_CALL3
00095 (
00096 res, thread->err,
00097
00098 OCIThreadIdInit(OCILib.env, thread->err, &thread->id)
00099 )
00100 }
00101 else
00102 res = FALSE;
00103
00104 if (res == FALSE)
00105 {
00106 OCI_ThreadFree(thread);
00107 thread = NULL;
00108 }
00109
00110 OCI_RESULT(res);
00111
00112 return thread;
00113 }
00114
00115
00116
00117
00118
00119 boolean OCI_API OCI_ThreadFree(OCI_Thread *thread)
00120 {
00121 boolean res = TRUE;
00122
00123 OCI_CHECK_THREAD_ENABLED(FALSE);
00124
00125 OCI_CHECK_PTR(OCI_IPC_THREAD, thread, FALSE);
00126
00127
00128
00129 if (thread->handle != NULL)
00130 {
00131 OCI_CALL0
00132 (
00133 res, thread->err,
00134
00135 OCIThreadClose(OCILib.env, thread->err, thread->handle)
00136 )
00137
00138 OCI_CALL0
00139 (
00140 res, thread->err,
00141
00142 OCIThreadHndDestroy(OCILib.env, thread->err, &thread->handle)
00143 )
00144 }
00145
00146
00147
00148 if (thread->id != NULL)
00149 {
00150 OCI_CALL0
00151 (
00152 res, thread->err,
00153
00154 OCIThreadIdDestroy(OCILib.env, thread->err, &thread->id)
00155 )
00156 }
00157
00158
00159
00160 if (thread->err != NULL)
00161 {
00162 OCI_HandleFree(thread->err, OCI_HTYPE_ERROR);
00163 }
00164
00165
00166
00167 OCI_FREE(thread);
00168
00169 OCI_RESULT(res);
00170
00171 return res;
00172 }
00173
00174
00175
00176
00177
00178 boolean OCI_API OCI_ThreadRun(OCI_Thread *thread, POCI_THREAD proc, void *arg)
00179 {
00180 boolean res = TRUE;
00181
00182 OCI_CHECK_THREAD_ENABLED(FALSE);
00183
00184 OCI_CHECK_PTR(OCI_IPC_THREAD, thread, FALSE);
00185 OCI_CHECK_PTR(OCI_IPC_PROC, proc, FALSE);
00186
00187 thread->proc = proc;
00188 thread->arg = arg;
00189
00190 OCI_CALL3
00191 (
00192 res, thread->err,
00193
00194 OCIThreadCreate(OCILib.env, thread->err, OCI_ThreadProc,
00195 thread, thread->id, thread->handle)
00196 )
00197
00198 OCI_RESULT(res);
00199
00200 return res;
00201 }
00202
00203
00204
00205
00206
00207 boolean OCI_API OCI_ThreadJoin(OCI_Thread *thread)
00208 {
00209 boolean res = TRUE;
00210
00211 OCI_CHECK_THREAD_ENABLED(FALSE);
00212
00213 OCI_CHECK_PTR(OCI_IPC_THREAD, thread, FALSE);
00214
00215 OCI_CALL3
00216 (
00217 res, thread->err,
00218
00219 OCIThreadJoin(OCILib.env, thread->err, thread->handle)
00220 )
00221
00222 OCI_RESULT(res);
00223
00224 return res;
00225 }