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

C++ queue_size函数代码示例

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

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



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

示例1: pthread_mutex_lock

/*
*функция производителя: читает файл строка за строкой
*в каждой строке выделяет числа, суммирует их
*и кладет результат в общий буфер - queueSource
*/
static void *producer(void* arg)
{   pthread_mutex_lock(myMutex);
		//если очередь переполнена, то производитель ждет, чтобы потребитель снял оттуда элемент
    while(queue_size(queueSource) > 100)
			pthread_cond_wait(onTakeCondition, myMutex);
    //парсит строку    
		char *line = NULL; int temp;
		size_t len = 0;
		ssize_t read;
    while ((read = getline(&line, &len, f)) != -1) {
          char *token;
          char *rest = line;
          int sumIntoStr = 0;
          token = strtok(rest, " ");
					while(token != NULL){
							temp = atoi(token);
							sumIntoStr += temp;
							token = strtok(NULL, " ");
					}
					printf("in producer: %d\n", sumIntoStr);
          //кладём сумму строки в очередь
          queue_enqueue(queueSource, sumIntoStr);
					if (queue_size(queueSource) - 1 <= 0) //очередь была пустая, а теперь нет - об этом нужно оповестить потребителя
					pthread_cond_signal(onPutCondition);
    }
		pthread_mutex_unlock(myMutex);
}
开发者ID:MarkovaDA,项目名称:ProducerConsumer1,代码行数:32,代码来源:task.c


示例2: void

/**
 * Calls appropriate callback functions for a given rule.
 *
 * @param rules Queue of rules.
 * @param notify_target Callback function for targets.
 * @param notify_dep Callback function for dependencies.
 * @param notify_cmd Callback function for commands.
 * @return Void.
 */
static void notifyRules
(
	queue_t *rules,
	void (*notify_target)(char *),
	void (*notify_dep)(char *,char *),
	void (*notify_cmd)(char *, char *)
)
{
	int ruleIdx, i;
	
	for(ruleIdx=0; ruleIdx < queue_size(rules); ruleIdx++){

		rule_t *curRule = queue_at(rules, ruleIdx);
		notify_target(curRule->target);

		for(i=0; i < queue_size(curRule->deps); i++){
			char *dep = queue_at(curRule->deps, i);
			notify_dep(curRule->target, dep);
		}
		
		for(i=0; i < queue_size(curRule->commands); i++){
			char *cmd = queue_at(curRule->commands, i);
			notify_cmd(curRule->target, cmd);
		}
	}
}
开发者ID:JLLLinn,项目名称:System-Programming,代码行数:35,代码来源:parser.c


示例3: handlecc

/* callback function to catch and handle ctrl+c
 *
 * @param - int signal
 * @return - all threads terminate, each closing their socket, and any memory left unfreed is now freed
 */
void handlecc(int sig)
{
	while(queue_size(clients))
	{
		int *temp=queue_dequeue(clients);
		shutdown(*temp, 2);
		free(temp);
	}
	while(queue_size(tids))
	{
		pthread_t *tid=queue_dequeue(tids);
		void **dummy;
		pthread_join(*tid, dummy);
	}
	queue_destroy(tids);
	queue_destroy(clients);
	free(tids);
	free(clients);
	pthread_mutex_destroy(lock);
	free(lock);


	exit(0);
	return;		//should never be reached
}
开发者ID:amshah4,项目名称:cs241mpx,代码行数:30,代码来源:server.c


示例4: addToML

/*******************************************************************************
 * @author	: Rohan Jyoti
 * @name	: addToML
 * @param	: Membership List to add to, Payload to add
 * @return	: void
 * @purpose	: Add a payload if it is non-existant in the memebrship list
 ******************************************************************************/
void addToML(queue_t *incomingML, mPayload_t *incomingPayload)
{	
	if(queue_size(incomingML) == 0)
	{
		//time(&incomingPayload->hb_timestamp);
		incomingPayload->udp_socket = -1;
		queue_enqueue(incomingML, (void *)incomingPayload);
	}
	else
	{
		//Recall that it is the IP address combined with the port that is unique
		char *ip_addr = incomingPayload->IP_address;
		int tPort = incomingPayload->port;
		
		unsigned int i;
		for(i=0; i<queue_size(incomingML); i++)
		{
			mPayload_t *tempPayload = (mPayload_t *)queue_at(incomingML, i);
			if((strcmp(ip_addr, tempPayload->IP_address) == 0) && (tPort == tempPayload->port))
				return; //meaning payload already exists in ML
		}
		
		//reach here indicating that payload not in ML
		//time(&incomingPayload->hb_timestamp);
		incomingPayload->udp_socket = -1;
		queue_enqueue(incomingML, (void *)incomingPayload);
	}
}
开发者ID:RohanJ,项目名称:DistributedFileSystem,代码行数:35,代码来源:payload.c


示例5: remove_item_test

int remove_item_test(void)
{
  clear_queue();
  insert_item(42);
  _assert(front() == 42);
  _assert(queue_size() == 1);

  _assert(remove_item() == 42);
  _assert(queue_size() == 0);
  _assert(is_empty() == true);

  insert_item(12);
  insert_item(13);
  insert_item(14);

  _assert(front() == 12);
  _assert(rear() == 14);
  _assert(queue_size() == 3);

  _assert(remove_item() == 12);
  _assert(front() == 13);
  _assert(rear() == 14);
  _assert(queue_size() == 2);

  _assert(remove_item() == 13);
  _assert(front() == 14);
  _assert(rear() == 14);
  _assert(queue_size() == 1);

  clear_queue();
  return 0;
}
开发者ID:Blaise2016,项目名称:c-programming,代码行数:32,代码来源:global-queue-spec.c


示例6: queue_push

int
queue_push(Queue * q, int value)
{
  int newhead;

  assert(q != NULL);
#ifdef QUEUE_STATS
  q->push_count++;
  q->push_total_size += queue_size(q);
#endif
  if (q->head == 0) {
    newhead = q->arraysize - 1;
  } else {
    newhead = q->head - 1;
  }
  if (newhead == q->tail) {
    return -1;  // queue is full
  }
  q->head = newhead;
  q->data[newhead] = value;
  q->elements++;

  assert(q->elements == queue_size(q));

  return 0;
}
开发者ID:iscmu2012,项目名称:WebServerEval,代码行数:26,代码来源:queue.c


示例7: multi_job_check

void multi_job_check (struct queue *queue)
{

    zlist_t *newjobs;
    json_t *jobs;

    ok (queue_size (queue) == 0,
        "queue is initially empty");
    if (!(jobs = json_pack ("[{s:I s:i s:i s:f s:i},"
                             "{s:I s:i s:i s:f s:i}]",
                            "id", 1,
                            "priority", 10,
                            "userid", 42,
                            "t_submit", 1.0,
                            "flags", 0,
                            "id", 2,
                            "priority", 11,
                            "userid", 43,
                            "t_submit", 1.1,
                            "flags", 1)))
        BAIL_OUT ("json_pack() failed");

    newjobs = submit_enqueue_jobs (queue, jobs);
    ok (newjobs != NULL,
        "submit_enqueue_jobs works");
    ok (queue_size (queue) == 2,
        "queue contains 2 jobs");
    ok (zlist_size (newjobs) == 2,
        "newjobs contains 2 jobs");
    submit_enqueue_jobs_cleanup (queue, newjobs);
    ok (queue_size (queue) == 0,
        "submit_enqueue_jobs_cleanup removed queue entries");

    json_decref (jobs);
}
开发者ID:flux-framework,项目名称:flux-core,代码行数:35,代码来源:submit.c


示例8: main

int main(void)
{
    Student s1 = {45, "hello"},
            s2 = {49, "world"}, * sptr;
    pQueue q = queue_new(sizeof(int));
    pQueue ps = queue_new(sizeof(Student));

    int value = 10, v = 12, *ip;
    queue_enqueue(q, &value);
    queue_enqueue(q, &v);
    ip = (int *)queue_front(q);
    printf("%d\n", *ip);
    queue_dequeue(q);
    ip = (int *)queue_front(q);
    printf("%d\n", *ip);
    queue_free(q);

    queue_enqueue(ps, &s1);
    queue_enqueue(ps, &s2);
    printf("queue size: %ld\n", queue_size(ps));
    sptr = (Student *)queue_front(ps);
    printf("no: %d, name: %s\n", sptr->no, sptr->name);
    queue_dequeue(ps);
    printf("queue size: %ld\n", queue_size(ps));
    sptr = (Student *)queue_front(ps);
    printf("no: %d, name: %s\n", sptr->no, sptr->name);
    queue_free(ps);
    exit(EXIT_SUCCESS);
}
开发者ID:qyh,项目名称:studio,代码行数:29,代码来源:Queue[1].c


示例9: queue_put

int
queue_put(Queue * q, int value)
{
  int newtail;
#ifdef QUEUE_STATS
  int size;
#endif

  assert(q != NULL);
#ifdef QUEUE_STATS
  q->put_count++;
  size = queue_size(q);
  if (size > q->put_max_size) {
    assert(size == q->put_max_size + 1);
    q->put_max_size = size;
  }
  q->put_total_size += size;
#endif
  newtail = (q->tail + 1) % q->arraysize;
  if (newtail == q->head) {
    return -1;  // queue is full
  }
  q->data[q->tail] = value;
  q->tail = newtail;
  q->elements++;

  assert(q->elements == queue_size(q));

  return 0;
}
开发者ID:iscmu2012,项目名称:WebServerEval,代码行数:30,代码来源:queue.c


示例10: device_read

static ssize_t device_read(struct file * fp, char __user * up, size_t sz, loff_t * off)
{
size_t out_sz = 0;

if( MINOR( fp->f_dentry->d_inode->i_rdev ) > MINOR_COUNT )
	{
	printk( KERN_ALERT "Bad Minor number in inode\n" );
	return out_sz;
	}

switch( MINOR( fp->f_dentry->d_inode->i_rdev ) )
	{
	case MINOR_META:
		//
		break;

	case MINOR_RX:
		while( sz && queue_size( &rx_queue ) )
			{
			put_user( queue_pop( &rx_queue ), up++ );
			out_sz++;
			}
		break;

	case MINOR_TX:
		while( sz && queue_size( &tx_queue ) )
			{
			put_user( queue_pop( &tx_queue ), up++ );
			out_sz++;
			}
		break;
	}

return 0;
}
开发者ID:rsaxvc,项目名称:serial_snooper,代码行数:35,代码来源:serial_snooper.c


示例11: _CONNECT

void _CONNECT(int sd){

  dem.procCounter++;

  printf("CONNECT (QUEUESIZE   :%d)\n",queue_size());
  printf("        (NUM OF PROCS:%d)\n",dem.procCounter);

  proc_data* sendProc;
  proc* p;

  sendProc = (proc_data*)malloc(sizeof(proc_data));
  p = get_proc(sd);

  if(queue_size() > 0 || dem.procCounter > MAXPROC){

    sendProc->REQUEST = CANNOTENTER;
    p->queued = 1;

  }else{

    sendProc->REQUEST = CONNECT;

    usleep(500000);//1.0[sec]

  }

  send(sd,sendProc,sizeof(proc_data),0);
}
开发者ID:tbrand,项目名称:MobileCUDA,代码行数:28,代码来源:connect.c


示例12: puts

void *consumer(void *data)
{
    struct wsqueue *queue = data;

    puts("start consume loop");
    while (cont || queue_size(&queue->squeue.queue)) {
        struct list_node *node;

        pthread_mutex_lock(&queue->squeue.mutex);
        while (cont && !queue_size(&queue->squeue.queue))
            pthread_cond_wait(&queue->cond, &queue->squeue.mutex);
        pthread_mutex_unlock(&queue->squeue.mutex);

        node = wsqueue_pop(queue);
        if (node) {
            struct payload *data = (struct payload *)node;
            printf("consumer got value %d\n", data->data);
            free(node);
        }
    }

    puts("finish consume loop");

    return NULL;
}
开发者ID:ordian,项目名称:Programming-Paradigms,代码行数:25,代码来源:msgqueue.c


示例13: imprime

void imprime(){
	int area,i;
	aux = NULL;

	printf("%d-%d",tempo,(tempo+1));
	for(area = 0; area < qtd_Tprocess; area++){

		if (processes!= NULL){
			iterador = processes;
			for(i = 0; i < queue_size((queue_t *) processes); i++){
				if (iterador->id == area) aux = iterador;
				else iterador = iterador->next;
			}
		}


		if (ready!= NULL){
			iterador = ready;
			for(i = 0; i < queue_size((queue_t *) ready); i++){
				if (iterador->id == area) aux = iterador;
				else iterador = iterador->next;
			}
		}

		if (processo_corrente != NULL){
			if (processo_corrente->id == area){
				aux = processo_corrente;
				processo_corrente->tempo_executado_total++;
			}
		}

		if (finesh!= NULL){
			iterador = finesh;
			for(i = 0; i < queue_size((queue_t *) finesh); i++){
				if (iterador->id == area) aux = iterador;
				else iterador = iterador->next;
			}
		}

		if (aux != NULL){
			switch (aux->estado_atual){ // 0 - nova, 1 - pronta, 2 - rodando, 3 - terminada
				case 0:
					printf("\t");
					break;
				case 1:
					printf("\t--");
					tempo_medio_espera++;
					break;
				case 2:
					printf("\t##");
					break;
				case 3:
					printf("\t");
					break;
			}
		}
	}
	printf("\n");
}
开发者ID:Bonssons,项目名称:CEFET-Operating-Systems,代码行数:59,代码来源:sjf.c


示例14: init_pingpong_queue

int32_t init_pingpong_queue(struct pingpong_queue *ppq,char *name,int32_t (*action)(),queue_t *destq,queue_t *errorq)
{
    ppq->name = name;
    ppq->destqueue = destq;
    ppq->errorqueue = errorq;
    ppq->action = action;
    ppq->offset = 1;
    return(queue_size(&ppq->pingpong[0]) + queue_size(&ppq->pingpong[1]));  // init mutex side effect
}
开发者ID:destenson,项目名称:jl777--btcd,代码行数:9,代码来源:system777.c


示例15: Has_command_to_run

/**
 * Determines if tgdb has commands it needs to run.
 *
 * \return
 * true if can issue directly to gdb. Otherwise false.
 */
bool Ctgdb::Has_command_to_run()
{
	if (tgdb_client_is_client_ready (tcc) && 
			((queue_size (gdb_input_queue) > 0) ||
			 (queue_size (oob_input_queue) > 0)))
		return true;

	return false;
}
开发者ID:amberik,项目名称:cgdb-initial.cgdb-featured,代码行数:15,代码来源:CTgdb.cpp


示例16: compute_to

void compute_to(sieve *s, int max)
{
	s->max = max;
	s->numbers = malloc(sizeof(struct linked_queue));
	s->prime = malloc(sizeof(struct linked_queue));

	int i;
	for (i = 2; i <= max; i++)
	{
		enqueue(s->numbers, i);
	}

	int p;
	queue *temp = malloc(sizeof( struct linked_queue));

	do {
		//obtain the next prime p by removing the first value in the queue of numbers.
		p = dequeue(s->numbers);
		//put p into the queue of primes.
		enqueue(s->prime, p);


		int size = queue_size(s->numbers);
		int x;
		//go through the queue of numbers, eliminating numbers divisible by p.
		for (x = 0; x < size; x++)
		{
			int t = dequeue(s->numbers);

			if (t % p != 0)
			{
				enqueue(temp, t);
			}
		}
		// Put stored prime values into the numbers queue.
		s->numbers = temp;

	} while (p < sqrt(max));

	// all remaining values in numbers queue are prime, so transfer them to primes queue
	int size = queue_size(s->numbers);
	int z;
	for (z = 0; z < size; z++)
	{
		enqueue(s->prime, dequeue(s->numbers));
	}

	// Returns numbers queue to original state.
	for (i = 2; i <= max; i++)
	{
		enqueue(s->numbers, i);
	}

	temp = NULL;
	free(temp);
}
开发者ID:Ag8833,项目名称:TCES-202-Advanced-Computer-Programming,代码行数:56,代码来源:sieve.c


示例17: depsAreFiles

int depsAreFiles(queue_t * dep){
	int i= 0;
	if(queue_size(dep) <= 0)
		return 0;
	for( ; i < queue_size(dep); i++){
		if(isRule(queue_at(dep, i)))
			return 0;
	}
	return 1;
}
开发者ID:MrTerrorbyte,项目名称:cs241-fa13,代码行数:10,代码来源:parmake.c


示例18: queue_check

void queue_check(){
    printf("Testing Queue Functions\n");
    Queue *q;
    q = queue_init(); assert_i(queue_size(q), 0, "Check Queue Size after init");

    queue_enqueue(q, 1, -1); assert_i(queue_size(q), 1, "Check Queue Size after Enqueue");
    queue_enqueue(q, 2, -2); assert_i(queue_size(q), 2, "Check Queue Size after Enqueue");
    queue_enqueue(q, 3, -3); assert_i(queue_size(q), 3, "Check Queue Size after Enqueue");

    int x, y;
    queue_dequeue(q, &x, &y);
        assert_p(x, y, 1, -1, "Check Dequeue");
        assert_i(queue_size(q), 2, "Check Size after Dequeue");
    queue_dequeue(q, &x, &y);
        assert_p(x, y, 2, -2, "Check Dequeue");
        assert_i(queue_size(q), 1, "Check Size after Dequeue");

    queue_enqueue(q, 6, -6); assert_i(queue_size(q), 2, "Check Queue Size after Enqueue");
    queue_dequeue(q, &x, &y);
        assert_p(x, y, 3, -3, "Check Dequeue");
        assert_i(queue_size(q), 1, "Check Size after Dequeue");
    queue_dequeue(q, &x, &y);
        assert_p(x, y, 6, -6, "Check Dequeue");
        assert_i(queue_size(q), 0, "Check Size after Dequeue");

    queue_free(q);
}
开发者ID:TRex22,项目名称:DDS_Group_Work,代码行数:27,代码来源:main.c


示例19: while

void *run_thread(void *args)
{
	arg_t *run_args = (arg_t *)args;
	
	while(1)
	{
		if (queue_size(run_args->ready_r) == 0 && 
			queue_size(run_args->rest_r) == 0)
		{
			return NULL;	
		}
		sem_wait(run_args->ready_sem);
		while(queue_size(run_args->ready_r) == 0)
		{
			if (queue_size(run_args->ready_r) == 0 && 
				queue_size(run_args->rest_r) == 0)
			{
				sem_post(run_args->ready_sem);
				return NULL;	
			}
			sem_wait(run_args->ready_sem);
		}
		rule_t *rule;
		pthread_mutex_lock(run_args->m);
		rule = queue_dequeue(run_args->ready_r);
		pthread_mutex_unlock(run_args->m);

		while(queue_size(rule->commands))
		{
			char *command = queue_dequeue(rule->commands);
			if (system(command) != 0)
			{
				exit(1);	
			}
			free(command);
		}

		char *temp = rule->target;
		while(queue_size(rule->deps))
		{
			char *dep = queue_dequeue(rule->deps);
			free(dep);
		}
		rule_destroy(rule);
		free(rule);
		
		pthread_mutex_lock(run_args->m);
		int pSize = queue_size(run_args->ready_r);
		queue_enqueue(run_args->complete_t, temp);
		process_queues(run_args->rest_r, run_args->ready_r, run_args->complete_t);
		int cSize = queue_size(run_args->ready_r);
		pthread_mutex_unlock(run_args->m);
		int i;
		for(i = 0; i < cSize - pSize; i++)
		{
			sem_post(run_args->ready_sem);
		}
		sem_post(run_args->ready_sem);
	}
}
开发者ID:Xuefeng-Zhu,项目名称:parallel-make,代码行数:60,代码来源:parmake.c


示例20: action

void DLL_EXPORT action(queue_t * action_object){
    puts("IT'S OVER 50!");
int sum = 100;
while(sum>=50&&queue_size(action_object)>0){
    sum=0;
    queue_remove(action_object);
    for(int i = 0; i < queue_size(action_object); i++)
    sum+=queue_get(action_object,i);
}
printf("SUM AFTER REMOVING %i\n", sum);
}
开发者ID:lorvis,项目名称:study,代码行数:11,代码来源:main.cpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ queue_task函数代码示例发布时间:2022-05-30
下一篇:
C++ queue_push函数代码示例发布时间: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