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_List * OCI_ListCreate
00046 (
00047 int type
00048 )
00049 {
00050 OCI_List *list = NULL;
00051
00052
00053
00054 list = (OCI_List *) OCI_MemAlloc(OCI_IPC_LIST, sizeof(*list), (size_t) 1, TRUE);
00055
00056
00057
00058 if (list != NULL)
00059 {
00060 list->type = type;
00061
00062 if (OCI_LIB_THREADED)
00063 {
00064 list->mutex = OCI_MutexCreateInternal();
00065
00066 if (list->mutex == NULL)
00067 OCI_FREE(list);
00068 }
00069 }
00070
00071 return list;
00072 }
00073
00074
00075
00076
00077
00078 boolean OCI_ListFree
00079 (
00080 OCI_List *list
00081 )
00082 {
00083 boolean res = TRUE;
00084
00085 OCI_CHECK(list == NULL, FALSE);
00086
00087 OCI_ListClear(list);
00088
00089 if (list->mutex != NULL)
00090 res = OCI_MutexFree(list->mutex);
00091
00092 OCI_FREE(list);
00093
00094 return res;
00095 }
00096
00097
00098
00099
00100
00101 OCI_Item * OCI_ListCreateItem
00102 (
00103 int type,
00104 int size
00105 )
00106 {
00107 OCI_Item *item = NULL;
00108
00109
00110
00111 item = (OCI_Item *) OCI_MemAlloc(OCI_IPC_LIST_ITEM, sizeof(*item),
00112 (size_t) 1, TRUE);
00113
00114 if (item != NULL)
00115 {
00116
00117
00118 item->data = (void *) OCI_MemAlloc(type, (size_t) size, (size_t) 1, TRUE);
00119
00120 if (item->data == NULL)
00121 OCI_FREE(item);
00122 }
00123
00124 return item;
00125 }
00126
00127
00128
00129
00130
00131 OCI_Item * OCI_ListAppend
00132 (
00133 OCI_List *list,
00134 int size
00135 )
00136 {
00137 OCI_Item *item = NULL;
00138 OCI_Item *temp = NULL;
00139
00140 OCI_CHECK(list == NULL, NULL);
00141
00142 item = OCI_ListCreateItem(list->type, size);
00143
00144 OCI_CHECK(item == NULL, FALSE);
00145
00146 if (list->mutex != NULL)
00147 OCI_MutexAcquire(list->mutex);
00148
00149 temp = list->head;
00150
00151 while (temp != NULL && temp->next)
00152 {
00153 temp = temp->next;
00154 }
00155
00156 if (temp != NULL)
00157 temp->next = item;
00158 else
00159 list->head = item;
00160
00161 list->count++;
00162
00163 if (list->mutex != NULL)
00164 OCI_MutexRelease(list->mutex);
00165
00166 return item;
00167 }
00168
00169
00170
00171
00172
00173 boolean OCI_ListClear
00174 (
00175 OCI_List *list
00176 )
00177 {
00178 OCI_Item *item = NULL;
00179 OCI_Item *temp = NULL;
00180
00181 OCI_CHECK(list == NULL, FALSE);
00182
00183 if (list->mutex != NULL)
00184 OCI_MutexAcquire(list->mutex);
00185
00186
00187
00188 item = list->head;
00189
00190 while (item != NULL)
00191 {
00192 temp = item;
00193 item = item->next;
00194
00195
00196
00197 OCI_FREE(temp->data);
00198 OCI_FREE(temp);
00199 }
00200
00201 list->head = NULL;
00202 list->count = 0;
00203
00204 if (list->mutex != NULL)
00205 OCI_MutexRelease(list->mutex);
00206
00207 return TRUE;
00208 }
00209
00210
00211
00212
00213
00214 boolean OCI_ListForEach
00215 (
00216 OCI_List *list,
00217 POCI_LIST_FOR_EACH proc
00218 )
00219 {
00220 OCI_Item *item = NULL;
00221
00222 OCI_CHECK(list == NULL, FALSE);
00223
00224 if (list->mutex != NULL)
00225 OCI_MutexAcquire(list->mutex);
00226
00227 item = list->head;
00228
00229
00230
00231 while (item != NULL)
00232 {
00233 proc(item->data);
00234 item = item->next;
00235 }
00236
00237 if (list->mutex != NULL)
00238 OCI_MutexRelease(list->mutex);
00239
00240 return TRUE;
00241 }
00242
00243
00244
00245
00246
00247 boolean OCI_ListRemove
00248 (
00249 OCI_List *list,
00250 void *data
00251 )
00252 {
00253 OCI_Item *item = NULL;
00254 OCI_Item *temp = NULL;
00255
00256 OCI_CHECK(list == NULL, FALSE);
00257 OCI_CHECK(data == NULL, FALSE);
00258
00259 if (list->mutex != NULL)
00260 OCI_MutexAcquire(list->mutex);
00261
00262 item = list->head;
00263
00264 while (item != NULL)
00265 {
00266 if (item->data == data)
00267 {
00268 if (temp) temp->next = item->next;
00269
00270
00271
00272
00273 if (item == list->head) list->head = item->next;
00274
00275 OCI_FREE(item);
00276
00277 break;
00278 }
00279
00280 temp = item;
00281 item = item->next;
00282 }
00283
00284 list->count--;
00285
00286 if (list->mutex != NULL)
00287 OCI_MutexRelease(list->mutex);
00288
00289 return TRUE;
00290 }