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