• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ queue_get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中queue_get函数的典型用法代码示例。如果您正苦于以下问题:C++ queue_get函数的具体用法?C++ queue_get怎么用?C++ queue_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了queue_get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: create_all_numbers_queue

void *main_thread(void *arg) {
	CircularQueue *entryQueue = create_all_numbers_queue(_max_number);
	
	CircularQueue *exitQueue;
	queue_init(&exitQueue, _max_number);
	
	pthread_t filter_tid;
	
	pthread_create(&filter_tid, NULL, filter_thread, exitQueue);
	
	unsigned int first = queue_get(entryQueue);
	
	if (place_number_into_shared_memory(first)) {
		printf("Error while accessing the shared memory region.\n");
		
		exit(EXIT_FAILURE);
	}
	
	#if DEBUG
	printf("Placed %d on the shared memory region.\n", first);
	#endif
	
	unsigned int number = 0;
	
	while (( number = queue_get(entryQueue) ))	//	Get each number from the entry queue up until "0"
		if (number % first)	//	Up so far, the number is not prime.
			queue_put(exitQueue, number);
	
	queue_put(exitQueue, 0);
	
	queue_destroy(entryQueue);
	
	return NULL;
}
开发者ID:joaodealmeida,项目名称:SOPE2,代码行数:34,代码来源:main.c


示例2: unsorted_mode

void unsorted_mode() {
	queue_t *q = queue_create();
	
	char *t1 = malloc(1);
	char *t2 = malloc(2);
	char *t3 = malloc(4);
	char *t4 = malloc(8);
	
	test *s1 = malloc(sizeof(test));
	s1->test = t1; 
	test *s2 = malloc(sizeof(test));
	s2->test = t2; 
	test *s3 = malloc(sizeof(test));
	s3->test = t3; 
	test *s4 = malloc(sizeof(test));
	s4->test = t4; 
	
	queue_put(q, s1);
	queue_put(q, s2);
	queue_put(q, s3);
	queue_put(q, s4);
	
	test *t;
	queue_get(q, (void **)&t);
	free_test(t);
	queue_get(q, (void **)&t);
	free_test(t);
	
	queue_destroy_complete(q, (void *)free_test);
}
开发者ID:MatthewEdge,项目名称:Queue,代码行数:30,代码来源:example.c


示例3: sorted2_mode

void sorted2_mode() {
	queue_t *q = queue_create_limited_sorted(3, 1, (void *)cmp_int_ptr);
	
	int t1 = 1;
  queue_put(q, &t1);
	int t2 = 15;
  queue_put(q, &t2);
	int t3 = 3;
  queue_put(q, &t3);
	int t4 = 27;
  queue_put(q, &t4);
	int t5 = 9;
  queue_put(q, &t5);
  
  int *i;
  queue_get(q, (void **)&i);
  printf("first element was %d\n", *i);
  queue_get(q, (void **)&i);
  printf("second element was %d\n", *i);
  queue_get(q, (void **)&i);
  printf("third element was %d\n", *i);
  queue_get(q, (void **)&i);
  printf("fourth element was %p\n", i);
  queue_get(q, (void **)&i);
  printf("fifth element was %p\n", i);
  
	queue_destroy_complete(q, NULL);
}
开发者ID:MatthewEdge,项目名称:Queue,代码行数:28,代码来源:example.c


示例4: sorted_mode

void sorted_mode() {
	queue_t *q = queue_create_sorted(1, (void *)cmp_int_ptr);
	
	int *t1 = malloc(sizeof(int));
	int *t2 = malloc(sizeof(int));
	int *t3 = malloc(sizeof(int));
	int *t4 = malloc(sizeof(int));
	
	*t1 = 10;
	*t2 = 12;
	*t3 = 1;
	*t4 = 1;
	
	queue_put(q, t1);
	queue_put(q, t2);
	queue_put(q, t3);
	queue_put(q, t4);
	
	int *t;
	queue_get(q, (void **)&t);
	printf("first int %i\n", *t);
	free(t);
	queue_get(q, (void **)&t);
	printf("second int %i\n", *t);
	free(t);
	queue_get(q, (void **)&t);
	printf("third int %i\n", *t);
	free(t);
	queue_get(q, (void **)&t);
	printf("fourth int %i\n", *t);
	free(t);
	
	queue_destroy_complete(q, NULL);
}
开发者ID:MatthewEdge,项目名称:Queue,代码行数:34,代码来源:example.c


示例5: queue_get

void *filterThreadFunc(void *arg) {
	CircularQueue* q = arg;
	QueueElem elem = queue_get(q);
	QueueElem first = elem;
	addPrimesToList(first);
	if(first  > (int) sqrt(N)){
		elem = queue_get(q);
		while(elem != 0) {
			
			addPrimesToList(elem);
			elem = queue_get(q);
		}
		sem_post(&canTerminate);
	}
	else {		
		pthread_t filterThreadId;
		CircularQueue* temp;
		queue_init(&temp, queueSize);
		if(pthread_create(&filterThreadId, NULL, filterThreadFunc, (void*) temp)) {
			printf("Thread error.");
		}	
		do {
			elem = queue_get(q);
			if(elem % first != 0)
				queue_put(temp, elem);
		} while (elem != 0);
		queue_put(temp, 0);
	}
	queue_destroy(q);
	return NULL;
}
开发者ID:Orpheuz,项目名称:SOPE-PrimeNumbers,代码行数:31,代码来源:primes.c


示例6: Filter

void* Filter(void* q){
	QueueElem primo= queue_get(q);
	QueueElem temp= queue_get(q);
	//printf(" ler %d \n",temp);
	if(primo>ceil(sqrt(N))){
		while(temp!=0){
			// printf(" a ler finais : %d \n",temp);
			if(temp!=0){
				pthread_mutex_lock(&mutex2);
				primes[ind]=temp;
				ind++;
				pthread_mutex_unlock(&mutex2);
			}
			temp=queue_get(q);
		}
		pthread_mutex_lock(&mutex2);
		primes[ind]=primo;
		ind++;
		pthread_mutex_unlock(&mutex2);
		
		queue_destroy(q);
		sem_post(&semaforo);
	}
	else{
		CircularQueue* q2;
		queue_init(&q2,10);
		pthread_t ThreadPrimo;
		pthread_create(&ThreadPrimo,NULL,Filter,q2);

		// printf("thread created \n");
		pthread_mutex_lock(&mutex1);
		number_threads++;
		pthread_mutex_unlock(&mutex1);

		while(temp!=0){
			if(temp%primo!=0){
				queue_put(q2,temp);
				// printf(" por %d \n",temp);
			}	

			temp=queue_get(q);
			// printf(" ler %d \n",temp);

		}
		queue_put(q2,0);
		queue_destroy(q);

		pthread_mutex_lock(&mutex2);
		primes[ind]=primo;
		ind++;
		pthread_mutex_unlock(&mutex2);
	}

	pthread_mutex_lock(&mutex1);
	number_threads--;
	pthread_mutex_unlock(&mutex1);

	return NULL;
}
开发者ID:PedroFariaa,项目名称:SOPE,代码行数:59,代码来源:Primes.c


示例7: queue_init

void *filter_thread(void *arg) {
	CircularQueue *entryQueue = (CircularQueue *) arg;
	
	CircularQueue *exitQueue;
	queue_init(&exitQueue, _max_number);
	
	unsigned int first = queue_get(entryQueue);
	
	if (place_number_into_shared_memory(first)) {
		printf("Error while accessing the shared memory region.\n");
		
		exit(EXIT_FAILURE);
	}
	
	#if DEBUG
	printf("Placed %d on the shared memory region.\n", first);
	#endif
	
	unsigned int number = 0;
	
	if (first > sqrt(_max_number)) {
		#if DEBUG
		printf("Finished, the rest are primes. (%d and up)\n", first);
		#endif
		
		while (( number = queue_get(entryQueue) ))	//	Get each number from the entry queue up until "0"
			place_number_into_shared_memory(number);
		
		//	Signal the EOP semaphore, we are done!
		
		sem_t *semaphore = sem_open(SEM1_NAME, 0, 0600, NULL);
		
		if (semaphore == SEM_FAILED) {
			printf("Error while getting the End of Program semaphore.\n");
			
			exit(EXIT_FAILURE);
		}
		
		sem_post(semaphore);
		
		return NULL;
	}
	
	pthread_t filter_tid;
	
	pthread_create(&filter_tid, NULL, filter_thread, exitQueue);
	
	while (( number = queue_get(entryQueue) ))	//	Get each number from the entry queue up until "0"
		if (number % first)	//	So far, the number is prime.
			queue_put(exitQueue, number);
	
	queue_put(exitQueue, 0);
	
	queue_destroy(entryQueue);
	
	return NULL;
}
开发者ID:joaodealmeida,项目名称:SOPE2,代码行数:57,代码来源:main.c


示例8: playlist_delete_internal

static void
playlist_delete_internal(struct playlist *playlist, unsigned song,
			 const struct song **queued_p)
{
	unsigned songOrder;

	assert(song < queue_length(&playlist->queue));

	songOrder = queue_position_to_order(&playlist->queue, song);

	if (playlist->playing && playlist->current == (int)songOrder) {
		bool paused = pc_get_state() == PLAYER_STATE_PAUSE;

		/* the current song is going to be deleted: stop the player */

		pc_stop();
		playlist->playing = false;

		/* see which song is going to be played instead */

		playlist->current = queue_next_order(&playlist->queue,
						     playlist->current);
		if (playlist->current == (int)songOrder)
			playlist->current = -1;

		if (playlist->current >= 0 && !paused)
			/* play the song after the deleted one */
			playlist_play_order(playlist, playlist->current);
		else
			/* no songs left to play, stop playback
			   completely */
			playlist_stop(playlist);

		*queued_p = NULL;
	} else if (playlist->current == (int)songOrder)
		/* there's a "current song" but we're not playing
		   currently - clear "current" */
		playlist->current = -1;

	/* now do it: remove the song */

	if (!song_in_database(queue_get(&playlist->queue, song)))
		pc_song_deleted(queue_get(&playlist->queue, song));

	queue_delete(&playlist->queue, song);

	/* update the "current" and "queued" variables */

	if (playlist->current > (int)songOrder) {
		playlist->current--;
	}
}
开发者ID:OpenInkpot-archive,项目名称:iplinux-mpd,代码行数:52,代码来源:playlist_edit.c


示例9: while

void *doSum(void *arg) {
  int sum = 0;
  Queue *queue = (Queue*)arg;


  Task *task = (Task*)queue_get(queue);
  while(task) {
    sum += task->value;
    free(task);

    task = (Task*)queue_get(queue);
  }

  pthread_exit((void*)(intptr_t)sum);
}
开发者ID:eamars,项目名称:ENCE360-Assignment-V2,代码行数:15,代码来源:queue_test.c


示例10: i2s_stm32_read

static int i2s_stm32_read(struct device *dev, void **mem_block, size_t *size)
{
	struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
	int ret;

	if (dev_data->rx.state == I2S_STATE_NOT_READY) {
		LOG_DBG("invalid state");
		return -EIO;
	}

	if (dev_data->rx.state != I2S_STATE_ERROR) {
		ret = k_sem_take(&dev_data->rx.sem, dev_data->rx.cfg.timeout);
		if (ret < 0) {
			return ret;
		}
	}

	/* Get data from the beginning of RX queue */
	ret = queue_get(&dev_data->rx.mem_block_queue, mem_block, size);
	if (ret < 0) {
		return -EIO;
	}

	return 0;
}
开发者ID:loicpoulain,项目名称:zephyr,代码行数:25,代码来源:i2s_ll_stm32.c


示例11: join_threads

void join_threads(void) {
    cnode *curnode;
    printf("joining threads...\n");
    while (numthreads) {
        pthread_mutex_lock(&cq.control.mutex);
        /* below, we sleep until there really is a new cleanup node.  This
           takes care of any false wakeups... even if we break out of
           pthread_cond_wait(), we don't make any assumptions that the
           condition we were waiting for is true.  */
        while (cq.cleanup.head==NULL) {
            pthread_cond_wait(&cq.control.cond,&cq.control.mutex);
        }
        /* at this point, we hold the mutex and there is an item in the
           list that we need to process.  First, we remove the node from
           the queue.  Then, we call pthread_join() on the tid stored in
           the node.  When pthread_join() returns, we have cleaned up
           after a thread.  Only then do we free() the node, decrement the
           number of additional threads we need to wait for and repeat the
           entire process, if necessary */
        curnode = (cnode *) queue_get(&cq.cleanup);
        pthread_mutex_unlock(&cq.control.mutex);
        pthread_join(curnode->tid,NULL);
        printf("joined with thread %d\n",curnode->threadnum);
        free(curnode);
        numthreads--;
    }
}
开发者ID:andrewpetrovic,项目名称:note,代码行数:27,代码来源:workcrew.c


示例12: get_ports

static int
get_ports(ClientData clientData,
              Tcl_Interp *interp,
              int argc,
              char *argv[])
{
    char msg[255];
    channel_t *chan;
    int i, n;

    memset(msg, 0, 255);
    n = queue_length(priv_c);
    Tcl_SetResult(interp,NULL,TCL_STATIC);
    for(i = 0; i < n; i++) {
        chan = (channel_t*)queue_get(priv_c, i, Q_KEEP);
        sprintf(msg, "%d", chan->port);
        Tcl_AppendElement(interp,msg);
    }

    UNUSED(clientData);
    UNUSED(argc);
    UNUSED(argv);

    return TCL_OK;
}
开发者ID:uclmediatools,项目名称:reflector,代码行数:25,代码来源:ui-controller.c


示例13: umask

void *write_thread(void *_ts) {
	struct ts *ts = _ts;
	struct packet *packet;

	mode_t umask_val = umask(0);
	dir_perm = (0777 & ~umask_val) | (S_IWUSR | S_IXUSR);

	set_thread_name("tsdump-write");
	while ((packet = queue_get(ts->packet_queue))) {
		if (!packet->data_len)
			continue;

		p_dbg1(" - Got packet %d, size: %u, file_time:%lu packet_time:%lu depth:%d\n",
			packet->num, packet->data_len, ALIGN_DOWN(packet->ts.tv_sec, ts->rotate_secs),
			packet->ts.tv_sec, ts->packet_queue->items);

		handle_files(ts, packet);

		if (ts->output_fd > -1) {
			p_dbg2(" - Writing into fd:%d size:%d file:%s\n", ts->output_fd, packet->data_len, ts->output_filename);
			ssize_t written = write(ts->output_fd, packet->data, packet->data_len);
			if (written != packet->data_len) {
				p_err("Can not write data (fd:%d written %zd of %d file:%s)",
					ts->output_fd, written, packet->data_len, ts->output_filename);
			}
		}
		free_packet(packet);
	}
	close_output_file(ts, NO_UNLINK);
	return NULL;
}
开发者ID:davidtsulaia,项目名称:tsdumper2,代码行数:31,代码来源:process.c


示例14: pthread_mutex_lock

void *threadfunc(void *myarg) {
    wnode *mywork;
    cnode *mynode;
    mynode=(cnode *) myarg;
    pthread_mutex_lock(&wq.control.mutex);
    while (wq.control.active) {
        while (wq.work.head==NULL && wq.control.active) {
            pthread_cond_wait(&wq.control.cond, &wq.control.mutex);
        }
        if (!wq.control.active)
            break;
        //we got something!
        mywork=(wnode *) queue_get(&wq.work);
        pthread_mutex_unlock(&wq.control.mutex);
        //perform processing...
        printf("Thread number %d processing job %d\n",mynode->threadnum,mywork->jobnum);
        free(mywork);
        pthread_mutex_lock(&wq.control.mutex);
    }
    pthread_mutex_unlock(&wq.control.mutex);
    pthread_mutex_lock(&cq.control.mutex);
    queue_put(&cq.cleanup,(node *) mynode);
    pthread_mutex_unlock(&cq.control.mutex);
    pthread_cond_signal(&cq.control.cond);
    printf("thread %d shutting down...\n",mynode->threadnum);
    return NULL;

}
开发者ID:andrewpetrovic,项目名称:note,代码行数:28,代码来源:workcrew.c


示例15: spl_save_queue

enum playlist_result
spl_save_queue(const char *name_utf8, const struct queue *queue)
{
	char *path_fs;
	FILE *file;

	if (map_spl_path() == NULL)
		return PLAYLIST_RESULT_DISABLED;

	if (!spl_valid_name(name_utf8))
		return PLAYLIST_RESULT_BAD_NAME;

	path_fs = map_spl_utf8_to_fs(name_utf8);
	if (path_fs == NULL)
		return PLAYLIST_RESULT_BAD_NAME;

	if (g_file_test(path_fs, G_FILE_TEST_EXISTS)) {
		g_free(path_fs);
		return PLAYLIST_RESULT_LIST_EXISTS;
	}

	file = fopen(path_fs, "w");
	g_free(path_fs);

	if (file == NULL)
		return PLAYLIST_RESULT_ERRNO;

	for (unsigned i = 0; i < queue_length(queue); i++)
		playlist_print_song(file, queue_get(queue, i));

	fclose(file);

	idle_add(IDLE_STORED_PLAYLIST);
	return PLAYLIST_RESULT_SUCCESS;
}
开发者ID:OpenInkpot-archive,项目名称:iplinux-mpd,代码行数:35,代码来源:playlist_save.c


示例16: SWI0_IRQHandler

void SWI0_IRQHandler(void)
{
    uint32_t err_code;

    while (!queue_is_empty(&m_evt_queue))
    {
        radio_evt_t evt;

        err_code = queue_get(&m_evt_queue, &evt.type);
        ASSUME_SUCCESS(err_code);

        switch (evt.type)
        {
            case PACKET_RECEIVED:
                err_code = rx_queue_get(&evt.packet);
                ASSUME_SUCCESS(err_code);
                break;

            default:
                break;
        }

        (*m_evt_handler)(&evt);
    }
}
开发者ID:hlnd,项目名称:nrf51-simple-radio,代码行数:25,代码来源:evt_queue.c


示例17: write_dqueue_worker

/* worker thread | glock: UNUSED */
void* write_dqueue_worker(void *arg) {
	struct timeval tv;
	uint32_t sec,usec,cnt;
	uint8_t *id;
	(void)arg;
	for (;;) {
		queue_get(dqueue,&sec,&usec,&id,&cnt);
		gettimeofday(&tv,NULL);
		if ((uint32_t)(tv.tv_usec) < usec) {
			tv.tv_sec--;
			tv.tv_usec += 1000000;
		}
		if ((uint32_t)(tv.tv_sec) < sec) {
			// time went backward !!!
			sleep(1);
		} else if ((uint32_t)(tv.tv_sec) == sec) {
			usleep(1000000-(tv.tv_usec-usec));
		}
		cnt--;
		if (cnt>0) {
			gettimeofday(&tv,NULL);
			queue_put(dqueue,tv.tv_sec,tv.tv_usec,(uint8_t*)id,cnt);
		} else {
			queue_put(jqueue,0,0,id,0);
		}
	}
	return NULL;
}
开发者ID:andyqzb,项目名称:shadow-mfs,代码行数:29,代码来源:writedata.c


示例18: audioTx_isr

/** audio tx isr  (to be called from dispatcher) 
 *   - get chunk from tx queue
 *    - if valid, release old pending chunk to buffer pool 
 *    - configure DMA 
 *    - if not valid, configure DMA to replay same chunk again
 * Parameters:
 * @param pThis  pointer to own object
 *
 * @return None 
 */
void audioTx_isr(void *pThisArg)
{
    // create local casted pThis to avoid casting on every single access
    audioTx_t  *pThis = (audioTx_t*) pThisArg;

    chunk_t *pchunk = NULL;

    // validate that TX DMA IRQ was triggered 
    if ( *pDMA4_IRQ_STATUS & 0x1  ) {
        //printf("[TXISR]\n");
        /* We need to remove the data from the queue and create space for more data
         * (The data was read previously by the DMA)

        1. First, attempt to get the new chunk, and check if it's available: */
    	if (PASS == queue_get(&pThis->queue, (void **)&pchunk) ) {
    		/* 2. If so, release old chunk on success back to buffer pool */
    		bufferPool_release(pThis->pBuffP, pThis->pPending);

    		/* 3. Register the new chunk as pending */
    		pThis->pPending = pchunk;

    	} else {
    		//printf("[Audio TX]: TX Queue Empty! \r\n");
    	}

        *pDMA4_IRQ_STATUS  |= DMA_DONE;     // Clear the interrupt

        // config DMA either with new chunk (if there was one), or with old chunk on empty Q
        audioTx_dmaConfig(pThis->pPending);
    }
}
开发者ID:tLiMiT,项目名称:TinCan-XBee-Phone,代码行数:41,代码来源:audioTx.c


示例19: queue_get

static void *waitq_thread(void *arg)
{
    Conn *start = NULL;
    Exec *e = arg;
    for (;;) {
        Conn *c = queue_get(e->waitq);
        if (c->io->stop) {
            start = NULL;
            conn_free(c);
        } else if (sys_iready(c->io, 0)) {
            start = NULL;
            queue_put(e->runq, c);
        } else if (sys_millis() - c->time > KEEP_ALIVE_MS) {
            start = NULL;
            conn_free(c);
        } else {
            if (start == c)                 /* we are in the wait-loop */
                queue_wait(e->waitq, 10);   /* wait for new connections */

            if (start == NULL)
                start = c;

            queue_put(e->waitq, c);
        }
    }

    return NULL;
}
开发者ID:bandilab,项目名称:bandicoot,代码行数:28,代码来源:bandicoot.c


示例20: print

void *connection_writer(void *arg) {
  msg_node *mn;
  message *msg;
  conn_node *c;
  
  c=(conn_node *) arg;
  
#ifndef NDEBUG
  print( DEBUG, "started (fd=%d, tid=%lu)", c->fd, pthread_self() );
#endif
  
  pthread_mutex_lock(&(c->outcoming.control.mutex));
  
  while(c->outcoming.control.active || c->outcoming.list.head) {
    
    while(!(c->outcoming.list.head) && c->outcoming.control.active) {
      pthread_cond_wait(&(c->outcoming.control.cond), &(c->outcoming.control.mutex));
    }
    
    mn = (msg_node *) queue_get(&(c->outcoming.list));
    
    if(!mn)
      continue;
    
    pthread_mutex_unlock(&(c->outcoming.control.mutex));
    
    pthread_mutex_lock(&(c->control.mutex));
    
    while(c->freeze) {
      pthread_cond_wait(&(c->control.cond), &(c->control.mutex));
    }
    
    pthread_mutex_unlock(&(c->control.mutex));
    
    msg = mn->msg;
    
    if(send_message(c->fd, msg)) {
      print( ERROR, "cannot send the following message" );
      dump_message(msg);
    }
    
    free_message(msg);
    free(mn);
    
    pthread_mutex_lock(&(c->outcoming.control.mutex));
  }
  
  pthread_mutex_unlock(&(c->outcoming.control.mutex));
  
  pthread_mutex_lock(&(c->control.mutex));
  c->writer_done=1;
  pthread_mutex_unlock(&(c->control.mutex));
  
  pthread_cond_broadcast(&(c->control.cond));
  
  send_me_to_graveyard();
  
  return 0;
}
开发者ID:Katarzynasrom,项目名称:daemon,代码行数:59,代码来源:connection.c



注:本文中的queue_get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ queue_init函数代码示例发布时间:2022-05-30
下一篇:
C++ queue_flag_set_unlocked函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap