コード例 #1
0
ファイル: Queue.c プロジェクト: hamiltop/CultOfSkaro
/** Initialize a pre-alocated Queue struct to an empty state.
This Queue implementation requires that the user code allocate 
the memory space for both the Queue struct AND the data array
where the data pushed onto the Queue will be stored. 


\param Q	 A pointer to the pre-allocated Queue struct
\param data  A void pointer array that is size * sizeof(void*)
\param size  Maximum number of elements the Queue can hold
*/
void QueueInit(Queue* Q, void** data, int MaxElements)
{
	//xil_printf("QueueInit, max elements: %d\r\n", MaxElements);
	Q->data = data;
	Q->capacity = MaxElements;
	QueueClear(Q);
}
コード例 #2
0
ファイル: Junction.c プロジェクト: Rollmops/via
int
CountComponents(VImage src)
{
  int nbands,nrows,ncols,npixels;
  Voxel v,vv;
  int label,n;
  int b0,b1,r0,r1,c0,c1,b,r,c,bb,rr,cc;
  
  nbands  = VImageNBands(src);
  nrows   = VImageNRows(src);
  ncols   = VImageNColumns(src);
  npixels = nbands * nrows * ncols;

  label = 0;

  for (b=0; b<nbands; b++) {
    for (r=0; r<nrows; r++) {
      for (c=0; c<ncols; c++) {
	if (VPixel(src,b,r,c,VBit) == 0) continue;
	if (VPixel(ldest,b,r,c,VUByte) > 0) continue;

	QueueClear(&queue);

	label++;
	n = 1;

	v.b = b;
	v.r = r;
	v.c = c;
	if (enQueue(&queue,v) == FALSE) VError(" error in enQueue");
	VPixel(ldest,b,r,c,VUByte) = label;

	while (! QueueEmpty(&queue)) {

	  deQueue(&queue,&v);

	  b0 = (v.b > 0) ? v.b - 1 : 0;
	  b1 = (v.b + 1 < nbands) ? v.b + 1 : nbands - 1;
	  for (bb=b0; bb<=b1; bb++) {

	    r0 = (v.r > 0) ? v.r - 1 : 0;
	    r1 = (v.r + 1 < nrows) ? v.r + 1 : nrows - 1;
	    for (rr=r0; rr<=r1; rr++) {

	      c0 = (v.c > 0) ? v.c - 1 : 0;
	      c1 = (v.c + 1 < ncols) ? v.c + 1 : ncols - 1;
	      for (cc=c0; cc<=c1; cc++) {

		if (bb == v.b && rr == v.r && cc == v.c) continue;
		if (VPixel(src,bb,rr,cc,VBit) == 0) continue;
		if (VPixel(ldest,bb,rr,cc,VUByte) > 0) continue;
		vv.b = bb;
		vv.r = rr;
		vv.c = cc;
		if (enQueue(&queue,vv) == FALSE) VError(" error in enQueue");
		VPixel(ldest,bb,rr,cc,VUByte) = label;
		n++;
	      }
	    }
	  }
	}
      }
    }
  }
  return label;
}
コード例 #3
0
ファイル: bot.c プロジェクト: Beirdo/beirdobot
void serverKill( BalancedBTreeItem_t *node, IRCServer_t *server, bool unalloc )
{
    LinkedListItem_t       *listItem, *next;
    IRCChannel_t           *channel;
    BalancedBTreeItem_t    *item;

    if( server->enabled || server->enabledChanged ) {
        server->threadAbort = TRUE;
        thread_deregister( server->txThreadId );
        thread_deregister( server->threadId );
        server->threadAbort = FALSE;
    }

    if( unalloc ) {
        BalancedBTreeRemove( node->btree, node, LOCKED, FALSE );
    } else {
        server->enabled = FALSE;
    }

    if( server->txQueue ) {
        /* This *might* leak the contents of any queue entries? */
        QueueClear( server->txQueue, TRUE );
        QueueLock( server->txQueue );
        QueueDestroy( server->txQueue );
        server->txQueue = NULL;
    }

    if( server->channels ) {
        LinkedListLock( server->channels );
        BalancedBTreeLock( server->channelName );
        BalancedBTreeLock( server->channelNum );

        for( listItem = server->channels->head; listItem; listItem = next ) {
            next = listItem->next;
            channel = (IRCChannel_t *)listItem;

            regexpBotCmdRemove( server, channel );
            LinkedListRemove( server->channels, listItem, LOCKED );

            item = BalancedBTreeFind( server->channelName, 
                                      &channel->channel, LOCKED );
            if( item ) {
                BalancedBTreeRemove( server->channelName, item, LOCKED, 
                                     FALSE );
            }

            item = BalancedBTreeFind( server->channelNum, 
                                      &channel->channelId, LOCKED );
            if( item ) {
                BalancedBTreeRemove( server->channelNum, item, LOCKED, 
                                     FALSE );
            }

            ThreadAllNotifyChannel( channel );

            cursesMenuItemRemove( 2, MENU_CHANNELS, channel->menuText );
            free( channel->menuText );
            free( channel->channel );
            free( channel->fullspec );
            free( channel->url );
            free( channel );
        }

        LinkedListDestroy( server->channels );
        BalancedBTreeDestroy( server->channelName );
        BalancedBTreeDestroy( server->channelNum );
        server->channels = NULL;
        server->channelName = NULL;
        server->channelNum = NULL;
    }

    if( unalloc ) {
        free( server->server );
        free( server->password );
        free( server->nick );
        free( server->username );
        free( server->realname );
        free( server->nickserv );
        free( server->nickservmsg );
        free( server->ircInfo.Server );
    }

    LinkedListLock( server->floodList );
    for( listItem = server->floodList->head; listItem; listItem = next ) {
        next = listItem->next;

        LinkedListRemove( server->floodList, listItem, LOCKED );
        free( listItem );
    }
    LinkedListDestroy( server->floodList );
    server->floodList = NULL;

    ThreadAllNotifyServer( server );

    if( unalloc ) {
        cursesMenuItemRemove( 2, MENU_SERVERS, server->menuText );
        free( server->menuText );
        free( server->threadName );
        free( server->txThreadName );
        free( server );
        free( node );
    }
}