예제 #1
0
파일: dict_cursor.c 프로젝트: R7R8/simgrid
/**
 * @brief Create the cursor if it does not exists. Rewind it in any case.
 *
 * @param      dict   on what to let the cursor iterate
 * @param[out] cursor dest address
 */
inline void xbt_dict_cursor_first(const xbt_dict_t dict, xbt_dict_cursor_t * cursor)
{
  XBT_CDEBUG(xbt_dict_cursor, "xbt_dict_cursor_first");
  if (!*cursor) {
    XBT_CDEBUG(xbt_dict_cursor, "Create the cursor on first use");
    *cursor = xbt_dict_cursor_new(dict);
  } else {
    xbt_dict_cursor_rewind(*cursor);
  }
  if (dict != NULL && (*cursor)->current == NULL) {
    xbt_dict_cursor_step(*cursor);      /* find the first element */
  }
}
예제 #2
0
파일: dynar.c 프로젝트: R7R8/simgrid
/** @brief Mark the last dynar's element as unused and return a pointer to it.
 *
 * You can then use regular affectation to set its value instead of relying on the slow memcpy. This is what
 * xbt_dynar_pop_as() does.
 */
inline void *xbt_dynar_pop_ptr(xbt_dynar_t const dynar)
{
  _check_populated_dynar(dynar);
  XBT_CDEBUG(xbt_dyn, "Pop %p", (void *) dynar);
  dynar->used--;
  return _xbt_dynar_elm(dynar, dynar->used);
}
예제 #3
0
파일: dynar.c 프로젝트: FlorianPO/simgrid
/** @brief Get and remove the last element of the dynar */
XBT_INLINE void xbt_dynar_pop(xbt_dynar_t const dynar, void *const dst)
{

  /* sanity checks done by remove_at */
  XBT_CDEBUG(xbt_dyn, "Pop %p", (void *) dynar);
  xbt_dynar_remove_at(dynar, dynar->used - 1, dst);
}
예제 #4
0
/*********
 * Model *
 *********/
void CpuModel::updateActionsStateLazy(double now, double /*delta*/)
{
  CpuAction *action;
  while ((xbt_heap_size(getActionHeap()) > 0)
         && (double_equals(xbt_heap_maxkey(getActionHeap()), now, sg_surf_precision))) {
    action = static_cast<CpuAction*>(xbt_heap_pop(getActionHeap()));
    XBT_CDEBUG(surf_kernel, "Something happened to action %p", action);
    if (TRACE_is_enabled()) {
      Cpu *cpu = static_cast<Cpu*>(lmm_constraint_id(lmm_get_cnst_from_var(getMaxminSystem(), action->getVariable(), 0)));
      TRACE_surf_host_set_utilization(cpu->getName(), action->getCategory(),
                                      lmm_variable_getvalue(action->getVariable()),
                                      action->getLastUpdate(),
                                      now - action->getLastUpdate());
    }

    action->finish();
    XBT_CDEBUG(surf_kernel, "Action %p finished", action);

    /* set the remains to 0 due to precision problems when updating the remaining amount */
    action->setRemains(0);
    action->setState(SURF_ACTION_DONE);
    action->heapRemove(getActionHeap()); //FIXME: strange call since action was already popped
  }
  if (TRACE_is_enabled()) {
    //defining the last timestamp that we can safely dump to trace file
    //without losing the event ascending order (considering all CPU's)
    double smaller = -1;
    ActionList *actionSet = getRunningActionSet();
    for(ActionList::iterator it(actionSet->begin()), itend(actionSet->end())
       ; it != itend ; ++it) {
      action = static_cast<CpuAction*>(&*it);
        if (smaller < 0) {
          smaller = action->getLastUpdate();
          continue;
        }
        if (action->getLastUpdate() < smaller) {
          smaller = action->getLastUpdate();
        }
    }
    if (smaller > 0) {
      TRACE_last_timestamp_to_dump = smaller;
    }
  }
  return;
}
예제 #5
0
파일: log_usage.c 프로젝트: R7R8/simgrid
static void dolog(const char *settings)
{
  XBT_INFO("Test with the settings '%s'", settings);
  xbt_log_control_set(settings);
  XBT_DEBUG("val=%d", 1);
  XBT_WARN("val=%d", 2);
  XBT_CDEBUG(top, "val=%d%s", 3, "!");
  XBT_CRITICAL("false alarm%s%s%s%s%s%s", "", "", "", "", "", "!");
}
예제 #6
0
파일: dynar.c 프로젝트: R7R8/simgrid
/** @brief Frees the content and set the size to 0
 *
 * \param dynar who to squeeze
 */
inline void xbt_dynar_reset(xbt_dynar_t const dynar)
{
  _sanity_check_dynar(dynar);

  XBT_CDEBUG(xbt_dyn, "Reset the dynar %p", (void *) dynar);
  if (dynar->free_f) {
    xbt_dynar_map(dynar, dynar->free_f);
  }
  dynar->used = 0;
}
예제 #7
0
파일: dict.c 프로젝트: apargupta/simgrid
/**
 * \brief Add data to the dict (arbitrary key)
 * \param dict the container
 * \param key the key to set the new data
 * \param key_len the size of the \a key
 * \param data the data to add in the dict
 * \param free_ctn function to call with (\a data as argument) when
 *        \a data is removed from the dictionary
 *
 * Set the \a data in the structure under the \a key, which can be any kind
 * of data, as long as its length is provided in \a key_len.
 */
XBT_INLINE void xbt_dict_set_ext(xbt_dict_t dict,
                                 const char *key, int key_len,
                                 void *data, void_f_pvoid_t free_ctn)
{

    unsigned int hash_code = xbt_str_hash_ext(key, key_len);

    xbt_dictelm_t current, previous = NULL;
    xbt_assert(dict);

    XBT_CDEBUG(xbt_dict,
               "ADD %.*s hash = %u, size = %d, & = %u", key_len, key, hash_code,
               dict->table_size, hash_code & dict->table_size);
    current = dict->table[hash_code & dict->table_size];
    while (current != NULL &&
            (hash_code != current->hash_code || key_len != current->key_len
             || memcmp(key, current->key, key_len))) {
        previous = current;
        current = current->next;
    }

    if (current == NULL) {
        /* this key doesn't exist yet */
        current = xbt_dictelm_new(dict, key, key_len, hash_code, data, free_ctn);
        dict->count++;
        if (previous == NULL) {
            dict->table[hash_code & dict->table_size] = current;
            dict->fill++;
            if ((dict->fill * 100) / (dict->table_size + 1) > MAX_FILL_PERCENT)
                xbt_dict_rehash(dict);
        } else {
            previous->next = current;
        }
    } else {
        XBT_CDEBUG(xbt_dict, "Replace %.*s by %.*s under key %.*s",
                   key_len, (char *) current->content,
                   key_len, (char *) data, key_len, (char *) key);
        /* there is already an element with the same key: overwrite it */
        xbt_dictelm_set_data(dict, current, data, free_ctn);
    }
}
예제 #8
0
/** @brief Reinitialize the cursor. Mandatory after removal or add in dict. */
XBT_INLINE void xbt_dict_cursor_rewind(xbt_dict_cursor_t cursor)
{
  XBT_CDEBUG(xbt_dict_cursor, "xbt_dict_cursor_rewind");
  xbt_assert(cursor);

  cursor->line = 0;
  if (cursor->dict != NULL) {
    cursor->current = cursor->dict->table[0];
  } else {
    cursor->current = NULL;
  }
}
예제 #9
0
파일: dict_cursor.c 프로젝트: R7R8/simgrid
/** \brief Move to the next element. */
inline void xbt_dict_cursor_step(xbt_dict_cursor_t cursor)
{
  xbt_dictelm_t current;
  int line;

  XBT_CDEBUG(xbt_dict_cursor, "xbt_dict_cursor_step");
  xbt_assert(cursor);

  current = cursor->current;
  line = cursor->line;

  if (cursor->dict != NULL) {
    if (current != NULL) {
      XBT_CDEBUG(xbt_dict_cursor, "current is not null, take the next element");
      current = current->next;
      XBT_CDEBUG(xbt_dict_cursor, "next element: %p", current);
    }

    while (current == NULL && ++line <= cursor->dict->table_size) {
      XBT_CDEBUG(xbt_dict_cursor, "current is NULL, take the next line");
      current = cursor->dict->table[line];
      XBT_CDEBUG(xbt_dict_cursor, "element in the next line: %p", current);
    }
    XBT_CDEBUG(xbt_dict_cursor, "search finished, current = %p, line = %d", current, line);

    cursor->current = current;
    cursor->line = line;
  }
}
예제 #10
0
파일: dict_cursor.c 프로젝트: R7R8/simgrid
/**
 * @brief Get current data, or free the cursor if there is no data left
 *
 * @returns true if it's ok, false if there is no more data
 */
inline int xbt_dict_cursor_get_or_free(xbt_dict_cursor_t * cursor, char **key, void **data)
{
  xbt_dictelm_t current;

  XBT_CDEBUG(xbt_dict_cursor, "xbt_dict_get_or_free");

  if (!cursor || !(*cursor))
    return FALSE;

  current = (*cursor)->current;
  if (current == NULL) {        /* no data left */
    xbt_dict_cursor_free(cursor);
    return FALSE;
  }

  *key = current->key;
  *data = current->content;
  return TRUE;
}