280 |
int |
int |
281 |
list_do (list_t list, list_action_t * action, void *cbdata) |
list_do (list_t list, list_action_t * action, void *cbdata) |
282 |
{ |
{ |
283 |
struct list_data *current; |
iterator_t itr; |
284 |
int status = 0; |
int status = 0; |
285 |
|
|
286 |
if (list == NULL || action == NULL) |
if (list == NULL || action == NULL) |
287 |
return EINVAL; |
return EINVAL; |
288 |
|
status = iterator_create(&itr, list); |
289 |
|
if (status) |
290 |
|
return status; |
291 |
monitor_rdlock (list->monitor); |
monitor_rdlock (list->monitor); |
292 |
for (current = list->head.next; current != &(list->head); |
for (iterator_first (itr); !iterator_is_done (itr); iterator_next (itr)) |
|
current = current->next) |
|
293 |
{ |
{ |
294 |
|
void *item; |
295 |
|
iterator_current (itr, &item); |
296 |
if ((status = action (current->item, cbdata))) |
if ((status = action (current->item, cbdata))) |
297 |
break; |
break; |
298 |
} |
} |
299 |
monitor_unlock (list->monitor); |
monitor_unlock (list->monitor); |
300 |
|
iterator_destroy (&itr); |
301 |
return status; |
return status; |
302 |
} |
} |
303 |
|
|
314 |
{ |
{ |
315 |
size_t total = 0; |
size_t total = 0; |
316 |
|
|
317 |
if (list != NULL) |
if (!list) |
318 |
|
return EINVAL; |
319 |
|
|
320 |
|
total = (count < list->count) ? count : list->count; |
321 |
|
|
322 |
|
if (array) |
323 |
{ |
{ |
324 |
size_t i; |
size_t i; |
325 |
struct list_data *current; |
struct list_data *current; |
326 |
total = (count < list->count) ? count : list->count; |
|
327 |
for (i = 0, current = list->head.next; i < total && current != &(list->head); current = current->next) |
for (i = 0, current = list->head.next; |
328 |
{ |
i < total && current != &(list->head); current = current->next) |
329 |
if (array) |
array[i] = current->item; |
|
array[i] = current->item; |
|
|
} |
|
330 |
} |
} |
331 |
if (pcount) |
if (pcount) |
332 |
*pcount = total; |
*pcount = total; |