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


C++ pthread_create函数代码示例

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


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

示例1: sync_worker_init

int sync_worker_init(struct bladerf_sync *s)
{
    int status = 0;
    s->worker = (struct sync_worker*) calloc(1, sizeof(*s->worker));

    if (s->worker == NULL) {
        status = BLADERF_ERR_MEM;
        goto worker_init_out;
    }

    s->worker->state = SYNC_WORKER_STATE_STARTUP;
    s->worker->cb = s->stream_config.module == BLADERF_MODULE_RX ?
                        rx_callback : tx_callback;

    status = bladerf_init_stream(&s->worker->stream,
                                 s->dev,
                                 s->worker->cb,
                                 &s->buf_mgmt.buffers,
                                 s->buf_mgmt.num_buffers,
                                 s->stream_config.format,
                                 s->stream_config.samples_per_buffer,
                                 s->stream_config.num_xfers,
                                 s);

    if (status != 0) {
        log_debug("%s worker: Failed to init stream: %s\n", MODULE_STR(s),
                  bladerf_strerror(status));
        goto worker_init_out;
    }


    status = pthread_mutex_init(&s->worker->state_lock, NULL);
    if (status != 0) {
        status = BLADERF_ERR_UNEXPECTED;
        goto worker_init_out;
    }

    status = pthread_cond_init(&s->worker->state_changed, NULL);
    if (status != 0) {
        status = BLADERF_ERR_UNEXPECTED;
        goto worker_init_out;
    }

    status = pthread_mutex_init(&s->worker->request_lock, NULL);
    if (status != 0) {
        status = BLADERF_ERR_UNEXPECTED;
        goto worker_init_out;
    }

    status = pthread_cond_init(&s->worker->requests_pending, NULL);
    if (status != 0) {
        status = BLADERF_ERR_UNEXPECTED;
        goto worker_init_out;
    }

    status = pthread_create(&s->worker->thread, NULL, sync_worker_task, s);
    if (status != 0) {
        status = BLADERF_ERR_UNEXPECTED;
        goto worker_init_out;
    }

    /* Wait until the worker thread has initialized and is ready to go */
    status = sync_worker_wait_for_state(s->worker, SYNC_WORKER_STATE_IDLE, 1000);
    if (status != 0) {
        status = BLADERF_ERR_TIMEOUT;
        goto worker_init_out;
    }

worker_init_out:
    if (status != 0) {
        free(s->worker);
        s->worker = NULL;
    }

    return status;
}
开发者ID:manfiS,项目名称:private,代码行数:76,代码来源:sync_worker.c

示例2: main

int main(void)
{
	pthread_t tid1, tid2, tid3, tid4;
	void *res;
	int err;
	
	err = pthread_create(&tid1, NULL, tfn1, NULL);	
	if (err != 0) {
		printf("can't create thread %s\n", strerror(err));
		exit(1);	
	}

	err = pthread_join(tid1, &res);
	if (err != 0) {
		printf("can't join thread %s\n", strerror(err));
		exit(1);	
	}
	printf("lst result: %d, %d\n", ((struct a *)res)->b, ((struct a *)res)->c);

	err = pthread_create(&tid2, NULL, tfn2, NULL);	
	if (err != 0) {
		printf("can't create thread %s\n", strerror(err));
		exit(1);	
	}

	err = pthread_join(tid2, &res);
	if (err != 0) {
		printf("can't join thread %s\n", strerror(err));
		exit(1);	
	}
	printf("2nd result: %d, %d\n", ((struct a *)res)->b, ((struct a *)res)->c);
	free(res);

	err = pthread_create(&tid3, NULL, tfn3, NULL);	
	if (err != 0) {
		printf("can't create thread %s\n", strerror(err));
		exit(1);	
	}

	err = pthread_join(tid3, &res);
	if (err != 0) {
		printf("can't join thread %s\n", strerror(err));
		exit(1);	
	}
	printf("3rd result: %d, %d\n", ((struct a *)res)->b, ((struct a *)res)->c);

	struct a *p;
	p = (struct a *)malloc(sizeof(struct a));
	p->b = 10;
	p->c = 11;

	err = pthread_create(&tid4, NULL, tfn4, (void *)p);	
	if (err != 0) {
		printf("can't create thread %s\n", strerror(err));
		exit(1);	
	}

	err = pthread_join(tid4, &res);
	if (err != 0) {
		printf("can't join thread %s\n", strerror(err));
		exit(1);	
	}
	printf("4th result: %d, %d\n", ((struct a *)res)->b, ((struct a *)res)->c);
	free(p);

	return 0;
}
开发者ID:nmred,项目名称:study_test,代码行数:67,代码来源:thread_exit_status.c

示例3: Active

void *phy_layer_server(void *num){

	cout<<"Physical Active(PHY)"<<endl;
	//Setup Socket
        int sockfd, portno;
        socklen_t clilen;
        void *newsockfd;
        struct sockaddr_in serv_addr, cli_addr;
        sockfd = socket(AF_INET, SOCK_STREAM, 0);
        if (sockfd < 0)
                diewithError("ERROR opening socket");
        bzero((char *) &serv_addr, sizeof(serv_addr));
        portno = PORT;

	//Basic Socket Parameters
        serv_addr.sin_family = AF_INET;
        serv_addr.sin_addr.s_addr = INADDR_ANY;
        serv_addr.sin_port = htons(portno);
        if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
                diewithError("ERROR on binding");
        listen(sockfd, 5);
        clilen = sizeof(cli_addr);

	//Threads
	int *socket[10];
	pthread_t phy_layer_thread[10];

	int client=0;
	int rc;

	try{
		while(1){
			//Wait for clients
			socket[client]=(int *) malloc(sizeof(int));
			cout<<"Waiting for clients (PHY)"<<endl;
			*socket[client]=accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
			cout<<"Socket Accepted (PHY)"<<endl;
	    
			 // Mark the socket as non-blocking, for safety.
			int x;
			x=fcntl(*socket[client],F_GETFL,0);
			fcntl(*socket[client],F_SETFL,x | O_NONBLOCK);
			if(*socket[client]==-1) diewithError("Could not connect to client");
			cout<<"Socket Made non-blocking (PHY)"<<endl;

			//Spawn Thread
			rc = pthread_create( &phy_layer_thread[client], NULL, phy_layer_t, (void*) socket[client]);
			if(rc)diewithError("ERROR; return code from pthread_create()");
			cout<<"Thread spawned for client (PHY)"<<endl;
			client++;

		}
	}
	//Something went wrong :(
	catch(int e) {
		//Stop threads
		for(int i=0;i<client;i++)
			pthread_cancel(phy_layer_thread[i]);
    	}
	return 0;

}
开发者ID:travisfcollins,项目名称:ECE506_Project,代码行数:62,代码来源:phy_q_server_multi.cpp

示例4: at_open

/**
 * Starts AT handler on stream "fd'
 * returns 0 on success, -1 on error
 */
int at_open(int fd, ATUnsolHandler h)
{
    int ret;
    pthread_t tid;
    pthread_attr_t attr;

    s_fd = fd;
    s_unsolHandler = h;
    s_readerClosed = 0;

    s_responsePrefix = NULL;
    s_smsPDU = NULL;
    sp_response = NULL;

    /* Android power control ioctl */
#ifdef HAVE_ANDROID_OS
#ifdef OMAP_CSMI_POWER_CONTROL
    ret = ioctl(fd, OMAP_CSMI_TTY_ENABLE_ACK);
    if(ret == 0) {
        int ack_count;
		int read_count;
        int old_flags;
        char sync_buf[256];
        old_flags = fcntl(fd, F_GETFL, 0);
        fcntl(fd, F_SETFL, old_flags | O_NONBLOCK);
        do {
            ioctl(fd, OMAP_CSMI_TTY_READ_UNACKED, &ack_count);
			read_count = 0;
            do {
                ret = read(fd, sync_buf, sizeof(sync_buf));
				if(ret > 0)
					read_count += ret;
            } while(ret > 0 || (ret < 0 && errno == EINTR));
            ioctl(fd, OMAP_CSMI_TTY_ACK, &ack_count);
         } while(ack_count > 0 || read_count > 0);
        fcntl(fd, F_SETFL, old_flags);
        s_readCount = 0;
        s_ackPowerIoctl = 1;
    }
    else
        s_ackPowerIoctl = 0;

#else // OMAP_CSMI_POWER_CONTROL
    s_ackPowerIoctl = 0;

#endif // OMAP_CSMI_POWER_CONTROL
#endif /*HAVE_ANDROID_OS*/

    pthread_attr_init (&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    ret = pthread_create(&s_tid_reader, &attr, readerLoop, &attr);

    if (ret < 0) {
        perror ("pthread_create");
        return -1;
    }


    return 0;
}
开发者ID:checko,项目名称:sxx-ril,代码行数:65,代码来源:atchannel.c

示例5: pthread_attr_init

bool OThread::Start(void *pParam, int Priority, int affinity)
{
 if(m_bRunning)
  return true;

 m_pParam = pParam;


 m_bShutdown = false;
 int max_priority;
 int min_priority;
 int mid_priority;
 int min_max_diff;
 int min_max_diff_quarter;
 
 struct sched_param SchedVal;
 int iRetVal;
 pthread_attr_t attr;
  
 pthread_attr_init(&attr);
 
 iRetVal = pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
 
 if(iRetVal != 0)
 	return false;
 
 max_priority = sched_get_priority_max(SCHED_OTHER);
 min_priority = sched_get_priority_min(SCHED_OTHER);
 
 min_max_diff = max_priority - min_priority;
 mid_priority = (min_max_diff / 2) + min_priority;
 min_max_diff_quarter = min_max_diff / 4;
  
 switch(Priority)
 {
 	case THREAD_PRIORITY_ABOVE_NORMAL:
 	
 		SchedVal.sched_priority = max_priority - min_max_diff_quarter;
 	
 		break;
 	
 	case THREAD_PRIORITY_BELOW_NORMAL:
 	
 	    SchedVal.sched_priority = min_priority + min_max_diff_quarter;
 	    
 		break;
 	
 	case THREAD_PRIORITY_HIGHEST:
 	case THREAD_PRIORITY_TIME_CRITICAL:
 	
 		SchedVal.sched_priority = max_priority;
 	
 		break;
 		  
 	case THREAD_PRIORITY_IDLE:    
 	
 		SchedVal.sched_priority = min_priority;
 	
 		break;
 	
 	case THREAD_PRIORITY_NORMAL:
  	default:
 	
 		SchedVal.sched_priority = mid_priority;
 	 	
 		break; 	
 }

 if(SchedVal.sched_priority < min_priority)
 	SchedVal.sched_priority = min_priority;
 
 if(SchedVal.sched_priority > max_priority)
 	SchedVal.sched_priority = max_priority;
 	
 iRetVal = pthread_attr_setschedparam(&attr, &SchedVal);
 
 if(iRetVal != 0)
 	return false;
  
 iRetVal = pthread_create(&m_thread, NULL, CThreadRunFunction, this);

 if(iRetVal != 0)
 	return false;

 m_bRunning = true;

 return true;


}
开发者ID:drewhearle,项目名称:icsneoapi,代码行数:90,代码来源:OThread.cpp

示例6: alsa_init

/*static*/ int
alsa_init(cubeb ** context, char const * context_name)
{
  cubeb * ctx;
  int r;
  int i;
  int fd[2];
  pthread_attr_t attr;
  snd_pcm_t * dummy;

  assert(context);
  *context = NULL;

  pthread_mutex_lock(&cubeb_alsa_mutex);
  if (!cubeb_alsa_error_handler_set) {
    snd_lib_error_set_handler(silent_error_handler);
    cubeb_alsa_error_handler_set = 1;
  }
  pthread_mutex_unlock(&cubeb_alsa_mutex);

  ctx = calloc(1, sizeof(*ctx));
  assert(ctx);

  ctx->ops = &alsa_ops;

  r = pthread_mutex_init(&ctx->mutex, NULL);
  assert(r == 0);

  r = pipe(fd);
  assert(r == 0);

  for (i = 0; i < 2; ++i) {
    fcntl(fd[i], F_SETFD, fcntl(fd[i], F_GETFD) | FD_CLOEXEC);
    fcntl(fd[i], F_SETFL, fcntl(fd[i], F_GETFL) | O_NONBLOCK);
  }

  ctx->control_fd_read = fd[0];
  ctx->control_fd_write = fd[1];

  /* Force an early rebuild when alsa_run is first called to ensure fds and
     nfds have been initialized. */
  ctx->rebuild = 1;

  r = pthread_attr_init(&attr);
  assert(r == 0);

  r = pthread_attr_setstacksize(&attr, 256 * 1024);
  assert(r == 0);

  r = pthread_create(&ctx->thread, &attr, alsa_run_thread, ctx);
  assert(r == 0);

  r = pthread_attr_destroy(&attr);
  assert(r == 0);

  /* Open a dummy PCM to force the configuration space to be evaluated so that
     init_local_config_with_workaround can find and modify the default node. */
  r = alsa_locked_pcm_open(&dummy, SND_PCM_STREAM_PLAYBACK, NULL);
  if (r >= 0) {
    alsa_locked_pcm_close(dummy);
  }
  ctx->is_pa = 0;
  pthread_mutex_lock(&cubeb_alsa_mutex);
  ctx->local_config = init_local_config_with_workaround(CUBEB_ALSA_PCM_NAME);
  pthread_mutex_unlock(&cubeb_alsa_mutex);
  if (ctx->local_config) {
    ctx->is_pa = 1;
    r = alsa_locked_pcm_open(&dummy, SND_PCM_STREAM_PLAYBACK, ctx->local_config);
    /* If we got a local_config, we found a PA PCM.  If opening a PCM with that
       config fails with EINVAL, the PA PCM is too old for this workaround. */
    if (r == -EINVAL) {
      pthread_mutex_lock(&cubeb_alsa_mutex);
      snd_config_delete(ctx->local_config);
      pthread_mutex_unlock(&cubeb_alsa_mutex);
      ctx->local_config = NULL;
    } else if (r >= 0) {
      alsa_locked_pcm_close(dummy);
    }
  }

  *context = ctx;

  return CUBEB_OK;
}
开发者ID:AtulKumar2,项目名称:gecko-dev,代码行数:84,代码来源:cubeb_alsa.c

示例7: stream_enable_cache

/**
 * \return 1 on success, 0 if the function was interrupted and -1 on error
 */
int stream_enable_cache(stream_t *stream,int64_t size,int64_t min,int64_t seek_limit){
  int ss = stream->sector_size ? stream->sector_size : STREAM_BUFFER_SIZE;
  int res = -1;
  cache_vars_t* s;

  if (stream->flags & STREAM_NON_CACHEABLE) {
    mp_msg(MSGT_CACHE,MSGL_STATUS,"\rThis stream is non-cacheable\n");
    return 1;
  }
  if (size > SIZE_MAX) {
    mp_msg(MSGT_CACHE, MSGL_FATAL, "Cache size larger than max. allocation size\n");
    return -1;
  }

  s=cache_init(size,ss);
  if(s == NULL) return -1;
  stream->cache_data=s;
  s->stream=stream; // callback
  s->seek_limit=seek_limit;


  //make sure that we won't wait from cache_fill
  //more data than it is allowed to fill
  if (s->seek_limit > s->buffer_size - s->fill_limit ){
     s->seek_limit = s->buffer_size - s->fill_limit;
  }
  if (min > s->buffer_size - s->fill_limit) {
     min = s->buffer_size - s->fill_limit;
  }
  // to make sure we wait for the cache process/thread to be active
  // before continuing
  if (min <= 0)
    min = 1;

#if FORKED_CACHE
  if((stream->cache_pid=fork())){
    if ((pid_t)stream->cache_pid == -1)
      stream->cache_pid = 0;
#else
  {
    stream_t* stream2=malloc(sizeof(stream_t));
    memcpy(stream2,s->stream,sizeof(stream_t));
    s->stream=stream2;
#if defined(__MINGW32__)
    stream->cache_pid = _beginthread( ThreadProc, 0, s );
#elif defined(__OS2__)
    stream->cache_pid = _beginthread( ThreadProc, NULL, 256 * 1024, s );
#else
    {
    pthread_t tid;
    pthread_create(&tid, NULL, ThreadProc, s);
    stream->cache_pid = 1;
    }
#endif
#endif
    if (!stream->cache_pid) {
        mp_msg(MSGT_CACHE, MSGL_ERR,
               "Starting cache process/thread failed: %s.\n", strerror(errno));
        goto err_out;
    }
    // wait until cache is filled at least prefill_init %
    mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64"  pre:%"PRId64"  eof:%d  \n",
	s->min_filepos,s->read_filepos,s->max_filepos,min,s->eof);
    while(s->read_filepos<s->min_filepos || s->max_filepos-s->read_filepos<min){
      /*
	mp_msg(MSGT_CACHE,MSGL_STATUS,MSGTR_CacheFill,
	100.0*(float)(s->max_filepos-s->read_filepos)/(float)(s->buffer_size),
	s->max_filepos-s->read_filepos
	);
      */
	if(s->eof) break; // file is smaller than prefill size
	if(stream_check_interrupt(PREFILL_SLEEP_TIME)) {
	  res = 0;
	  goto err_out;
        }
    }
    mp_msg(MSGT_CACHE,MSGL_STATUS,"\n");
    return 1; // parent exits

err_out:
    cache_uninit(stream);
    return res;
  }

#if FORKED_CACHE
  signal(SIGTERM,exit_sighandler); // kill
  cache_mainloop(s);
  // make sure forked code never leaves this function
  exit(0);
#endif
}

#if !FORKED_CACHE
#if defined(__MINGW32__) || defined(__OS2__)
static void ThreadProc( void *s ){
  cache_mainloop(s);
  _endthread();
//.........这里部分代码省略.........
开发者ID:larsmagne,项目名称:mplayer,代码行数:101,代码来源:cache2.c

示例8: run

		void run() throw(kul::threading::Exception){
			if(s) KEXCEPTION("Thread running");
			f = 0;
			s = 1;
			pthread_create(&thr, NULL, Thread::threadFunction, this);
		}
开发者ID:TheHandsomeCoder,项目名称:mkn.kul,代码行数:6,代码来源:threads.os.hpp

示例9: fvl_srio_init


//.........这里部分代码省略.........
        FVL_LOG("port %d dma_pool_init failed!\n",port_num+1);
        return -errno;
    }
    rvl = dma_pool_init(&port_dma_ctl_wr,ctl_win_size,ctl_win_size/2);
    if(rvl!=0)
    {
        FVL_LOG("port %d dma_pool_init failed!\n",port_num+1);
        return -errno;
    }
    FVL_LOG("*********************dma pool init end**************\n");    
    uint32_t attr_read, attr_write;
    attr_read = srio_test_win_attrv[3];
    attr_write = srio_test_win_attrv[0];
    FVL_LOG("attr_write = %u, srio_type = 0\n", attr_write);
        
    ppool = &psrio->portpool[port_num];
    ppool->write_result = port_dma_wr->dma_phys_base;
    ppool->pwrite_result = port_dma_wr->dma_virt_base;

    ppool->write_ctl_result = port_dma_ctl_wr->dma_phys_base;
    ppool->write_ctl_data = port_dma_ctl_wp->dma_phys_base;
    ppool->pwrite_ctl_result = port_dma_ctl_wr->dma_virt_base;
    ppool->pwrite_ctl_data = port_dma_ctl_wp->dma_virt_base;
    
    ctl_law=FVL_BASE_LAW+fvl_get_law((ctl_win_size/FVL_BASE_LAW_SIZE)-1);
    FVL_LOG("ctl law:%d\n",ctl_law);

    fsl_srio_set_ibwin(sriodev, port_num, 2, ppool->write_ctl_result,
            FVL_SRIO_CTL_ADDR, ctl_law);
    
    rvl=fsl_srio_set_deviceid(sriodev,port_num,source_id[port_num]);
    if(rvl!=0)
    {
        FVL_LOG("SRIO port %d set  source_id faile!\n",port_num);
        return -errno;
    }
    rvl=fsl_srio_set_targetid(sriodev,port_num,1,target_id[port_num]);
    if(rvl!=0)
    {
        FVL_LOG("SRIO port %d set  target_id faile!\n",port_num);
        return -errno;
    }
    rvl=fsl_srio_set_targetid(sriodev,port_num,2,target_id[port_num]);
    if(rvl!=0)
    {
        FVL_LOG("SRIO port %d set  target_id faile!\n",port_num);
        return -errno;
    }
    fsl_srio_set_err_rate_degraded_threshold(sriodev,port_num,0);
    fsl_srio_set_err_rate_failed_threshold(sriodev,port_num,0);
    fsl_srio_set_phy_retry_threshold(sriodev,port_num,0,0);
    
    memset(port_dma_wr->dma_virt_base,0x5a,win_size);        
    memset(port_dma_ctl_wp->dma_virt_base,0,ctl_win_size);        
    memset(port_dma_ctl_wr->dma_virt_base,0,ctl_win_size); 
    
    fvl_srio_channel_t *temp_channel;
    for(i=0;i<FVL_PORT_CHAN_NUM_MAX;i++)
    {
        pscb=fvl_srio_getcb(port_num,i*2);
        if(pscb==NULL)
        {
            FVL_LOG("port:%d channel:%d : dmadev init error.\n",port_num+1,2*i);
            return -1;
        }
        temp_channel=&srio_channel_context[FVL_PORT_CHAN_NUM_MAX*port_num+i];
        cscb=&(temp_channel->chanblk);
        cscb->dmadev=pscb->dmadev;
        cscb->bfnum=pscb->bfnum;
        cscb->port = pscb->port;
        
        pscb=fvl_srio_getcb(port_num,i*2+1);
        if(pscb==NULL)
        {
            FVL_LOG("port:%d channel:%d : dmadev init error.\n",port_num+1,2*i+1);
            return -1;
        }
        re_cscb=&(temp_channel->rechanblk);
        re_cscb->dmadev=pscb->dmadev;
        re_cscb->bfnum=pscb->bfnum;
        re_cscb->port = pscb->port;
    }        

//create thread:
    FVL_LOG("port_num:%d\n",port_num);
    head_arg[port_num].num = port_num;
    head_arg[port_num].cpu = port_num+1;
    head_arg[port_num].op_mode = 0;
    head_arg[port_num].buf_virt=ppool->pwrite_ctl_result;

    rvl = pthread_create(&(psrio->chan_id[port_num]), NULL,fvl_srio_recv_head, &head_arg[port_num]);
    if (rvl) 
    {
        FVL_LOG("Create receive packet thread error!\n");
        return -errno;
    }
    FVL_LOG("SRIO Initial complete\n");    

    return 0;
}
开发者ID:Cai900205,项目名称:test,代码行数:101,代码来源:fvl_srio.c

示例10: fvl_srio_channel_open

int fvl_srio_channel_open(char *name)
{
    int fd=0;
    int rvl=0,i=0;
    fvl_srio_context_t  *psrio = &g_srio_context;
    fvl_srio_portpool_t *cpool;
    fvl_srio_portpool_t *ppool;
    fvl_srio_ctrlblk_t *pscb;
    fvl_head_thread_t head_p_arg;
    int port_num=0,chan_size=0,ctl_size=0,bfnum=0;
    uint32_t offset=0,ctl_offset=0;
    fd=fvl_get_channel(name);
    if(fd==-1)
    {
        FVL_LOG("open error:channel name error.\n");
        return -1;
    }
    port_num=srio_ctable_context[fd].port;
    bfnum = srio_ctable_context[fd].chan;
    if(bfnum > psrio->chan_num[port_num])
    {
        FVL_LOG("open error:channel not exist.\n");
        return -1; 
    }
    FVL_LOG("************************************************\n");
    FVL_LOG("port_num:%d uflag:%d\n",port_num,head_port[port_num].uflag);
    volatile uint8_t *flag= &head_port[port_num].uflag;
    while(1)
    {
        fflush(stdout);
        if(*flag)
        {
            break;
        }
    }

    rese_num[fd]=head_port[port_num].data_se_cluster[(fd%FVL_PORT_CHAN_NUM_MAX)].buf_num;

//end mode master
    FVL_LOG("*****after while ****Head_size:%d rese_num:%d \n",HEAD_SIZE,rese_num[fd]);

    ctl_size = FVL_CTL_WIN_SIZE;
    ctl_offset=ctl_size*bfnum;
    for(i=0;i<bfnum;i++)
    {
        offset=offset+srio_channel_context[i].chan_size;
    }
    FVL_LOG("offset:%08x\n",offset);
 
    fvl_srio_channel_t *temp_channel;

    temp_channel=&srio_channel_context[fd];
    cpool=&(temp_channel->chanpool);
    pscb=&(temp_channel->chanblk);

    ppool = &psrio->portpool[port_num];

    cpool->write_result = ppool->write_result+offset;
    cpool->pwrite_result = ppool->pwrite_result+offset;
         
    cpool->write_ctl_result = ppool->write_ctl_result+HEAD_SIZE+ctl_offset;
    cpool->write_ctl_data = ppool->write_ctl_data+HEAD_SIZE+ctl_offset;
        
    cpool->pwrite_ctl_result = ppool->pwrite_ctl_result+HEAD_SIZE+ctl_offset;
    cpool->pwrite_ctl_data = ppool->pwrite_ctl_data+HEAD_SIZE+ctl_offset;
// very important
    cpool->port_info.range_start=ppool->port_info.range_start+offset;
    cpool->ctl_info_start = ppool->ctl_info_start+HEAD_SIZE+ctl_offset;
    
    uint64_t dest_phys,src_phys;
    FVL_LOG("##### channel:%d Slave receive ctl_head info!\n",fd);

    dest_phys=cpool->ctl_info_start;
    src_phys=cpool->write_ctl_data;
    memcpy(cpool->pwrite_ctl_data,&head_channel[fd],HEAD_SIZE);

    fvl_srio_send(pscb->dmadev,src_phys,dest_phys,HEAD_SIZE);

    FVL_LOG("##### channel:%d Slave reback ctl_head info!\n",fd);

// add
    ctl_re_arg[fd].fd=fd;
    ctl_re_arg[fd].port_num=port_num;
    ctl_re_arg[fd].cpu=fd+3;
    ctl_re_arg[fd].buf_virt=cpool->pwrite_ctl_result+FVL_SRIO_RD_OP*HEAD_SIZE;

    rvl = pthread_create(&(temp_channel->chan_id), NULL,fvl_srio_recv_ctl, &ctl_re_arg[fd]);
    if (rvl) 
    {
        FVL_LOG("Create receive packet thread error!\n");
        return -errno;
    }

    return fd;
}
开发者ID:Cai900205,项目名称:test,代码行数:95,代码来源:fvl_srio.c

示例11: main

int main(int argc, char *argv[]){
 int N, i, rc;
 str_tiratore *tiratore;
 void *status;
 pthread_attr_t attr;
  
   if(argc!=5){
    printf("Numero dei parametri inseriti errato....\n");
   exit(EXIT_FAILURE);
    }
 N=atoi(argv[1]); //numero appassionati di tiro con l'arco
 K=atoi(argv[2]); //numero dei tiri a disposizione
 A=atoi(argv[3]); //numero di archi
 I=atoi(argv[4]); //numero di freccie

  if((N<10)||(N>30)||(A<1)||(A>3)||(I<3)||(I>6)){
    printf("NON consentito\n");
   exit(-1);
   }
 
   tiratore=(str_tiratore *)malloc(N*sizeof(str_tiratore));
 //inizializzazione semafori
    sem_init(&archi,0,A); //semaforo x gli archi
    sem_init(&freccie,0,I); //semaforo per le freccie
 //inizializzazione mutex
    pthread_mutex_init(&bersaglio, NULL);
 //inizializzazione dei thread
    pthread_attr_init(&attr);
     pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE);
   
    for(i=0; i<N; i++){
     tiratore[i].id=i;
      tiratore[i].parziale=0;
      tiratore[i].totale=0;
    rc=pthread_create(&tiratore[i].tid,&attr,routine_tiro,(void *)(&tiratore[i]));
      if(rc){
        printf("ERRORE.....\n");
         getchar(); //premere invio
     exit(-1);}
     }
    rc=pthread_create(&gestore,&attr,routine_gestore,NULL);
      if(rc){
        printf("ERRORE.....\n");
         getchar(); //premere invio
     exit(-1);}
     
 //rilascio delle risorse per i thread
    pthread_attr_destroy(&attr);
     for(i=0; i<N; i++)
        pthread_join(tiratore[i].tid,&status);  //si attende che finiscano tutti i thread

   printf("\n	CLASSIFICA	\n");
     for(i=0; i<N; i++){
    printf("tiratore %d, ha totalizzato %d punti\n",tiratore[i].id,tiratore[i].totale);
  }
 //rilascio delle risorse per il mutex
     pthread_mutex_destroy(&bersaglio);
 //rilascio delle risorse per i semafori
     sem_destroy(&archi);
       sem_destroy(&freccie);

pthread_exit(NULL);
 }
开发者ID:Manfrins,项目名称:CsInfoPa,代码行数:63,代码来源:bis1.c

示例12: edrv_init

//------------------------------------------------------------------------------
tOplkError edrv_init(const tEdrvInitParam* pEdrvInitParam_p)
{
    struct sched_param  schedParam;

    // Check parameter validity
    ASSERT(pEdrvInitParam_p != NULL);

    // clear instance structure
    OPLK_MEMSET(&edrvInstance_l, 0, sizeof(edrvInstance_l));

    if (pEdrvInitParam_p->pDevName == NULL)
        return kErrorEdrvInit;

    // save the init data
    edrvInstance_l.initParam = *pEdrvInitParam_p;

    /* if no MAC address was specified read MAC address of used
     * Ethernet interface
     */
    if ((edrvInstance_l.initParam.aMacAddr[0] == 0) &&
        (edrvInstance_l.initParam.aMacAddr[1] == 0) &&
        (edrvInstance_l.initParam.aMacAddr[2] == 0) &&
        (edrvInstance_l.initParam.aMacAddr[3] == 0) &&
        (edrvInstance_l.initParam.aMacAddr[4] == 0) &&
        (edrvInstance_l.initParam.aMacAddr[5] == 0))
    {   // read MAC address from controller
        getMacAdrs(edrvInstance_l.initParam.pDevName,
                   edrvInstance_l.initParam.aMacAddr);
    }

    // Set up and activate the pcap live capture handle
    edrvInstance_l.pPcap = startPcap();
    if (edrvInstance_l.pPcap == NULL)
    {
        return kErrorEdrvInit;
    }

    if (pcap_setdirection(edrvInstance_l.pPcap, PCAP_D_OUT) < 0)
    {
        DEBUG_LVL_ERROR_TRACE("%s() couldn't set PCAP direction\n", __func__);
        return kErrorEdrvInit;
    }

    if (pthread_mutex_init(&edrvInstance_l.mutex, NULL) != 0)
    {
        DEBUG_LVL_ERROR_TRACE("%s() couldn't init mutex\n", __func__);
        return kErrorEdrvInit;
    }

    if (sem_init(&edrvInstance_l.syncSem, 0, 0) != 0)
    {
        DEBUG_LVL_ERROR_TRACE("%s() couldn't init semaphore\n", __func__);
        return kErrorEdrvInit;
    }

    if (pthread_create(&edrvInstance_l.hThread, NULL,
                       workerThread,  &edrvInstance_l) != 0)
    {
        DEBUG_LVL_ERROR_TRACE("%s() Couldn't create worker thread!\n", __func__);
        return kErrorEdrvInit;
    }

    schedParam.sched_priority = CONFIG_THREAD_PRIORITY_MEDIUM;
    if (pthread_setschedparam(edrvInstance_l.hThread, SCHED_FIFO, &schedParam) != 0)
    {
        DEBUG_LVL_ERROR_TRACE("%s() couldn't set thread scheduling parameters!\n", __func__);
    }

#if (defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 12))
    pthread_setname_np(edrvInstance_l.hThread, "oplk-edrvpcap");
#endif

    /* wait until thread is started */
    sem_wait(&edrvInstance_l.syncSem);

    return kErrorOk;
}
开发者ID:OpenAutomationTechnologies,项目名称:openPOWERLINK_V2,代码行数:78,代码来源:edrv-pcap_linux.c

示例13: main

int main()
{

   socket_init();

   fp1 = fopen("raw_recv_data.txt","w");
   fp2 = fopen("increase_bit.txt","w");

   printf("my:hello fedora!\n");
if((testfd = ML605Open())<0)
   printf("open ml605 failed");

if(ML605StartEthernet(testfd, SFP_TX_START)<0) {
    printf("PCIe:Start ethernet failure\n");
	  ML605Close(testfd);
    exit(-1);
  }

/* pthread_t writethread;
  if (pthread_create(&writethread, NULL, mywrite, NULL)) 
  {
    perror("writethread process thread creation failed");
  }  
  sleep(1);
*/  

/*
  pthread_t readthread;
  if (pthread_create(&readthread, NULL, GetRate, NULL)) 
  {
    perror("readthread process thread creation failed");
  }  
  sleep(1);
*/  
  pthread_t ratathread;
/*

  if (pthread_create(&ratathread, NULL, myread2, NULL)) 
  {
    perror("readthread process thread creation failed");
  }
  pthread_t readthread2;
  if (pthread_create(&ratathread, NULL, myread, NULL)) 
  {
    perror("readthread process thread creation failed");
  }  
*/
  pthread_t readthread3;
  if (pthread_create(&ratathread, NULL, myread3, NULL)) 
  {
    perror("readthread process thread creation failed");
  }  
  sleep(1);


  char ch_input;
  scanf("%c", &ch_input);
  isclose=0;
  ML605Close(testfd);
  fclose(fp1);
  fclose(fp2);
}
开发者ID:uestcmy,项目名称:5000_test_20140305,代码行数:62,代码来源:3000aaa0_save_20140311.cpp

示例14: main

int main(int argc, char **argv) {
int err_ret, sin_size;
struct sockaddr_in serv_addr, client_addr;
pthread_t interrupt;

list_init(&client_list);//initialize linked list

pthread_mutex_init(&clientlist_mutex, NULL);//initiate mutex

if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {//avoir le socket
err_ret = errno;
fprintf(stderr, "socket() failed...\n");
return err_ret;
}
/*set initiate values*/
serv_addr.sin_family = AF_INET;//@family=internet
serv_addr.sin_port = htons(PORT);
serv_addr.sin_addr.s_addr = inet_addr(IP);//set l @ IP to local host
memset(&(serv_addr.sin_zero), 0, 8);

if(bind(sockfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) == -1) {//reserver le port sur lequel on veut secouter
err_ret = errno;
fprintf(stderr, "bind() failed...\n");
return err_ret;
}
/*start listen with max connection*/
if(listen(sockfd, BACKLOG) == -1) {
err_ret = errno;
fprintf(stderr, "listen() failed...\n");
return err_ret;
}
/*initiate interrupt handler for IO controlling */
printf("Starting server...\n");
if(pthread_create(&interrupt, NULL, io_handler, NULL) != 0) {
err_ret = errno;
fprintf(stderr, "pthread_create() failed...\n");
return err_ret;
}
/*on accepte la connexion */
printf("accepting connections...\n");
while(1) {
sin_size = sizeof(struct sockaddr_in);
if((newfd = accept(sockfd, (struct sockaddr *)&client_addr, (socklen_t*)&sin_size)) == -1) {
err_ret = errno;
fprintf(stderr, "accept() failed...\n");
return err_ret;
}
else {
if(client_list.size == CLIENTS) {
fprintf(stderr, "Connection full, request rejected...\n");
continue;
}
printf("Connection requested received...\n");
struct THREADINFO threadinfo;
threadinfo.sockfd = newfd;
strcpy(threadinfo.alias, "Anonymous");
pthread_mutex_lock(&clientlist_mutex);
list_insert(&client_list, &threadinfo);
pthread_mutex_unlock(&clientlist_mutex);
pthread_create(&threadinfo.thread_ID, NULL, client_handler, (void *)&threadinfo);
}
}
return 0;
}
开发者ID:ns7900f,项目名称:linux,代码行数:64,代码来源:server.c

示例15: main

int main(int argc, char *argv[ ])
{
	tree *bst = NULL;
	int input[ 5000 ];
	char input_num[MAX];
	char *temp;
	char *temp2;
	int b[MAX];
	int try[5] = {5,4,3,2,1};
	int i=0, num, req;
	int j = 0;
	int count = 0;
	int check = 0;
	int input_size = 0;
	int a[MAX] = {0};
	int test;
	char get_ch ;
	//  FILE pointer of reading and writing
	//  and thread_t
	FILE *fp;
	FILE *fw;

	//   check the arguments if it is exactly three
	/*
	if(argc != 3){
		perror("parameter amount error!");
		return 0;
	}
	*/
	

	// open two files for read input and write output
	fp = fopen(argv[1], "r");
 	//fw = fopen(argv[2], "a");
	/*
	while( (get_ch = fgetc(fp)) != EOF ){
		printf("this character: %s\n",get_ch);
		if( get_ch != )
		count ++;
	}
	*/
	while( fgets(input_num,MAX,fp) != NULL )
	{	
		printf("this is count: %d\n", count);
		temp = strtok(input_num," ");	
		while( temp != NULL){
			printf("%s\n",temp);
			//printf("test\n");
			if(count == 0){
				b[i] = atoi(temp);
				//printf("what is b[%d] ? %d\n",i,b[i]);
				i++;
				check++;
			}else{
				input[j] = atoi(temp);
				j++;
				input_size++;	
			}
			//printf("%s ",temp);
			temp = strtok(NULL, " ");
		}
		
		//char temp[10];
		count++;
	}
	i = 0;
	j = 0;
	// arr to catch the "to search numbers"
	// the value of the array "arr" is the number to search in the bst
	int arr[check];
	//printf("\n\ncheck: %d\n",check);
	for(j=0;j<check;++j){
		arr[j] = b[j];
		printf(" array arr value: %d \n",arr[j]);
	}
	printf("the total input numbers' size: %d\n",input_size);
	for(i=0;i<input_size;i++)
		printf("input[%d] , value: %d\n",i,input[i]);
	// create thread according to the number of int's on the first line
	pthread_t threads[check];
	// thread_data_t type structture initialize
	thread_data_t thr_data[check];
	// check the thread ids
	int check_thread[check];
	for(i=0;i<check;++i){
		thr_data[i].amount = input_size;
		thr_data[i].tid = i;
		thr_data[i].search_num = arr[i];
		thr_data[i].arg = argv[2];
		for(j=0;j<thr_data[i].amount;++j){
			thr_data[i].list[j] = input[j];
		}
		if( (check_thread[i] = pthread_create(&threads[i], NULL, thr_func, &thr_data[i])) ){
			fprintf(stderr,"error: pthread_create, thread: %d\n",check_thread[i]);
			return EXIT_FAILURE;
		}
	}
		// insert the array into the tree
	
	// print out the data in the inorder fashion
//.........这里部分代码省略.........
开发者ID:kastress0121,项目名称:C-stuff,代码行数:101,代码来源:thread_bst.c


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