Example #1
0
static int etimerheapCompareCB( void *elem1, void *elem2, void *param)
     /* Note: if the arguments are not valid 0 will be returned */
{
  int loc1 = (int)elem1;
  int loc2 = (int)elem2;
  HLIST raH = (HLIST)param;
  etimerNode *e1, *e2;
  UINT32 diff;

  if ( loc1<0 || loc2<0 )
    return 0;

  if( !( e1 = (etimerNode *)listGetElem(raH, loc1) ) )
    return 0;

  if (! ( e2 = (etimerNode *)listGetElem(raH, loc2)))
    return 0;

  if ( e1->absTime == e2->absTime )
    return 0;

/* if e2 is smaller it will be inserted later on the first place.
  Now the "1" will be returned.
  The problem arise when e2 is smaller because of time rollover.
  The rollover event can be identified if the difference between 2 elements
  is bigger 0x80000000 which is about 24 days*/
  if (e1->absTime  > e2->absTime)
	diff = e1->absTime - e2->absTime;  
  else 
	diff = e2->absTime - e1->absTime;  

  if (( e1->absTime > e2->absTime) && (diff<0x80000000))
  {
    /* examples
	   e1=100,     e2=80       result e2 is smaller
	   e1=F0000100 e2=F000080  result e2 is smaller
	   e1=F0000100 e2=0000080  result e2 is NOT smaller, because diff > 0x80000000 
	 */
    return 1;
  }
  else
  if (( e1->absTime < e2->absTime) && (diff>0x80000000))
  { 
    /* examples
	   e1= 100 e2=F000080 result e2 is SMALLER, 
	                      because diff > 0x80000000 which means e1 after rollover
	 */
    return 1;
  } 
  return -1;

}
Example #2
0
/*
 *Function   : mlistNext
 *Description: define 'next'element in the list in mlist
 *Parameters : hlist - mlist handle
 *             list  - list number to get 'next' element
 *             location - location after which to get 'next' element
 *Return     : 'next' element in the list
 */
int     mlistNext       (HLIST hlist, int list, int location)
{
    mListDesc *mlist=(mListDesc*)listGetElem(hlist, list);
    if (!mlist) return RVERROR;
    if (location==mlist->tail) return RVERROR;
    return listNext(hlist, location);
}
Example #3
0
/*
 *Function   : mlistHead
 *Description: define 1st (head) element in the list in mlist
 *Parameters : hlist - mlist handle
 *             list  - list number to get 'next' element
 *Return     : 1st (head) element in the list
 */
int     mlistHead       (HLIST hlist, int list)
{
    mListDesc *mlist=(mListDesc*)listGetElem(hlist, list);
    if (!mlist) return RVERROR;
    if (!mlist->count) return RVERROR;
    return listNext(hlist, list);
}
Example #4
0
/*
 *Function   : mlistDelete
 *Description: delete an element located at 'location' from the list in mlist
 *Parameters : hlist - mlist handle
 *             list  - list number to delete element from
 *             location - element to delete
 *Return     : TRUE if success, otherwise FALSE
 */
BOOL    mlistDelete     (HLIST hlist, int list, int location)
{
    mListDesc *mlist=(mListDesc*)listGetElem(hlist, list);
    if (!mlist) return FALSE;
    if (!mlist->count) return FALSE;
    if (mlist->tail==location) mlist->tail=listPrev(hlist,location);
    if (mlist->tail==list) mlist->tail=RVERROR;
    if (!listDelete(hlist, location)) return FALSE;
    mlist->count--;
    return TRUE;
}
Example #5
0
static etimerNode *etimerGetMinElement(
                    HETIMER timer
                    )
{
  etimerStruct *tm = (etimerStruct *)timer;
  int loc=0;

  if ( !timer ) return NULL;

  if (( loc = (int)bheapTop(tm->heap) ) < 0 )
    return NULL;

  return ( (etimerNode *)listGetElem(tm->timer, loc));
}
Example #6
0
static int etimerheapUpdateCB( void **elem, void *param )
{
  int loc;
  HLIST raH = (HLIST)param;
  etimerNode *e;

  if ( !elem )
    return RVERROR;

  loc = (int)(*elem);
  if ( !(e = (etimerNode *)listGetElem(raH, loc)))
    return RVERROR;
  e->heapRef = elem;
  return OK;

}
int listAddNode(ptNode pStart, size_t nmb, TKey key, TVal val)
{
	ptNode pN=listGetElem(pStart, nmb);
	if(pN)
	{		// Ежели эл-т есть, то начинаем
		ptNode pT=new TNode;	// Создали новый узел
		pT->link=pN->link;		// Новый узел указывает на 
								// тот же узел, что и исходный
		pN->link=pT;			// Исходный узел указывает на 
								// новый
		pT->name=key;
		pT->number=val;
	}	
	else	// Ежели эл-та нет, то заканчиваем =) 
		return 1;
	return 0;
}
Example #8
0
/*
 *Function   : mlistAdd
 *Description: add an element to the list in mlist
 *Parameters : hlist - mlist handle
 *             list  - list number to add element
 *             location - location where to add element
 *             elem - element to add
 *Return     : position of the new element in the list
 */
int     mlistAdd        (HLIST hlist, int list, int location, Element elem)
{
    int pos;
    mListDesc *mlist=(mListDesc*)listGetElem(hlist, list);
    if (!mlist) return RVERROR;
    if (location<0) location=list;
    pos=listAdd(hlist, location, elem);
    if (pos>=0)
    {
        if (!mlist->count || mlist->tail==location)
            mlist->tail=pos;
        /*h.e unused!!!
          mlist->changed++;
         */
        mlist->count++;
    }
    return pos;
}
int listRemoveNode(ptNode pStart, size_t nmb)
{
	ptNode pN=pStart;

	if(nmb==1)
		return -1;
	
	pN=listGetElem(pStart, nmb-1);
	if(pN)
	{
		ptNode pT=pN->link;
		pN->link=pT->link;
		delete pT;
	}
	else
		return 1;
	return 0;
}
Example #10
0
UINT32 etimerGetNextExpiration(
                   HETIMER timer
                   )
{
  etimerStruct *tm = (etimerStruct *)timer;
  etimerNode *node;
  int loc=0;

  if ( !timer ) return (UINT32)RVERROR;

  if (( loc = (int)bheapTop(tm->heap) ) < 0 )
    return (UINT32)RVERROR;

  if ( ! (node = (etimerNode *)listGetElem(tm->timer, loc) ) )
    return (UINT32)RVERROR;

  return ( node->absTime );

}
Example #11
0
int
etimerDelete(HETIMER timer, HETIMERELEM tNode)
{
  etimerStruct *tm = (etimerStruct *)timer;
  int location = (int)tNode;
  etimerNode *node;
  int loc;

  if (!timer) return RVERROR; /* NULL function */
  if (! (node = (etimerNode*)listGetElem(tm->timer, location) ))
    return RVERROR;
  loc = (int)(bheapDeleteNode(tm->heap, (BHeapNode*)node->heapRef ));

    if (loc!=location)
    {
        loc=location;
    }

  listDelete(tm->timer, location);
  return TRUE;
}
Example #12
0
int
etimerGetParams(
        IN HETIMER timer,
        IN HETIMERELEM tNode,
        OUT ETimerHandler *callback,
        OUT void **param
        )
{
  etimerStruct *tm = (etimerStruct *)timer;
  int location = (int)tNode;
  etimerNode *node;


  if (!timer) return RVERROR; /* NULL function */
  if (! (node = (etimerNode*)listGetElem(tm->timer, location) ))
    return RVERROR;

  *callback = node->callback;
  *param = node->param;

  return OK;
}
Example #13
0
/*
 *Function   : mlistGetElem
 *Description: get an element from mlist
 *Parameters : hlist - mlist handle
 *             location - location of the element to fetch
 *Return     : fetched element
 */
Element mlistGetElem    (HLIST hlist, int list, int location)
{
    if (list);

    return listGetElem(hlist, location);
}
Example #14
0
/*
 *Function   : mlistCurSize
 *Description: define number of elements in the list
 *Parameters : hlist - mlist handle
 *             list  - list number to get 'next' element
 *Return     : number of elements in the list
 */
int     mlistCurSize    (HLIST hlist, int list)
{
    mListDesc *mlist=(mListDesc*)listGetElem(hlist, list);
    if (!mlist) return 0;
    return mlist->count;
}