예제 #1
0
파일: timer.c 프로젝트: StoneAerospace/ipc
IPC_RETURN_TYPE IPC_addTimerGetRef(unsigned long tdelay, long count,
				   TIMER_HANDLER_TYPE handler,
				   void *clientData,
				   TIMER_REF *timerRef)
{
  TIMER_PTR timer;

  if (!handler) {
    RETURN_ERROR(IPC_Null_Argument);
  } else if (tdelay == 0) {
    RETURN_ERROR(IPC_Argument_Out_Of_Range);
  } else if (count <= 0 && count != TRIGGER_FOREVER) {
    RETURN_ERROR(IPC_Argument_Out_Of_Range);
  } else {
    if (0 == timerRef) {
      /* if IPC_addTimerGetRef() is being called from IPC_addTimer(),
         we will clobber any old timers with the same handler
         for backwards compatibility */  
      timer = ipcGetTimer(handler);
      if (timer && timer->status != Timer_Deleted) {
	X_IPC_MOD_WARNING1("Replacing existing timer for handler (%#lx)\n",
			   (long)handler);
      } else {
	timer = NEW(TIMER_TYPE);
	LOCK_M_MUTEX;
	x_ipc_listInsertItemLast((const void *)timer, GET_M_GLOBAL(timerList));
	UNLOCK_M_MUTEX;
      }
    } else {
      /* if IPC_addTimerGetRef() is being called directly with a non-zero
	 timerRef argument, we don't clobber */
      timer = NEW(TIMER_TYPE);
      LOCK_M_MUTEX;
      x_ipc_listInsertItemLast((const void *)timer, GET_M_GLOBAL(timerList));
      UNLOCK_M_MUTEX;
    }

    timer->timerFn = handler;
    timer->period = tdelay;
    timer->clientData = clientData;
    timer->maxTrigger = count;
    timer->triggerTime = x_ipc_timeInMsecs() + tdelay;
    timer->status = Timer_Waiting;

    if (0 != timerRef) *timerRef = (TIMER_REF) timer;

    return IPC_OK;
  }
}
예제 #2
0
void x_ipc_listInsertItemAfter(const void *item, void *after, LIST_PTR list)
{
  LIST_ELEM_PTR element, tmp;
  
  if (!item || !list)
    return;
  
  LOCK_LIST_MUTEX;
  if (!after) {
    x_ipc_listInsertItemFirst(item, list);
    UNLOCK_LIST_MUTEX;
    return;
  }
  
  tmp = list->first;
  
  while (tmp && tmp->item != after) 
    tmp = tmp->next;
  
  if (!tmp || (tmp == list->last)) {
    x_ipc_listInsertItemLast(item, list);
    UNLOCK_LIST_MUTEX;
    return;
  }
  
  /* No need to lock M_MUTEX, since list.c is only place this is accessed */
  if (!GET_M_GLOBAL(listCellFreeListGlobal))
    x_ipc_listIncCellFreeList();
  
  element = GET_M_GLOBAL(listCellFreeListGlobal);
  GET_M_GLOBAL(listCellFreeListGlobal) = 
    GET_M_GLOBAL(listCellFreeListGlobal)->next;
  
  element->item = (const char *)item;
  element->next = tmp->next;
  element->previous = tmp;
  
  tmp->next = element;
  
  list->length++;
  UNLOCK_LIST_MUTEX;
}