当前位置: 首页>>代码示例>>C++>>正文


C++ queue_get函数代码示例

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


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


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