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