Ejemplo n.º 1
0
int main(void) {
  uint16_t   i;
  message_t *m;

  /*** do one-time pool init for app */
  init_mpool();

  /*** use the pool */
  for (i = 0; i < 1000; i++) {
    /* grab a message from the pool
     *   linked list: 31 clocks, <16 us on tmote
     *   array impl:  40 clocks, 10 us on tmote
     */
    if ((m = get_from_pool()) == NULL)
      return FAIL;

    /* ...use it... */

    /* put it back when done
     *   linked list: 26 clocks, <7 us on tmote
     *   array impl:  44 clocks, 11 us on tmote
     */
    return_to_pool(m);
  }

  /*** linked list is almost 50% faster 
   ***
   *** this is largely due to the s-l-o-w multiply-by-46
   ***
   ***/

  return SUCCESS;
}
Ejemplo n.º 2
0
/* called with note_lock held */
uint do_hash(struct dentry * dentry, struct vfsmount * vfsmnt, struct dentry * root, struct vfsmount * rootmnt)
{
	struct qstr * dname;
	uint value = -1;
	uint firsthash;
	uint incr;
	uint parent = 0;
	struct op_hash_index *entry;

	if (!wind_dentries(dentry, vfsmnt, root, rootmnt))
		goto out;

	/* unwind and hash */

	while ((dname = pop_dname())) {
		/* if N is prime, value in [0-N[ and incr = max(1, value) then
		 * iteration: value = (value + incr) % N covers the range [0-N[
		 * in N iterations */
		incr = firsthash = value = name_hash(dname->name, dname->len, parent);
		if (incr == 0)
			incr = 1;

	retry:
		entry = &hash_map[value];
		/* existing entry ? */
		if (streq(get_from_pool(entry->name), dname->name)
			&& entry->parent == parent)
			goto next;

		/* new entry ? */
		if (entry->parent == -1) {
			if (add_hash_entry(entry, parent, dname->name, dname->len))
				goto fullpool;
			goto next;
		}

		/* nope, find another place in the table */
		value = (value + incr) % OP_HASH_MAP_NR;

		if (value == firsthash)
			goto fulltable;

		goto retry;
	next:
		parent = value;
	}

out:
	op_dname_top = 0;
	return value;
fullpool:
	printk(KERN_ERR "oprofile: string pool exhausted.\n");
	value = -1;
	goto out;
fulltable:
	printk(KERN_ERR "oprofile: component hash table full :(\n");
	value = -1;
	goto out;
}
Ejemplo n.º 3
0
auto_ptr<EngineCloned> Engine::clone()
{
    if (conn_.get())
        return auto_ptr<EngineCloned>(new EngineCloned(
                    mode_, conn_.get(), dialect_, logger_.get()));
    SqlConnection *conn = get_from_pool();
    return auto_ptr<EngineCloned>(new EngineCloned(
                mode_, conn, dialect_, logger_.get(), pool_.get()));
}
Ejemplo n.º 4
0
SqlConnection *Engine::get_conn()
{
    if (conn_.get())
        return conn_.get();
    if (conn_ptr_)
        return conn_ptr_;
    conn_ptr_ = get_from_pool();
    return conn_ptr_;
}