-#include <units.h>
-#include <unit.h>
-#include <fstreams.h>
-
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);
-
-units_t
-units_new(runner_t runner, fstreams_t fstreams)
-{
- register fstream_t fstream;
-
- units_t units = xbt_new0(s_units_t, 1);
-
- if(!(units->items = vector_new(fstreams_get_size(fstreams), unit_free)))
- {
- free(units);
- return NULL;
- }
-
-
- vector_rewind(fstreams->items);
-
- while((fstream = vector_get(fstreams->items)))
- {
- if(vector_push_back(units->items, unit_new(runner, NULL, NULL, fstream)))
- {
- vector_free(&(units->items));
- free(units);
- return NULL;
- }
-
- vector_move_next(fstreams->items);
- }
-
- return units;
-}
-
-
-int
-units_is_empty(units_t units)
-{
- if(!units)
- {
- errno = EINVAL;
- return 0;
- }
-
- return vector_is_empty(units->items);
-}
-
-int
-units_get_size(units_t units)
-{
- if(!units)
- {
- errno = EINVAL;
- return -1;
- }
-
- return vector_get_size(units->items);
-}
-
-
-int
-units_run_all(units_t units, xbt_os_mutex_t mutex)
-{
- register unit_t unit;
-
- if(!units)
- return EINVAL;
-
- if(vector_is_empty(units->items))
- return EAGAIN;
-
- /* move the cursor at the begining of the vector */
- vector_rewind(units->items);
-
- /* run all the units */
- while((unit = vector_get(units->items)))
- {
- unit_run(unit, mutex);
- vector_move_next(units->items);
-
- }
-
- return 0;
-
-}
-
-int
-units_join_all(units_t units)
-{
- register unit_t unit;
-
- if(!units)
- return EINVAL;
-
- if(vector_is_empty(units->items))
- return EAGAIN;
-
- /* move the cursor at the begining of the vector */
- vector_rewind(units->items);
-
- /* run all the units */
- while((unit = vector_get(units->items)))
- {
- if(unit->thread)
- xbt_os_thread_join(unit->thread, NULL);
-
- vector_move_next(units->items);
- }
-
- return 0;
-}
-
-int
-units_interrupt_all(units_t units)
-{
- register unit_t unit;
-
- if(!units)
- return EINVAL;
-
- if(vector_is_empty(units->items))
- return EAGAIN;
-
- /* move the cursor at the begining of the vector */
- vector_rewind(units->items);
-
- /* run all the units */
- while((unit = vector_get(units->items)))
- {
- if(!(unit->successeded) && !(unit->interrupted))
- unit_interrupt(unit);
-
- vector_move_next(units->items);
- }
-
- return 0;
-}
-
-int
-units_verbose(units_t units)
-{
- register unit_t unit;
-
- if(!units)
- return EINVAL;
-
- if(vector_is_empty(units->items))
- return EAGAIN;
-
- /* move the cursor at the begining of the vector */
- vector_rewind(units->items);
-
- /* run all the units */
- while((unit = vector_get(units->items)))
- {
- unit_verbose(unit);
- vector_move_next(units->items);
- }
-
- return 0;
-
-}
-
-int
-units_reset_all(units_t units)
-{
- register unit_t unit;
-
- if(!units)
- return EINVAL;
-
- if(vector_is_empty(units->items))
- return EAGAIN;
-
- /* move the cursor at the begining of the vector */
- vector_rewind(units->items);
-
- /* run all the units */
- while((unit = vector_get(units->items)))
- {
- unit_reset(unit);
- vector_move_next(units->items);
- }
-
- return 0;
-}
-
-int
-units_free(void** unitsptr)
-{
- int rv;
-
- if(!(*unitsptr))
- return EINVAL;
-
- if((rv = vector_free(&((*((units_t*)unitsptr))->items))))
- return rv;
-
- free(*unitsptr);
- *unitsptr = NULL;
-
- return 0;
-}
-
+#include <units.h>\r
+#include <unit.h>\r
+#include <fstreams.h>\r
+\r
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(tesh);\r
+\r
+units_t\r
+units_new(runner_t runner, fstreams_t fstreams)\r
+{\r
+ fstream_t fstream;\r
+ unsigned int i;\r
+ unit_t unit;\r
+ \r
+ units_t units = xbt_new0(s_units_t, 1);\r
+\r
+ units->items = xbt_dynar_new(sizeof(unit_t), (void_f_pvoid_t)unit_free);\r
+\r
+ xbt_dynar_foreach(fstreams->items, i, fstream)\r
+ {\r
+ unit = unit_new(runner, NULL, NULL, fstream);\r
+ xbt_dynar_push(units->items, &unit);\r
+ }\r
+ \r
+ return units;\r
+}\r
+\r
+\r
+int\r
+units_is_empty(units_t units)\r
+{\r
+ if(!units)\r
+ {\r
+ errno = EINVAL;\r
+ return 0;\r
+ }\r
+ \r
+ return (0 == xbt_dynar_length(units->items));\r
+}\r
+\r
+int\r
+units_get_size(units_t units)\r
+{\r
+ if(!units)\r
+ {\r
+ errno = EINVAL;\r
+ return -1;\r
+ }\r
+\r
+ return xbt_dynar_length(units->items);\r
+}\r
+\r
+\r
+int\r
+units_run_all(units_t units, xbt_os_mutex_t mutex)\r
+{\r
+ unit_t unit;\r
+ unsigned int i;\r
+ \r
+ if(!units)\r
+ return EINVAL;\r
+ \r
+ if(!xbt_dynar_length(units->items))\r
+ return EAGAIN;\r
+\r
+ xbt_dynar_foreach(units->items, i, unit)\r
+ {\r
+ unit_run(unit, mutex);\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+int\r
+units_join_all(units_t units)\r
+{\r
+ unit_t unit;\r
+ unsigned int i;\r
+ \r
+ if(!units)\r
+ return EINVAL;\r
+ \r
+ if(!xbt_dynar_length(units->items))\r
+ return EAGAIN;\r
+\r
+ xbt_dynar_foreach(units->items, i, unit)\r
+ {\r
+ if(unit->thread)\r
+ xbt_os_thread_join(unit->thread, NULL);\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+int\r
+units_interrupt_all(units_t units)\r
+{\r
+ unit_t unit;\r
+ unsigned int i;\r
+ \r
+ if(!units)\r
+ return EINVAL;\r
+\r
+ if(!xbt_dynar_length(units->items))\r
+ return EAGAIN;\r
+\r
+ xbt_dynar_foreach(units->items, i, unit)\r
+ {\r
+ if(!(unit->successeded) && !(unit->interrupted))\r
+ unit_interrupt(unit);\r
+ else\r
+ {\r
+ if(!unit->released && unit->sem)\r
+ {\r
+ unit->released = 1;\r
+ xbt_os_sem_release(unit->sem);\r
+ }\r
+ }\r
+ \r
+ }\r
+ \r
+ return 0;\r
+}\r
+\r
+int\r
+units_summuarize(units_t units)\r
+{\r
+ unit_t unit;\r
+ unsigned int i;\r
+\r
+ if(!units)\r
+ return EINVAL;\r
+\r
+ if(!xbt_dynar_length(units->items))\r
+ return EAGAIN;\r
+\r
+ xbt_dynar_foreach(units->items, i, unit)\r
+ {\r
+ unit_summuarize(unit);\r
+ }\r
+ \r
+ return 0;\r
+ \r
+}\r
+\r
+int\r
+units_reset_all(units_t units)\r
+{\r
+ unit_t unit;\r
+ unsigned int i;\r
+ \r
+ if(!units)\r
+ return EINVAL;\r
+ \r
+ if(!xbt_dynar_length(units->items))\r
+ return EAGAIN;\r
+\r
+ xbt_dynar_foreach(units->items, i, unit)\r
+ {\r
+ unit_reset(unit);\r
+ }\r
+ return 0;\r
+}\r
+\r
+int\r
+units_free(void** unitsptr)\r
+{\r
+ if(!(*unitsptr))\r
+ return EINVAL;\r
+ \r
+ if((*((units_t*)unitsptr))->items)\r
+ xbt_dynar_free(&((*((units_t*)unitsptr))->items));\r
+ \r
+ free(*unitsptr);\r
+ *unitsptr = NULL;\r
+ \r
+ return 0;\r
+}\r
+\r