void Player::Enqueue (const QStringList& paths, bool sort) { QList<AudioSource> parsedSources; for (const auto& path : paths) parsedSources << AudioSource (path); Enqueue (parsedSources, sort); }
ACE_Future<QueryResult_AutoPtr> DatabaseWorkerPool::AsyncQuery(const char* sql) { QueryResultFuture res; BasicStatementTask* task = new BasicStatementTask(sql, res); Enqueue(task); return res; //! Fool compiler, has no use yet }
int refer_page (int pagenumber, int hash[], Queue *q) { listnode *node = hash[pagenumber]; if (node) { /* Page was found in the hash. Move the page to the top */ if (q->head == node) { /* already in front nothing to do */ } else if (q->tail == node) { /* remove this node from tail and put it in the front */ tail = tail->left; node->right = q->head; q->head->left = node; q->head = node; } else { node->left->right = node->right; node->right->left = node->left; node->right = q->head; q->head->left = node; q->head = node; } } else { node = newlistnode(pagenumber); Enqueue (node, q); hash[pagenumber] = node; } return 0; }
void EnqueueString(char* X, Queue* Q) { /*enqueue elements one by one*/ int i; for(i=0; X[i]; i++) Enqueue((unsigned char)X[i], Q); }
main(int argc, char **argv) { if (argc < 2) return 0; int port; if (sscanf(argv[1], "%d", &port) != 1) return 0; sockaddr_in serv; int sd = NewSock(); if (sd < 0 || Bind(sd, port) < 0) return -1; while(1) { if (!Ready(sd, -1)) continue; char mes[516]; sockaddr_in client; socklen_t c_len = sizeof(client); int l = recvfrom(sd, mes, 516, 0, (struct sockaddr *)&client, &c_len), stat; pid_t sub; while (qn > 0 && (sub = waitpid(-1, &stat, WNOHANG))) Dequeue(sub); if (Inqueue(client)) { fprintf(stderr, "get op = %d\n", *(short *)mes); continue; } sub = fork(); if (!sub) { Serve(mes, client); _exit(0); } Enqueue(client, sub); } }
// Function to insert a new node in complete binary tree void insert(struct node **root, int data, struct Queue* queue) { // Create a new node for given data struct node *temp = newNode(data); // If the tree is empty, initialize the root with new node. if (!*root) *root = temp; else { // get the front node of the queue. struct node* front = getFront(queue); // If the left child of this front node doesn’t exist, set the // left child as the new node if (!front->left) front->left = temp; // If the right child of this front node doesn’t exist, set the // right child as the new node else if (!front->right) front->right = temp; // If the front node has both the left child and right child, // Dequeue() it. if (hasBothChild(front)) Dequeue(queue); } // Enqueue() the new node for later insertions Enqueue(temp, queue); }
static void UnblockWaiters(BuildQueue* queue, NodeState* node) { const NodeData *src_node = node->m_MmapData; int enqueue_count = 0; for (int32_t link : src_node->m_BackLinks) { if (NodeState* waiter = GetStateForNode(queue, link)) { // Only wake nodes in our current pass if (waiter->m_MmapData->m_PassIndex != queue->m_CurrentPassIndex) continue; // If the node isn't ready, skip it. if (!AllDependenciesReady(queue, waiter)) continue; // Did someone else get to the node first? if (NodeStateIsQueued(waiter) || NodeStateIsActive(waiter)) continue; //printf("%s is ready to go\n", GetSourceNode(queue, waiter)->m_Annotation); Enqueue(queue, waiter); ++enqueue_count; } } if (enqueue_count > 0) WakeWaiters(queue, enqueue_count); }
/* * === FUNCTION ====================================================================== * Name: main * Description: * ===================================================================================== */ int main ( int argc, char *argv[] ) { int k=0; Queue my_queue; Tree_node my_tree_node; Queue_node dequeue_node; my_tree_node = malloc ( sizeof(struct tree_node) ); if ( my_tree_node==NULL ) { fprintf ( stderr, "\ndynamic memory allocation failed\n" ); exit (EXIT_FAILURE); } my_tree_node->data='A'; my_tree_node->firstchild=NULL; my_tree_node->nextsibling = NULL; my_queue = Init_Queue(); for(k=0;k<7;k++) { Enqueue(my_queue, my_tree_node); my_tree_node->data='A'+k+1; } Print_Queue(my_queue); printf("\n"); while((dequeue_node=Dequeue(my_queue))!=NULL) { printf("<!!%c!!>\n",dequeue_node->node_data.data); free(dequeue_node); Print_Queue(my_queue); printf("**************************\n\n"); } return EXIT_SUCCESS; } /* ---------- end of function main ---------- */
/** * Main loop for processing segments * @param ptr useless */ static void * process(void * ptr) { Bucket * b = NULL; Segment * seg = NULL; int turn = 0; while ((seg = (Segment *) Dequeue(service._iq)) != NULL) { if (seg->unique) { b = BucketInsert(b, seg); } Enqueue(service._oq, seg); } if (b != NULL) { SaveBucket(b); } Enqueue(service._oq, NULL); return NULL; }
void BasicPQueueTest(void) { int i; pqueueADT pq; printf("\n----------- Testing Basic PQueue functions -----------\n\n"); pq = NewPQueue(); printf("The pqueue was just created. Is it empty? %s", IsEmpty(pq) ? "TRUE" : "FALSE"); for (i = 1; i <= 10; i++) Enqueue(pq, i); printf("\nEnqueuing the integers from 1 to 10 (in forward order)\n"); printf("Pqueue should not be empty. Is it empty? %s\n", IsEmpty(pq) ? "TRUE" : "FALSE"); printf("Dequeuing the top 5 elements: "); for (i = 0; i < 5; i++) printf("%d ", DequeueMax(pq)); printf("\nDequeuing all the rest: "); while (!IsEmpty(pq)) printf("%d ", DequeueMax(pq)); printf("\nPqueue should be empty. Is it empty? %s\n", IsEmpty(pq) ? "TRUE" : "FALSE"); FreePQueue(pq); printf("Hit return to continue: "); { string s = GetLine(); FreeBlock(s); } }
int main(){ // create queue int queue[QUEUE_SIZE]={0}; int rear = 0; int front = 0; int choice; while(1){ showInitile(); choice = getChoice(); switch(choice){ case 1: displayQueue(queue); break; case 2: Enqueue(queue, &rear, &front); break; case 3: delqueue(queue, &rear, &front); break; case 4: system("CLS"); break; default: printf("你壞壞\n"); break; } } system("pause"); return 0; }
//BFS algorithm int shortestpath(Node *array, int Vnum, int root, int des) { int i,out,ss; //create a queue Queue *head=Initqueue(); Queue *path=Initqueue(); Node *travel,*p; int *color = (int *)malloc(Vnum*sizeof(int)); int *father = (int *)malloc(Vnum*sizeof(int)); for(i=0;i<Vnum;i++)father[i]=i; for(i=0;i<Vnum;i++)color[i]=white; //initialize colar Enqueue(head,root); color[root]=grey; father[root]=root; while(Isempty(head)!=1) { out = Dequeue(head); travel=array+out; for(p=travel->next;p!=NULL;p=p->next) { if(color[p->ID]==white) { Enqueue(head,p->ID); color[p->ID]=grey; father[p->ID]=out; } } color[out]=black; } if(color[des]==white) { printf("Error: there is no path between %d and %d.",root,des); ss=false; } else { //if there is a path, then print it out //for(i=0;i<Vnum;i++)printf("%d is father of %d\n",father[i],i); PrintPath(father,root,des); ss=true; } Clearqueue(head); Destroyqueue(head); free(color); free(father); return ss; }
int main() { Queue Q; Q = CreateQueue(4); Enqueue(1,Q); Enqueue(2,Q); Enqueue(3,Q); Enqueue(4,Q); printf("Size of queue is : %d and rear is :%d\n",Q->size,Q->rear); Dequeue(Q); printf("Size of queue is : %d and front is : %d\n",Q->size,Q->front); return 0; }
/** * In CPU-Transfer-Mode the API will add the length descriptor for us. In DMA mode we also use this behavior (it is, * however, redundant to the HPRPC protocol ... maybe it'd be the best to change the protocol ...) * * In DMA mode we prefix the transfer with the transfer length (and set the MSB to signalize DMA mode) * Here we add only a placeholder, later we will overwrite it during Send() (see OverwriteStartToken()). */ void CBufferedWriter::EnqueueDummyStartToken() { uint32_t lengthPlaceholder = 0; uint32_t sizeofPlaceholder = sizeof(lengthPlaceholder); Enqueue((uint8_t*)(&lengthPlaceholder), sizeofPlaceholder); m_pLengthPrefix = (uint32_t*)(m_KernelBufCursor - sizeofPlaceholder); //remember this place, we will write the total length to it when we finally send the buffers }
void Serial_Enter( serial_t serial) { pthread_t tid = pthread_self(); Enqueue(serial->queues[0],tid,NULL); while( pthread_equal(serial->queues[0]->head->id,tid)==0); pthread_mutex_lock(&(serial->mutexlock)); Dequeue(serial->queues[0]); }
void DatabaseWorkerPool::Execute(const char* sql) { if (!sql) return; BasicStatementTask* task = new BasicStatementTask(sql); Enqueue(task); }
//! asynchronously write TWO buffers and callback when delivered. The //! buffer2 are MOVED into the async writer. This is most useful to write a //! header and a payload Buffers that are hereby guaranteed to be written in //! order. void DispatcherThread::AsyncWrite( Connection& c, Buffer&& buffer, AsyncWriteCallback done_cb) { // the following captures the move-only buffer in a lambda. Enqueue([=, &c, b = std::move(buffer)]() mutable { dispatcher_->AsyncWrite(c, std::move(b), done_cb); }); WakeUpThread(); }
void Opportunity_Action_Repair_Installation::RegisterHostileAction(AiMain *ai, MapPointData &pos) { sint32 old_road_type; sint32 t; Pillaged_Node *p=NULL; if (ai->m_world->GetRoad(&pos, &old_road_type)) { t = ai->m_round_count->GetRound() + 10; p = new Pillaged_Node(pos, t, old_road_type); Enqueue(p); } else if (ai->m_world->HasUnderseaTunnel(&pos)) { t = ai->m_round_count->GetRound() + 10; p = new Pillaged_Node(pos, t, 0 ); Enqueue(p); } }
void cListQueue::Enqueue( int n ) { cNode* pNode = new cNode; pNode->m_nValue = n; Enqueue(pNode); }
PreparedQueryResultFuture DatabaseWorkerPool<T>::AsyncQuery(PreparedStatement* stmt) { PreparedStatementTask* task = new PreparedStatementTask(stmt, true); // Store future result before enqueueing - task might get already processed and deleted before returning from this method PreparedQueryResultFuture result = task->GetFuture(); Enqueue(task); return result; }
QueryResultHolderFuture DatabaseWorkerPool<T>::DelayQueryHolder(SQLQueryHolder* holder) { SQLQueryHolderTask* task = new SQLQueryHolderTask(holder); // Store future result before enqueueing - task might get already processed and deleted before returning from this method QueryResultHolderFuture result = task->GetFuture(); Enqueue(task); return result; }
void lib_AddPort(SysBase *SysBase, struct MsgPort *msgPort) { msgPort->mp_Node.ln_Type = NT_MSGPORT; NewListType(&msgPort->mp_MsgList,NT_MSGPORT); Forbid(); Enqueue(&SysBase->PortList, &msgPort->mp_Node); Permit(); }
QueryResultFuture DatabaseWorkerPool<T>::AsyncQuery(const char* sql) { BasicStatementTask* task = new BasicStatementTask(sql, true); // Store future result before enqueueing - task might get already processed and deleted before returning from this method QueryResultFuture result = task->GetFuture(); Enqueue(task); return result; }
void BFS_ST(int V0) { int Vx, Vy; Visit(V0); Enqueue(V0); while (!IsEmpty()) { Dequeue(&Vx); Vy = Find_Adj(Vx, 1); while (Vy != -1) { Visit(Vy); AddEdge(Vx, Vy); Enqueue(Vy); Vy = Find_Adj(Vx, 0); } } }
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ queue q; QueueNew(&q); Enqueue(&q, 5); Enqueue(&q, 6); Enqueue(&q, 7); PrintTop(&q); PrintTop(&q); return 0; }
void DatabaseWorkerPool<T>::Execute(const char* sql) { if (Trinity::IsFormatEmptyOrNull(sql)) return; BasicStatementTask* task = new BasicStatementTask(sql); Enqueue(task); }
void * chapeiro(void *args){ Cliente clitratar; int i; int duracao; int id_thread = (int) args; char idCha[11]; // string para o registo do id do chapeiro - p.e. "Chapeiro 1" char servico[27]; // string para o registo do numero do servico - p.e. "Tou a tratar o servico 1!" sprintf(idCha, "Chapeiro %d", id_thread); pthread_mutex_lock(&mutexRegis); regista(idCha, NULL, "Bom dia chefe, cheguei!"); pthread_mutex_unlock(&mutexRegis); while(work == 1) { if(!IsEmpty(Qcha)){ pthread_mutex_lock(&mutexCha); clitratar = FrontAndDequeue(Qcha); pthread_mutex_unlock(&mutexCha); pthread_mutex_lock(&mutexRegis); regista(idCha, clitratar.matricula, "Vou comecar a trabalhar"); pthread_mutex_unlock(&mutexRegis); for(i=0;i<clitratar.n_servicos;i++){ if(work != 1) break; pthread_mutex_lock(&mutexRegis); duracao = getDuracaoServico(clitratar.servicos[i], 3); pthread_mutex_unlock(&mutexRegis); if(duracao!=-1){ if(duracao!=0){ sprintf(servico, "Tou a tratar o servico %d!", clitratar.servicos[i]); pthread_mutex_lock(&mutexRegis); regista(idCha, clitratar.matricula, servico); pthread_mutex_unlock(&mutexRegis); sleep(duracao); } } else{ pthread_mutex_lock(&mutexPin); Enqueue(clitratar, Qpin); // envia o veiculo para a proxima fila pthread_mutex_unlock(&mutexPin); break; } } } else//Se nao houver carros para tratar, aguarda 2 segundos.. sleep(2); } pthread_mutex_lock(&mutexRegis); regista(idCha, NULL, "Ate amanha camaradas!"); pthread_mutex_unlock(&mutexRegis); return NULL; }
void Relabel(int v) { count[dist[v]]--; dist[v] = 2*N; for (int i = 0; i < G[v].size(); i++) if (G[v][i].cap - G[v][i].flow > 0) dist[v] = min(dist[v], dist[G[v][i].to] + 1); count[dist[v]]++; Enqueue(v); }
void Gap(int k) { for (int v = 0; v < N; v++) { if (dist[v] < k) continue; count[dist[v]]--; dist[v] = max(dist[v], N+1); count[dist[v]]++; Enqueue(v); } }
void Push(Edge &e) { int amt = int(min(excess[e.from], LL(e.cap - e.flow))); if (dist[e.from] <= dist[e.to] || amt == 0) return; e.flow += amt; G[e.to][e.index].flow -= amt; excess[e.to] += amt; excess[e.from] -= amt; Enqueue(e.to); }