void KisStroke::cancelStroke() { // case 6 if (m_isCancelled) return; if(!m_strokeInitialized) { clearQueue(); } else if(m_strokeInitialized && (!m_jobsQueue.isEmpty() || !m_strokeEnded)) { clearQueue(); if(m_cancelStrategy) { m_jobsQueue.enqueue( new KisStrokeJob(m_cancelStrategy, m_strokeStrategy->createCancelData())); } } // else { // too late ... // } m_isCancelled = true; m_strokeEnded = true; }
int main(int argc, char **argv) { if(argc != 3) { printf("Usage: zmq_bridge <port 1> <port 2>\n"); exit(EXIT_FAILURE); } int ret; int port1, port2; char portBuf[128]; void *context = zmq_init(1); void *pubber = zmq_socket(context, ZMQ_PUB); void *subber = zmq_socket(context, ZMQ_SUB); port1 = atoi(argv[1]); port2 = atoi(argv[2]); printf("%d-->%d\n", port1, port2); bzero(portBuf, 128); sprintf(portBuf, "tcp://*:%d", port1); printf("Subber: %s\n", portBuf); ret = zmq_bind(subber, portBuf); if(ret < 0) { printf("Error no= %s\n", strerror(errno)); } zmq_setsockopt(subber, ZMQ_SUBSCRIBE, "", 0); bzero(portBuf, 128); sprintf(portBuf, "tcp://*:%d", port2); printf("Pubber: %s\n", portBuf); ret = zmq_bind(pubber, portBuf); if(ret < 0) { printf("Error no= %s\n", strerror(errno)); } subq = newqueue(); pubq = newqueue(); /*Init sockaddr for UDP*/ memset((char *)&client, 0, sizeof(client)); client.sin_family = AF_INET; client.sin_port = htons(INT_PORT2); inet_aton("127.0.0.1", &client.sin_addr); memset((char *)&server, 0, sizeof(server)); server.sin_family = AF_INET; server.sin_port = htons(INT_PORT1); inet_aton("127.0.0.1", &server.sin_addr); startBridge(subber, pubber); //Clean up; clearQueue(subq); clearQueue(pubq); //Clean zmq return EXIT_SUCCESS; }
int updateGetSingleChunk(Packet *pkt, int peerID) { recvWindow *rw = &(downloadPool[peerID].rw); int dataSize = getPacketSize(pkt) - 16; uint8_t *dataPtr = pkt->payload + 16; uint32_t seq = (uint32_t)getPacketSeq(pkt); downloadPool[peerID].timeoutCount = 0; fprintf(stderr,"Got pkt %d expecting %d\n", seq, rw->nextPacketExpected); if(seq >= rw->nextPacketExpected) { if((seq > rw->nextPacketExpected) && ((seq - rw->nextPacketExpected) <= INIT_THRESH)) { insertInOrder(&(downloadPool[peerID].cache), newFreePacketACK(seq), seq); newPacketACK(rw->nextPacketExpected - 1, downloadPool[peerID].ackSendQueue); } else if(seq - rw->nextPacketExpected <= INIT_THRESH) { newPacketACK(seq, downloadPool[peerID].ackSendQueue); rw->nextPacketExpected = flushCache(rw->nextPacketExpected, downloadPool[peerID].ackSendQueue, &(downloadPool[peerID].cache)); } rw->lastPacketRead = seq; rw->lastPacketRcvd = seq; int curChunk = downloadPool[peerID].curChunkID; long offset = (seq - 1) * PACKET_DATA_SIZE + BT_CHUNK_SIZE * curChunk; FILE *of = getChunk.filePtr; fprintf(stderr,"In: %d [%ld-%ld]\n", seq, offset, offset + dataSize); if(of != NULL) { fseek(of, offset, SEEK_SET); fwrite(dataPtr, sizeof(uint8_t), dataSize, of); } if(rw->nextPacketExpected > BT_CHUNK_SIZE / PACKET_DATA_SIZE + 1){ clearQueue(downloadPool[peerID].timeoutQueue); fprintf(stderr,"Chunk finished downloading! Next expected %d thresh %d\n", rw->nextPacketExpected, BT_CHUNK_SIZE / PACKET_DATA_SIZE + 1); getChunk.list[curChunk].fetchState = 1; downloadPool[peerID].state = 0; clearQueue(downloadPool[peerID].timeoutQueue); initWindows(&(downloadPool[peerID].rw), &(uploadPool[peerID].sw)); fprintf(stderr,"Chunk %d fetched!\n", curChunk); // fprintf(stderr,"%d More GETs in queue\n", downloadPool[peerID].getQueue->size); return 1; } else { return 0; } } else { fprintf(stderr,"Received an unexpected packet!" "Expecting %d but received %d!", rw->nextPacketExpected, seq); newPacketACK(seq, downloadPool[peerID].ackSendQueue); return 0; } }
CSyncQueue::~CSyncQueue() { clearQueue(); clearList(); DeleteCriticalSection(&this->wQueue); DeleteCriticalSection(&this->dList); }
void testQueue() { pushQueue("we"); pushQueue("are"); pushQueue("the"); pushQueue("champion"); pushQueue("!"); while (!emptyQueue()) { showQueue(); printf("Pop the front of queue: %s\n", frontQueue()->value); popQueue(); } pushQueue("we"); pushQueue("are"); pushQueue("the"); pushQueue("champion"); pushQueue("!"); showQueue(); clearQueue(); printf("After clearing:\n"); showQueue(); return; }
void bfs_traverse(double road[][MAX_POINT]) { int visited[MAX_POINT]; int i; for (i = 1; i < MAX_POINT; i++) visited[i] = 0; struct queueLK *hq; initQueue(hq); for (i = 1; i < MAX_POINT; i++) { if (!visited[i]) { visited[i] = 1; visit(road, i); enQueue(hq, i); while (!emptyQueue(hq)) { int u = outQueue(hq); int j; for (j = 1; j < MAX_POINT; j++) { if (road[u][j] > 0.0001 && !visited[j]) { visited[j] = 1; visit(road, j); enQueue(hq, j); } } } } } clearQueue(hq); }
void ReadableStream::closeInternal() { ASSERT(m_state == Readable); m_state = Closed; resolveAllPendingReadsAsDone(); clearQueue(); if (m_reader) m_reader->close(); }
void TileResolver::setMapSourceId(int sourceId) { m_nStrategyId = sourceId; clearCache(true); clearQueue(); //((PhysicMap*)m_pPhysicMap)->releaseCells(); ((PhysicMap*)m_pPhysicMap)->reloadTiles(); }
void TileResolver::setMapSourceId(int sourceId) { m_nStrategyId = sourceId; MapStrategy* pS = MapStrategyFactory::getStrategy(sourceId); m_pTileLoader->setMapStrategy(pS); clearCache(true); clearQueue(); //((PhysicMap*)m_pPhysicMap)->releaseCells(); ((PhysicMap*)m_pPhysicMap)->reloadTiles(); }
void AsyncTaskExecutor::execute(Runnable *task) { if(_maxQueueSize != 0 && _queue.size() > _maxQueueSize) { clearQueue(); } _mutex.lock(); _queue.push_back( task ); _mutex.unlock(); _signal.notify_one(); }
void ReadableStream::error(DOMException* exception) { if (m_state != ReadableStream::Readable) return; m_exception = exception; clearQueue(); rejectAllPendingReads(m_exception); m_state = Errored; if (m_reader) m_reader->error(); }
void VideoDemuxerThread::close() { map<int, VideoMsgQueuePtr>::iterator it; for (it = m_PacketQs.begin(); it != m_PacketQs.end(); it++) { VideoMsgQueuePtr pPacketQ = it->second; clearQueue(pPacketQ); VideoMsgPtr pMsg(new VideoMsg); pMsg->setClosed(); pPacketQ->push(pMsg); m_PacketQEOFMap[it->first] = false; } stop(); }
void AsyncTaskExecutor::stop() { if(_isRunning) { _isRunning = false; clearQueue(); _signal.notify_one(); if(_thread) { _thread->join(); _thread.reset(nullptr); } } }
QtCamera::~QtCamera() { if (m_captureThread) { stopVideo(); delete m_captureThread; m_captureThread = NULL; } if (m_camera) { delete m_camera; m_camera = NULL; } clearQueue(); }
ScriptPromise ReadableStream::cancel(ScriptState* scriptState, ScriptValue reason) { if (m_state == Closed) return ScriptPromise::cast(scriptState, v8::Undefined(scriptState->isolate())); if (m_state == Errored) return ScriptPromise::rejectWithDOMException(scriptState, m_exception); ASSERT(m_state == Readable || m_state == Waiting); if (m_state == Waiting) m_ready->resolve(ToV8UndefinedGenerator()); clearQueue(); m_closed->resolve(ToV8UndefinedGenerator()); m_state = Closed; return m_source->cancelSource(scriptState, reason).then(ConstUndefined::create(scriptState)); }
void update2(int value) { int i; BALL b; event e; ball_event be; vector v1; char c = 0; if(chance == 0 && gamepause == 0) { runphytrd = 1; gameclock+=GAMETICK; while(!isEmpty(queue) && phydone == 1) {// do something e = dequeue(queue, queue_mutex); if(e.label == 1) {//pocketin enqueue(rulesque,e,rules_mutex); } if(e.label == 0) { // command to sinc ballques be = dequeue_ball(ballque,ballmutex); for(i=0;i<10;i++) { coins[i]=be.arr[i]; } } if(e.label==6) { runphy =0; runphytrd = 0; stopSim(); clearQueue(queue); chance = 2; gameclock =0; runphy = 1; gameRules(); coins[0].pos = relocateStriker(); } } } glutPostRedisplay(); glutTimerFunc(GAMETICK , update2 , 0); }
void VideoDemuxerThread::seek(int seqNum, float destTime) { map<int, VideoMsgQueuePtr>::iterator it; m_pDemuxer->seek(destTime); for (it = m_PacketQs.begin(); it != m_PacketQs.end(); it++) { VideoMsgQueuePtr pPacketQ = it->second; clearQueue(pPacketQ); // send SEEK_DONE VideoMsgPtr pMsg(new VideoMsg); pMsg->setSeekDone(seqNum, destTime); pPacketQ->push(pMsg); m_PacketQEOFMap[it->first] = false; } m_bEOF = false; }
/*main()函数*/ int main(int argc, char* argv[]) { queue_t q; int a[8] = {1, 2, 3, 4, 5, 6, 7, 8}; int i; initQueue(&q); for(i=0; i<8; i++) { enQueue(&q, a[i]); } // printf("%d",outQueue(&q)); enQueue(&q, 68); // printf("%d", peekQueue(&q)); while (!is_emptyQueue(&q)) { printf(" %d.\n", outQueue(&q)); } printf(" \n"); clearQueue(&q); }
int main(void) { QUEUE_t myQueue; STACK_t myStack; stack_init(&myStack); queue_init(&myQueue); for(int i = 0; i < 10; i++) { insertQueue(&myQueue,(void*) (rand() % 100)); push(&myStack, (void*) (rand() % 50)); } itemS_t* holdS = pop(&myStack); printf("Item popped: %d\n", holdS->keyValue); free(holdS); printf("Pushing 99...\n"); push(&myStack, (void*) 99); holdS = pop(&myStack); printf("Item popped: %d", holdS->keyValue); free(holdS); printQueue(&myQueue); printStack(&myStack); itemQ_t* holdQ = removeQueue(&myQueue); printf("Item removed from queue: %d.\n", holdQ->keyValue); free(holdQ); printQueue(&myQueue); printStack(&myStack); clearQueue(&myQueue); clearStack(&myStack); return 0; }
void ReadableStream::error(PassRefPtrWillBeRawPtr<DOMException> exception) { switch (m_state) { case Waiting: m_exception = exception; m_ready->reject(m_exception); m_closed->reject(m_exception); m_state = Errored; break; case Readable: clearQueue(); m_exception = exception; m_ready->reset(); m_ready->reject(m_exception); m_closed->reject(m_exception); m_state = Errored; break; default: break; } }
void lQueueTestMain() { SqQueue<float> Q; initQueue(Q); for(int i=0;i<18;++i) enQueue(Q,3.14f*i); queueTraverse(Q); float a; for(int i=0;i<4;++i) deQueue(Q,a); queueTraverse(Q); cout<<queueLength(Q)<<endl; getQueueHead(Q,a); cout<<a<<endl; clearQueue(Q); destroyQueue(Q); int aa=100; }
int main() { queue* Q = createQueue(); int i; do { printf("(1)enQueue (2)deQueue (3)getElement (4)clearQueue (5)traverse (6)length (7)exit : "); scanf("%d", &i); if (i == 1) { element ele; int temp; scanf("%d", &temp); ele.val = temp; enQueue(Q, ele); } else if (i == 2) printf("%s\n", deQueue(Q) ? "success" : "fail"); else if (i == 3) printf("%d\n", getElement(Q).val); else if (i == 4) clearQueue(Q); else if (i == 5) { traverseQueue(Q, printElement); putchar('\n'); } else if(i == 6) printf("%d\n",getLength(Q)); } while (i != 7); destroyQueue(Q); return 0; }
void QtCamera::startVideo() { if (!m_camera) { if (!createCamera()) { QMessageBox::warning(this, "QtCamera", "Error allocating camera", QMessageBox::Ok); return; } } if (!m_camera->open(0)) { delete m_camera; m_camera = NULL; QMessageBox::warning(this, "QtCamera", "Error opening camera", QMessageBox::Ok); return; } clearQueue(); if (!m_captureThread) { m_captureThread = new CaptureThread(); if (!m_captureThread) { QMessageBox::warning(this, "QtCamera", "Error allocating capture thread", QMessageBox::Ok); return; } } connect(m_captureThread, SIGNAL(newImage(Mat)), this, SLOT(newImage(Mat)), Qt::DirectConnection); if (m_captureThread->startCapture(m_camera)) { m_frameCount = 0; m_frameRateTimer = startTimer(3000); m_frameRefreshTimer = startTimer(20); ui.actionStart->setEnabled(false); ui.actionStop->setEnabled(true); } else { QMessageBox::warning(this, "QtCamera", "Error starting capture thread", QMessageBox::Ok); } }
void TCPConnection::finally() throw () { IBRCOMMON_LOGGER_DEBUG_TAG(TCPConnection::TAG, 60) << "TCPConnection down" << IBRCOMMON_LOGGER_ENDL; try { // shutdown the keepalive sender thread _keepalive_sender.stop(); // shutdown the sender thread _sender.stop(); } catch (const std::exception&) { }; // close the tcpstream if (_socket_stream != NULL) _socket_stream->close(); try { _callback.connectionDown(this); } catch (const ibrcommon::MutexException&) { }; // clear the queue clearQueue(); }
void testPushToQueue() { cmdType nCommand_1=cmd_upgrade; cmdOption nStat_1=upgrade_power; int tar_1 = 1; cmdType nCommand_2=cmd_upgrade; cmdOption nStat_2=upgrade_range; int tar_2 = 2; ActionQueueStructure newQueue = getQueue(NULL); sput_fail_unless(pushToQueue(newQueue,nCommand_1,nStat_1,tar_1) == 1,"Valid: 1 Queue Item"); sput_fail_unless(pushToQueue(newQueue,nCommand_2,nStat_2,tar_2) == 2,"Valid: 2 Queue Items"); sput_fail_unless(getFirstCommand(newQueue) == cmd_upgrade,"Valid: Top of Queue Upgrade Command"); sput_fail_unless(getFirstOption(newQueue) == upgrade_power,"Valid: Top of Queue Power Option"); sput_fail_unless(getLastCommand(newQueue) == cmd_upgrade,"Valid: Last in Queue upgrade Command"); sput_fail_unless(getLastOption(newQueue) == upgrade_range,"Valid: Last of Queue range Option"); pushToQueue(newQueue,cmd_mktwr,mktwr_int,2); sput_fail_unless(getLastCommand(newQueue) == cmd_mktwr,"Valid: Last in Queue make tower command"); sput_fail_unless(getLastOption(newQueue) == mktwr_int,"Valid: Last option in Queue is int tower"); clearQueue(); }
int main(){ Lol a,b,*z; GenericField *k; Queue *fila; strcpy(a.c,"CASA1"); strcpy(b.c,"CASA2"); a.v=10; b.v=20; fila=createQueue(); insertElement(fila,&a,STRUCT1); insertElement(fila,&b,STRUCT1); do{ z=(Lol *)getFieldValue(getElement(fila)); if(z!=NULL){ printf("%d %s\n",z->v,z->c); } }while(nextElement(fila)==0); clearQueue(fila); getchar(); return 0; }
/** * invokes the cache method on all queued audio events * (this will also remove them from the queue) * * in case the BulkCacher was constructed to work in * sequence, this method will cache the queue one event at a time * note that this method must be invoked after each cache-invocation * from the freshly cached event when it finishes its caching routine */ void BulkCacher::cacheQueue() { int amount = _queue->size(); //Debug::log( "BulkCacher::caching %d events", amount ); for ( int i = 0; i < amount; i++ ) { BaseCacheableAudioEvent* event = _queue->at( i ); // (interesting detail must remove the event from the queue // BEFORE invoking cache (isn't executed synchronously and // would cause a recursive loop!) removeFromQueue( event ); event->cache( _sequential ); // just one when sequential if ( _sequential ) return; } clearQueue(); // superfluous actually }
void MovementProcessor::process(void) { if (hasTeleported()) { player->getTile()->x = teleport_target->x; player->getTile()->z = teleport_target->z; /* Clear the queue */ clearQueue(); } else { if (!pendingTiles->empty()) { Tile to = popStep(); Tile me = *player->getTile(); int dx = to.x - me.x; int dz = to.z - me.z; walk_dir = directionForDelta(dx, dz); player->getTile()->x = to.x; player->getTile()->z = to.z; } else { walk_dir = -1; run_dir = -1; } } }
Scheduler::Scheduler() { clearQueue(); clearSchedule(); }
void procesCommand(void) { int i = 0; PORTD = ++count ; // Commandstrings starts with "AT" else invalid string than skip whole if ( CommandData[i] == '#') { i+= 1; } else return ; XLCDClear(); XLCDPutRamString((char*)CommandData); while( i < CommandLength ) { switch (CommandData[i++]) { case 'n': // Noise on // BeepOn() ; // PORTB = 0x55 ; break; case 'N': // Noise off // BeepOff() ; break; case 'L': XLCDPut('L'); //pressedA(); setLed(CommandData[i] - '0', CommandData[i + 1]- '0'); i += 2; break; case 'b': // Sets data on port setPortBData(CommandData[i]); i += 1; break; case 'B': // Set B port direction setPortBIO(CommandData[i]); i += 1; break; case 'd': setPortDData(CommandData[i]); i += 1; break; case 'D': setPortDIO(CommandData[i]); i += 1; break; case 'e': // We should take some care here EC ports contain PWM en direction bits. setPortECData(CommandData[i]); i += 1; break; case 'I': //Instruction List clearQueue(); XLCDClear(); XLCDL1home(); // for (temper=0;temper<17;temper++){ while(CommandData[i]!= 'I'){ XLCDPut(CommandData[i]); push((int) CommandData[i]); i += 1; } i +=1; break; case 'S': XLCDClear(); XLCDL1home(); XLCDPutRomString("STAHP! =("); //Emergency STHAP! emergencyStop = 1; break; // case 'r': // stored_CCPR1L = CommandData[i]; // setCCPR1L_REG(CommandData[i]); // //stored_CCPR1L = 140; // //setCCPR1L_REG(140); // i += 1; // break; // case 's': // stored_CCPR2L = CommandData[i]; // setCCPR2L_REG(CommandData[i]); // //stored_CCPR2L = 140; // //setCCPR2L_REG(140); // i += 1; // break; default: /* nop */ ; } } }