BOOL dll_addNodeTail( struct DoubleLinkedList *pdll, struct dllnode *pInsertNode ) { if ( NULL == pdll ) return FALSE; if ( NULL == pInsertNode ) return FALSE; pInsertNode->pNext = NULL; pInsertNode->pPrev = pdll->pTail; // if there already where nodes in the list let // previous node point at this one if ( NULL != pdll->pTail ) { pdll->pTail->pNext = pInsertNode; } // If this is the first node if ( NULL == pdll->pHead ) { pdll->pHead = pInsertNode; } // The tail always point at the end pdll->pTail = pInsertNode; // Calculate the number of elements in the list dll_getNodeCount( pdll ); return TRUE; };
int CCAN232Obj::dataAvailable(void) { int cnt; LOCK_MUTEX(m_can232ObjMutex); cnt = dll_getNodeCount(&m_can232obj.m_rcvList); UNLOCK_MUTEX(m_can232ObjMutex); return cnt; }
int CCAN232Obj::dataAvailable( void ) { int cnt; WaitForSingleObject( m_can232ObjMutex, INFINITE ); cnt = dll_getNodeCount( &m_can232obj.m_rcvList ); ReleaseMutex( m_can232ObjMutex ); return cnt; }
int CPeakObj::dataAvailable( void ) { int cnt; LOCK_MUTEX( m_receiveMutex ); cnt = dll_getNodeCount( &m_receiveList ); UNLOCK_MUTEX( m_receiveMutex ); return cnt; }
BOOL dll_removeNode( struct DoubleLinkedList *pdll, struct dllnode *pNode ) { struct dllnode *pNext; struct dllnode *pPrev; if ( NULL == pdll ) return FALSE; if ( NULL == pNode ) return FALSE; if ( NULL != pNode ) { // Remove the object if ( NULL != pNode->pObject ) { free( pNode->pObject ); pNode->pObject = NULL; } // Save links pNext = pNode->pNext; pPrev = pNode->pPrev; if ( NULL != pPrev ) { pPrev->pNext = pNext; } else { pdll->pHead = pNext; } if ( NULL != pNext ) { pNext->pPrev = pPrev; } else { pdll->pTail = pPrev; } // Remove the node free( pNode ); pdll->nCount--; } // Calculate the number of elements in the list dll_getNodeCount( pdll ); return TRUE; };
BOOL dll_addNodeAfter( struct DoubleLinkedList *pdll, struct dllnode *pNode, struct dllnode *pInsertNode ) { if ( NULL == pdll ) return FALSE; if ( NULL == pNode ) return FALSE; if ( NULL == pInsertNode ) return FALSE; if ( NULL == pNode->pNext ) { // There is no nodes after this one dll_addNodeTail( pdll, pInsertNode ); } else { // Add the node between the two dll_insertNode( pdll, pNode, pInsertNode ); } // Calculate the number of elements in the list dll_getNodeCount( pdll ); return TRUE; }
BOOL dll_insertNode( struct DoubleLinkedList *pdll, struct dllnode *pNode, struct dllnode *pInsertNode ) { //struct dllnode *pNode = malloc( sizeof( struct dllnode ) ); if ( NULL == pdll ) return FALSE; if ( NULL == pNode ) return FALSE; if ( NULL == pInsertNode ) return FALSE; // First link in the new node pInsertNode->pPrev = pNode; pInsertNode->pNext = pNode->pNext; // Fix up the node before pNode->pNext = pInsertNode; // Fix up the node after pNode->pNext->pPrev = pInsertNode; // Calculate the number of elements in the list dll_getNodeCount( pdll ); return TRUE; }