SimGrid: Fifo perl-like functions

SimGrid 3.10 Versatile Simulation of Distributed Systems

- Home page
- Online documentation
- Dev's Corner

All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Functions
Fifo perl-like functions
Fifo: generic workqueue

## Functions
xbt_fifo_item_t | xbt_fifo_push (xbt_fifo_t, void *)
void * | xbt_fifo_pop (xbt_fifo_t)
xbt_fifo_item_t | xbt_fifo_unshift (xbt_fifo_t, void *)
void * | xbt_fifo_shift (xbt_fifo_t)
int | xbt_fifo_size (xbt_fifo_t)
int | xbt_fifo_is_in (xbt_fifo_t, void *)
xbt_fifo_item_t | xbt_fifo_search_item (xbt_fifo_t f, int_f_pvoid_pvoid_t cmp_fun, void *closure)
| Search the given element in the fifo using a comparison function.

## Detailed Description

## Function Documentation

xbt_fifo_item_t xbt_fifo_push | ( | xbt_fifo_t | l,
|  | void * | t
| ) |  |

Push

Parameters

  l | list
  t | element

Returns
  the bucket that was just added

Add an object at the tail of the list

void* xbt_fifo_pop | ( | xbt_fifo_t | l | ) |

Pop

Parameters

  l | list

Returns
  the object stored at the tail of the list.

Removes and returns the object stored at the tail of the list. Returns NULL if the list is empty.

xbt_fifo_item_t xbt_fifo_unshift | ( | xbt_fifo_t | l,
|  | void * | t
| ) |  |

Parameters

  l | list
  t | element

Returns
  the bucket that was just added

Add an object at the head of the list

void* xbt_fifo_shift | ( | xbt_fifo_t | l | ) |

Shift

Parameters

  l | list

Returns
  the object stored at the head of the list.

Removes and returns the object stored at the head of the list. Returns NULL if the list is empty.

int xbt_fifo_size | ( | xbt_fifo_t | f | ) |

Parameters

  f | a list

Returns
  the number of buckets in f.

int xbt_fifo_is_in | ( | xbt_fifo_t | f,
|  | void * | content
| ) |  |

Parameters

  f | a list
  content | an object

Returns
  1 if content is in f.

xbt_fifo_item_t xbt_fifo_search_item | ( | xbt_fifo_t | f,
|  | int_f_pvoid_pvoid_t | cmp_fun,
|  | void * | closure
| ) |  |

Search the given element in the fifo using a comparison function.

This function allows to search an item with a user provided function instead of the pointer comparison used elsewhere in this module. Assume for example that you have a fifo of strings. You cannot use xbt_fifo_remove() to remove, say, "TOTO" from it because internally, xbt_fifo_remove() will do something like "if (item->content == "toto"), then remove it". And the pointer to the item content and the pointer to "toto" will never match. As a solution, the current function provides a way to search elements that are semanticaly equivalent instead of only syntaxically. So, removing "Toto" from a fifo can be achieved this way:

    int my_comparison_function(void *searched, void *seen) {
      return !strcmp(searched, seen);
    }

      xbt_fifo_remove_item(fifo,
                           xbt_fifo_search_item(fifo, my_comparison_function, "Toto"));

Parameters

  f | a fifo list
  cmp_fun | the comparison function. Prototype: void *a,void *b -> int. Semantic: returns true iff a=b
  closure | the element to search. It will be provided as first argument to each call of cmp_fun

Returns
  the first item matching the comparison function, or NULL if no such item exists