mtimer_t *_mtimer_ustart( int32_t usec, 
                          void    (*callback)(void *user),
                          void    *user)
{
    mtimer_t *n,*walk,*last;

    n = alloc_t(mtimer_t);
    n->expiration.tv_usec = g_tnow.tv_usec+usec;
    n->expiration.tv_sec = g_tnow.tv_sec;
    n->callback = callback;
    n->user = user;
    while (n->expiration.tv_usec > 1000000) {
        n->expiration.tv_usec -= 1000000;
        n->expiration.tv_sec++;
    }
    last = NULL;
    for (walk = timers; walk; walk = walk->next)
        if (walk->expiration.tv_sec > n->expiration.tv_sec ||
          (walk->expiration.tv_sec == n->expiration.tv_sec &&
          walk->expiration.tv_usec > n->expiration.tv_usec)) break;
        else last = walk;
    if (walk) 
        Q_INSERT_BEFORE(timers,n,walk);
    else 
        Q_INSERT_AFTER(timers,n,last);
    return n;
}
示例#2
0
void register_sleep_event(thread_t *me, event_t *e)
{
	sched_lock();
	thread_t *t;
	Q_SEARCH(t, &state.sleep_queue, q_link,
	         time_lt(e->u.wakeup, t->sleep_event.u.wakeup));
	if (t) {
		Q_INSERT_BEFORE(&state.sleep_queue, t, me, q_link);
	} else {
		Q_INSERT_TAIL(&state.sleep_queue, me, q_link);
	}
	sched_unlock();
}
示例#3
0
AsnInt setNetPrefix(VarBind *varbind, Variable *var)
{
  int cmp;
  NetPrefixNode *prefix, *newPrefix;
  AsnOid *varBindName;

  diag(COMPONENT,DIAG_DEBUG,"setNetPrefix");
  varBindName = &varbind->name;
  if(varbind->value->choiceId != OBJECTSYNTAX_SIMPLE ||
     varbind->value->a.simple->choiceId != SIMPLESYNTAX_NUMBER ||
     (varbind->value->a.simple->a.number != VALID && 
      varbind->value->a.simple->a.number != INVALID))
    return BADVALUE;
      
  if(AsnOidSize(varBindName) != NETPREFIX_LEN + INDEX_LEN ||
     varBindName->octs[NETPREFIX_LEN] != LOCALUNI || 
     varBindName->octs[NETPREFIX_LEN + 1] != NETPREFIX_STRINGLEN)
    return NOSUCHNAME;

  for(prefix = (NetPrefixNode *) var->value, cmp = AsnOidLess;
      prefix != NULL && (cmp = AsnOidCompare(varBindName, prefix->name)) <
	AsnOidEqual;
      prefix = prefix->next);

  if(varbind->value->a.simple->a.number == VALID && cmp != AsnOidEqual)
    {
      newPrefix = alloc_t(NetPrefixNode);
      newPrefix->name = alloc_t(AsnOid);
      newPrefix->name->octs = alloc(varBindName->octetLen);
      AsnOidCopy(newPrefix->name, varBindName);
{
      NetPrefixNode *tmp = (NetPrefixNode *) var->value;
      Q_INSERT_BEFORE(tmp, newPrefix, prefix);
}
      if(atmNetPrefix.octs == NULL)
	{
	  atmNetPrefix.octetLen = varBindName->octetLen - NETPREFIX_LEN - 2;
	  atmNetPrefix.octs = alloc(atmNetPrefix.octetLen);
	  memcpy(atmNetPrefix.octs, &varBindName->octs[NETPREFIX_LEN + 2], atmNetPrefix.octetLen);
	}
    }
  else if (varbind->value->a.simple->a.number == INVALID && cmp == AsnOidEqual)
    {
{
      NetPrefixNode *tmp = (NetPrefixNode *) var->value;
      Q_REMOVE(tmp, prefix);
}
    }

  return NOERROR;
}
mtimer_t *_mtimer_start( int32_t  sec,
                         void     (*callback)(void *arg),
                         void     *arg )
{
    mtimer_t *n, *walk, *last;

    n = alloc_t(mtimer_t);
    n->expiration.tv_usec = g_tnow.tv_usec;
    n->expiration.tv_sec  = g_tnow.tv_sec + sec;
    n->callback = callback;
    n->user = arg;

    last = NULL;
    for (walk = timers; walk; walk = walk->next)
        if (walk->expiration.tv_sec > n->expiration.tv_sec ||
            (walk->expiration.tv_sec == n->expiration.tv_sec &&
             walk->expiration.tv_usec > n->expiration.tv_usec)) break;
        else last = walk;
    if (walk) 
        Q_INSERT_BEFORE(timers,n,walk);
    else 
        Q_INSERT_AFTER(timers,n,last);
    return n;
}