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

C++ create_worker函数代码示例

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

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



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

示例1: test_fingerprint

static void test_fingerprint(void *z)
{
	struct Worker *server = NULL, *client = NULL;

	tt_assert(tls_init() == 0);

	/* both server & client with cert */
	str_check(create_worker(&server, true, SERVER1, CA2,
		"verify-client=1",
		"peer-sha1=ssl/ca2_client2.crt.sha1",
		"peer-sha256=ssl/ca2_client2.crt.sha256",
		NULL), "OK");
	str_check(create_worker(&client, false, CLIENT2, CA1,
		"host=server1.com",
		"peer-sha1=ssl/ca1_server1.crt.sha1",
		"peer-sha256=ssl/ca1_server1.crt.sha256",
		NULL), "OK");
	str_check(run_case(client, server), "OK");

	/* client without cert */
	str_check(create_worker(&server, true, SERVER1, CA1,
		"verify-client=1",
		"peer-sha1=ssl/ca2_client2.crt.sha1",
		"peer-sha256=ssl/ca2_client2.crt.sha256",
		NULL), "OK");
	str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
	str_any2(run_case(client, server),
		 "C:sslv3 alert handshake failure - S:peer did not return a certificate",
		 "C:sslv3 alert handshake failure,C:shutdown while in init - S:peer did not return a certificate");
end:;
}
开发者ID:v2tmobile,项目名称:libusual,代码行数:31,代码来源:test_tls.c


示例2: test_verify

static void test_verify(void *z)
{
	struct Worker *server = NULL, *client = NULL;

	tt_assert(tls_init() == 0);

	/* default: client checks server cert, succeeds */
	str_check(create_worker(&server, true, SERVER1, NULL), "OK");
	str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "OK");

	/* default: client checks server cert, fails due to bad ca */
	str_check(create_worker(&server, true, SERVER1, NULL), "OK");
	str_check(create_worker(&client, false, CA2, "host=example.com", NULL), "OK");
	str_check(run_case(client, server), "C:certificate verify failed - S:tlsv1 alert unknown ca");

	/* default: client checks server cert, fails due to bad hostname */
	str_check(create_worker(&server, true, SERVER1, NULL), "OK");
	str_check(create_worker(&client, false, CA1, "host=example2.com", NULL), "OK");
	str_check(run_case(client, server), "C:name `example2.com' not present in server certificate");

#if 0
	/* client: aggressive close */
	str_check(create_worker(&server, true, SERVER1, NULL), "OK");
	str_check(create_worker(&client, false, CA1, "aggressive-close=1", "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "S:bad pkt: res=-1 err=read failed: EOF,S:close error: res=-1 err=shutdown failed: Broken pipe");

	/* server: aggressive close */
	str_check(create_worker(&server, true, SERVER1, "aggressive-close=1", NULL), "OK");
	str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "C:write failed: Broken pipe,C:close error: res=-1 err=shutdown failed: Success");
#endif

end:;
}
开发者ID:ifduyue,项目名称:libusual,代码行数:35,代码来源:test_tls.c


示例3: test_fingerprint

static void test_fingerprint(void *z)
{
	struct Worker *server = NULL, *client = NULL;

	tt_assert(tls_init() == 0);

	/* both server & client with cert */
	str_check(create_worker(&server, true, SERVER1, CA2,
		"peer-sha1=ssl/ca2_client2.crt.sha1",
		"peer-sha256=ssl/ca2_client2.crt.sha256",
		NULL), "OK");
	str_check(create_worker(&client, false, CLIENT2, CA1,
		"host=server1.com",
		"peer-sha1=ssl/ca1_server1.crt.sha1",
		"peer-sha256=ssl/ca1_server1.crt.sha256",
		NULL), "OK");
	str_check(run_case(client, server), "OK");

	/* client without cert */
	str_check(create_worker(&server, true, SERVER1, CA1,
		"peer-sha1=ssl/ca2_client2.crt.sha1",
		"peer-sha256=ssl/ca2_client2.crt.sha256",
		NULL), "OK");
	str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "C:write!=3 - S:FP-sha1-fail");
end:;
}
开发者ID:greenplum-db,项目名称:libusual,代码行数:27,代码来源:test_tls.c


示例4: test_set_mem

static void test_set_mem(void *z)
{
	struct Worker *server = NULL, *client = NULL;

	tt_assert(tls_init() == 0);

	/* both server & client with cert */
	str_check(create_worker(&server, true, "mem=1", SERVER1, CA2, NULL), "OK");
	str_check(create_worker(&client, false, "mem=1", CLIENT2, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "OK");
end:;
}
开发者ID:v2tmobile,项目名称:libusual,代码行数:12,代码来源:test_tls.c


示例5: group

/* One group of senders and receivers */
static unsigned int group(pthread_t *pth,
		unsigned int num_fds,
		int ready_out,
		int wakefd)
{
	unsigned int i;
	struct sender_context *snd_ctx = malloc(sizeof(struct sender_context)
			+ num_fds * sizeof(int));

	if (!snd_ctx)
		barf("malloc()");

	for (i = 0; i < num_fds; i++) {
		int fds[2];
		struct receiver_context *ctx = malloc(sizeof(*ctx));

		if (!ctx)
			barf("malloc()");


		/* Create the pipe between client and server */
		fdpair(fds);

		ctx->num_packets = num_fds * loops;
		ctx->in_fds[0] = fds[0];
		ctx->in_fds[1] = fds[1];
		ctx->ready_out = ready_out;
		ctx->wakefd = wakefd;

		pth[i] = create_worker(ctx, (void *)receiver);

		snd_ctx->out_fds[i] = fds[1];
		if (!thread_mode)
			close(fds[0]);
	}

	/* Now we have all the fds, fork the senders */
	for (i = 0; i < num_fds; i++) {
		snd_ctx->ready_out = ready_out;
		snd_ctx->wakefd = wakefd;
		snd_ctx->num_fds = num_fds;

		pth[num_fds+i] = create_worker(snd_ctx, (void *)sender);
	}

	/* Close the fds we have left */
	if (!thread_mode)
		for (i = 0; i < num_fds; i++)
			close(snd_ctx->out_fds[i]);

	/* Return number of children to reap */
	return num_fds * 2;
}
开发者ID:3null,项目名称:fastsocket,代码行数:54,代码来源:sched-messaging.c


示例6: test_clientcert

static void test_clientcert(void *z)
{
	struct Worker *server = NULL, *client = NULL;

	tt_assert(tls_init() == 0);

	/* ok: server checks server cert */
	str_check(create_worker(&server, true, SERVER1, CA2, NULL), "OK");
	str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "OK");

	/* fail: server rejects invalid cert */
	str_check(create_worker(&server, true, SERVER1, CA1, NULL), "OK");
	str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "C:tlsv1 alert unknown ca - S:handshake failure");

	/* noverifycert: server allow invalid cert */
	str_check(create_worker(&server, true, SERVER1, CA1, "noverifycert=1", NULL), "OK");
	str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "OK");

	/* allow client without cert */
	str_check(create_worker(&server, true, SERVER1, CA2, NULL), "OK");
	str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "OK");
end:;
}
开发者ID:greenplum-db,项目名称:libusual,代码行数:27,代码来源:test_tls.c


示例7: thread_init

void thread_init(int t_num, struct event_base *main_base)
{
    dispatch_thread.base = main_base;
    dispatch_thread.thread_id = pthread_self();
    int i;
    threads = calloc(t_num, sizeof(wk_thread));
    if (!threads) {
        perror("Can't alloc so many thread\n");
        exit(1);
    }

    for (i = 0; i < t_num; i++) {
        int fds[2];
        if (pipe(fds)) {
            perror("can't pipe\n");
            exit(1);
        }
        threads[i].notify_receive_fd = fds[0];
        threads[i].notify_send_fd = fds[1];

        setup_thread(&threads[i]);
    }

    for (i = 0; i < t_num; i++) {
        create_worker(worker_libevent, &threads[i]);
    }

}
开发者ID:baotiao,项目名称:Asenal,代码行数:28,代码来源:thread.c


示例8: thread_init

static void thread_init(global_conf_st * g_conf)
{
    int i;
    pthread_mutex_init(&init_lock,NULL);
    pthread_cond_init(&init_cond,NULL);
    
    int nthreads = g_conf->max_thread;
    threads = calloc(nthreads,sizeof(work_thread));
    if(!threads){
	fprintf(stderr,"%s:%d :Cant allocate threads info",__FILE__,__LINE__);
	exit(-1);
    }
    for(i = 0 ;i < nthreads;i++){
	threads[i].g_conf = g_conf;
	threads[i].msg_queue = g_async_queue_new();
    }
    for(i = 0 ;i < nthreads;i++){
	create_worker(worker_thread,&threads[i]);
    }
    pthread_mutex_lock(&init_lock);
    while(init_count < nthreads){
	pthread_cond_wait(&init_cond,&init_lock);
    }
    pthread_mutex_unlock(&init_lock);
}
开发者ID:easingz,项目名称:BigHead,代码行数:25,代码来源:link_mining.c


示例9: thr_pool_queue

int
thr_pool_queue(thr_pool_t *pool, void *(*func)(void *), void *arg)
{
    job_t *job;

    if ((job = malloc(sizeof (*job))) == NULL) {
        errno = ENOMEM;
        return (-1);
    }
    job->job_next = NULL;
    job->job_func = func;
    job->job_arg = arg;

    (void) pthread_mutex_lock(&pool->pool_mutex);

    if (pool->pool_head == NULL)
        pool->pool_head = job;
    else
        pool->pool_tail->job_next = job;
    pool->pool_tail = job;

    if (pool->pool_idle > 0)
        (void) pthread_cond_signal(&pool->pool_workcv);
    else if (pool->pool_nthreads < pool->pool_maximum &&
        create_worker(pool) == 0)
        pool->pool_nthreads++;

    (void) pthread_mutex_unlock(&pool->pool_mutex);
    return (0);
}
开发者ID:chavula,项目名称:control-plane,代码行数:30,代码来源:thr_pool.c


示例10: tpool_dispatch

/*
 * Dispatch a work request to the thread pool.
 * If there are idle workers, awaken one.
 * Else, if the maximum number of workers has
 * not been reached, spawn a new worker thread.
 * Else just return with the job added to the queue.
 */
int
tpool_dispatch(tpool_t *tpool, void (*func)(void *), void *arg)
{
	tpool_job_t *job;

	if ((job = malloc(sizeof (*job))) == NULL)
		return (-1);
	bzero(job, sizeof(*job));
	job->tpj_next = NULL;
	job->tpj_func = func;
	job->tpj_arg = arg;

	pthread_mutex_lock(&tpool->tp_mutex);

	if (tpool->tp_head == NULL)
		tpool->tp_head = job;
	else
		tpool->tp_tail->tpj_next = job;
	tpool->tp_tail = job;
	tpool->tp_njobs++;

	if (!(tpool->tp_flags & TP_SUSPEND)) {
		if (tpool->tp_idle > 0)
			(void) pthread_cond_signal(&tpool->tp_workcv);
		else if (tpool->tp_current < tpool->tp_maximum &&
		    create_worker(tpool) == 0)
			tpool->tp_current++;
	}

	pthread_mutex_unlock(&tpool->tp_mutex);
	return (0);
}
开发者ID:JabirTech,项目名称:JabirOS-source,代码行数:39,代码来源:thread_pool.c


示例11: test_clientcert

static void test_clientcert(void *z)
{
	struct Worker *server = NULL, *client = NULL;

	tt_assert(tls_init() == 0);

	/* ok: server checks client cert */
	str_check(create_worker(&server, true, SERVER1, CA2,
				"verify-client=1",
				NULL), "OK");
	str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "OK");

	/* fail: server rejects invalid cert */
	str_check(create_worker(&server, true, SERVER1, CA1,
				"verify-client=1",
				NULL), "OK");
	str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
	str_any3(run_case(client, server),
		"C:tlsv1 alert unknown ca - S:no certificate returned",
		"C:tlsv1 alert unknown ca,C:shutdown while in init - S:certificate verify failed",
		"C:tlsv1 alert unknown ca - S:certificate verify failed");

	/* noverifycert: server allow invalid cert */
	str_check(create_worker(&server, true, SERVER1, CA1,
				"noverifycert=1",
				NULL), "OK");
	str_check(create_worker(&client, false, CLIENT2, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "OK");

	/* verify-client: don't allow client without cert */
	str_check(create_worker(&server, true, SERVER1, CA2,
				"verify-client=1",
				NULL), "OK");
	str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
	str_any2(run_case(client, server),
		 "C:sslv3 alert handshake failure - S:peer did not return a certificate",
		 "C:sslv3 alert handshake failure,C:shutdown while in init - S:peer did not return a certificate");

	/* verify-client-optional: allow client without cert */
	str_check(create_worker(&server, true, SERVER1, CA2,
				"verify-client-optional=1",
				NULL), "OK");
	str_check(create_worker(&client, false, CA1, "host=server1.com", NULL), "OK");
	str_check(run_case(client, server), "OK");
end:;
}
开发者ID:v2tmobile,项目名称:libusual,代码行数:47,代码来源:test_tls.c


示例12: create_modules

void create_modules() {
    ok(create_client( mod_gm_opt->server_list, &client ) == GM_OK, "created test client");

    ok(create_worker( mod_gm_opt->server_list, &worker ) == GM_OK, "created test worker");
    ok(worker_add_function( &worker, GM_DEFAULT_RESULT_QUEUE, get_results ) == GM_OK, "added result worker");
    ok(worker_add_function( &worker, "dummy", dummy ) == GM_OK, "added dummy worker");
    //gearman_worker_add_options(&worker, GEARMAN_WORKER_NON_BLOCKING);
    gearman_worker_set_timeout(&worker, 5000);
    return;
}
开发者ID:hedenface,项目名称:mod_gearman,代码行数:10,代码来源:02-full.c


示例13: test_cipher_nego

static void test_cipher_nego(void *z)
{
	struct Worker *server = NULL, *client = NULL;

	tt_assert(tls_init() == 0);

	/* server key is EC:secp384r1 - ECDHE-ECDSA */
	str_check(create_worker(&server, true, "show=ciphers", SERVER1, NULL), "OK");
	str_check(create_worker(&client, false, CA1,
		"ciphers=AESGCM",
		"host=server1.com",
		NULL), "OK");
	str_any3(run_case(client, server),
		 "TLSv1.2/ECDHE-ECDSA-AES256-GCM-SHA384/ECDH=secp384r1",
		 "TLSv1.2/ECDHE-ECDSA-AES256-GCM-SHA384/ECDH=X25519",
		 "TLSv1.2/ECDHE-ECDSA-AES256-GCM-SHA384");

	/* server key is RSA - ECDHE-RSA */
	str_check(create_worker(&server, true, "show=ciphers", SERVER2, NULL), "OK");
	str_check(create_worker(&client, false, CA2,
		"ciphers=AESGCM",
		"host=server2.com",
		NULL), "OK");
	str_any3(run_case(client, server),
		 "TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=prime256v1",
		 "TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=X25519",
		 "TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384");

	/* server key is RSA - DHE-RSA */
	str_check(create_worker(&server, true, SERVER2,
		"show=ciphers",
		"dheparams=auto",
		NULL), "OK");
	str_check(create_worker(&client, false, CA2,
		"ciphers=EDH+AESGCM",
		"host=server2.com",
		NULL), "OK");
	str_check(run_case(client, server), "TLSv1.2/DHE-RSA-AES256-GCM-SHA384/DH=2048");

	/* server key is RSA - ECDHE-RSA */
	str_check(create_worker(&server, true, SERVER2,
		"show=ciphers",
		NULL), "OK");
	str_check(create_worker(&client, false, CA2,
		"ciphers=EECDH+AES",
		"host=server2.com",
		NULL), "OK");
	str_any3(run_case(client, server),
		 "TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=prime256v1",
		 "TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384/ECDH=X25519",
		 "TLSv1.2/ECDHE-RSA-AES256-GCM-SHA384");
end:;
}
开发者ID:ifduyue,项目名称:libusual,代码行数:53,代码来源:test_tls.c


示例14: test_noverifyname

static void test_noverifyname(void *z)
{
	struct Worker *server = NULL, *client = NULL;

	tt_assert(tls_init() == 0);

	/* noverifyname: client checks server cert, ignore bad hostname */
	str_check(create_worker(&server, true, SERVER1, NULL), "OK");
	str_check(create_worker(&client, false, CA1, "host=example2.com",
		"noverifyname=1",
		NULL), "OK");
	str_check(run_case(client, server), "OK");

	/* noverifyname: client checks server cert, ignore NULL hostname */
	str_check(create_worker(&server, true, SERVER1, NULL), "OK");
	str_check(create_worker(&client, false, CA1, "noverifyname=1", NULL), "OK");
	str_check(run_case(client, server), "OK");
end:;
}
开发者ID:v2tmobile,项目名称:libusual,代码行数:19,代码来源:test_tls.c


示例15: thread_init

/*
 * Initializes the thread subsystem, creating various worker threads.
 *
 * nthreads  Number of worker event handler threads to spawn
 * main_base Event base for main thread
 */
void thread_init(int nthreads, struct event_base *main_base) {
    int         i;

    pthread_mutex_init(&cache_lock, NULL);/*Lock for cache operations (item_*, assoc_*)*/
    pthread_mutex_init(&stats_lock, NULL);/*Lock for global stats*/

    pthread_mutex_init(&init_lock, NULL);
    pthread_cond_init(&init_cond, NULL);

    pthread_mutex_init(&cqi_freelist_lock, NULL);
    cqi_freelist = NULL;

    threads = calloc(nthreads, sizeof(LIBEVENT_THREAD));
    /* 分配一个数组 ,数据大小为nthreads ,
     * 数据的的每个元素的内存空间为 sizeof(LIEVENT_THREAD) 并且,返回一个指针,
     * 指向该数组*/
    /* Allocate nthreads elements of sizeof(LIBEVENT_THREAD) bytes each, all initialized to 0.  */

    if (! threads) {//很明显这是是提示说tmd竟然分配内存失败了!
        perror("Can't allocate thread descriptors");
        exit(1);
    }

    dispatcher_thread.base = main_base;
    /*main_base这个是主线程的libevent句柄,这个在main()方法里面初始化*/
    dispatcher_thread.thread_id = pthread_self();/*获取当前线程的id 。*/

    for (i = 0; i < nthreads; i++) {
        int fds[2];
        if (pipe(fds)) {//创建一个管道符,用于两个进程之间的联系
            perror("Can't create notify pipe");
            exit(1);
        }

        threads[i].notify_receive_fd = fds[0];
        threads[i].notify_send_fd = fds[1];

        setup_thread(&threads[i]);//设置一些线程信息
    }

    /* Create threads after we've done all the libevent setup. */
    for (i = 0; i < nthreads; i++) {
	//顾名思义,每个线程的信息初始化完毕,开始创建线程
        create_worker(worker_libevent, &threads[i]);
    }

    /* 
     * 主线程等所有线程创建完毕之后再结束
     * Wait for all the threads to set themselves up before returning. */
    pthread_mutex_lock(&init_lock);
    while (init_count < nthreads) {
        pthread_cond_wait(&init_cond, &init_lock);
    }
    pthread_mutex_unlock(&init_lock);
}
开发者ID:JunBian,项目名称:memcached,代码行数:61,代码来源:thread.c


示例16: thread_init

/*
 * Initializes the thread subsystem, creating various worker threads.
 *
 * nthreads  Number of worker event handler threads to spawn
 * main_base Event base for main thread
 */
void thread_init(int nthr, struct event_base *main_base,
                 void (*dispatcher_callback)(int, short, void *)) {
    int i;
    nthreads = nthr + 1;

    pthread_mutex_init(&stats_lock, NULL);
    pthread_mutex_init(&init_lock, NULL);
    pthread_cond_init(&init_cond, NULL);

    pthread_mutex_init(&cqi_freelist_lock, NULL);
    cqi_freelist = NULL;

    threads = calloc(nthreads, sizeof(LIBEVENT_THREAD));
    if (! threads) {
        settings.extensions.logger->log(EXTENSION_LOG_WARNING, NULL,
                                        "Can't allocate thread descriptors: %s",
                                        strerror(errno));
        exit(1);
    }
    thread_ids = calloc(nthreads, sizeof(pthread_t));
    if (! thread_ids) {
        perror("Can't allocate thread descriptors");
        exit(1);
    }

    setup_dispatcher(main_base, dispatcher_callback);

    for (i = 0; i < nthreads; i++) {
        if (!create_notification_pipe(&threads[i])) {
            exit(1);
        }
        threads[i].index = i;

        setup_thread(&threads[i], i == (nthreads - 1));
    }

    /* Create threads after we've done all the libevent setup. */
    for (i = 0; i < nthreads; i++) {
        create_worker(worker_libevent, &threads[i], &thread_ids[i]);
        threads[i].thread_id = thread_ids[i];
    }

    tap_thread = &threads[nthreads - 1];

    /* Wait for all the threads to set themselves up before returning. */
    pthread_mutex_lock(&init_lock);
    while (init_count < nthreads) {
        pthread_cond_wait(&init_cond, &init_lock);
    }
    pthread_mutex_unlock(&init_lock);
}
开发者ID:ForcerKing,项目名称:ShaoqunXu-mysql5.7,代码行数:57,代码来源:thread.c


示例17: worker_cleanup

/*
 * Worker thread is terminating.  Possible reasons:
 * - excess idle thread is terminating because there is no work.
 * - thread was cancelled (pool is being destroyed).
 * - the job function called pthread_exit().
 * In the last case, create another worker thread
 * if necessary to keep the pool populated.
 */
void
worker_cleanup(thr_pool_t *pool)
{
    --pool->pool_nthreads;
    if (pool->pool_flags & POOL_DESTROY) {
        if (pool->pool_nthreads == 0)
            (void) pthread_cond_broadcast(&pool->pool_busycv);
    } else if (pool->pool_head != NULL &&
        pool->pool_nthreads < pool->pool_maximum &&
        create_worker(pool) == 0) {
        pool->pool_nthreads++;
    }
    (void) pthread_mutex_unlock(&pool->pool_mutex);
}
开发者ID:chavula,项目名称:control-plane,代码行数:22,代码来源:thr_pool.c


示例18: thread_init

/*
 * Initializes the thread subsystem, creating various worker threads.
 *
 * nthreads  Number of worker event handler threads to spawn
 * main_base Event base for main thread
 */
void thread_init(int nthreads, struct event_base *main_base)
{
    int         i;
    int         power;

    pthread_mutex_init(&cache_lock, NULL);
    pthread_mutex_init(&init_lock, NULL);
    pthread_cond_init(&init_cond, NULL);

    pthread_mutex_init(&cqi_freelist_lock, NULL);
    cqi_freelist = NULL;

    threads = (LIBEVENT_THREAD *)calloc(nthreads, sizeof(LIBEVENT_THREAD));
    if (! threads)
    {
        log_debug(LOG_ERR, "Can't allocate thread descriptors, error:%s\n", strerror(errno));
        exit(1);
    }

    dispatcher_thread.base = main_base;
    dispatcher_thread.thread_id = pthread_self();

    for (i = 0; i < nthreads; i++)
    {
        int fds[2];
        if (pipe(fds))
        {
            log_debug(LOG_ERR, "Can't create notify pipe, error:%s\n", strerror(errno));
            exit(1);
        }

        threads[i].notify_receive_fd = fds[0];
        threads[i].notify_send_fd = fds[1];

        setup_thread(&threads[i]);
        /* Reserve three fds for the libevent base, and two for the pipe */
    }

    /* Create threads after we've done all the libevent setup. */
    for (i = 0; i < nthreads; i++)
    {
        create_worker(worker_libevent, &threads[i]);
    }

    /* Wait for all the threads to set themselves up before returning. */
    pthread_mutex_lock(&init_lock);
    wait_for_thread_registration(nthreads);
    pthread_mutex_unlock(&init_lock);
}
开发者ID:songweibeijing,项目名称:prefix_match_server,代码行数:55,代码来源:thread.cpp


示例19: thread_init

/*
 * Initializes the thread subsystem, creating various worker threads.
 *
 * nthreads  Number of worker event handler threads to spawn
 * main_base Event base for main thread
 */
void thread_init(int nthreads, struct event_base *main_base) {
    int         i;

    pthread_mutex_init(&cache_lock, NULL);
    pthread_mutex_init(&stats_lock, NULL);

    pthread_mutex_init(&init_lock, NULL);
    pthread_cond_init(&init_cond, NULL);

    pthread_mutex_init(&cqi_freelist_lock, NULL);
    cqi_freelist = NULL;

    threads = calloc(nthreads, sizeof(LIBEVENT_THREAD));
    if (! threads) {
        perror("Can't allocate thread descriptors");
        exit(1);
    }

    dispatcher_thread.base = main_base;
    dispatcher_thread.thread_id = pthread_self();

    for (i = 0; i < nthreads; i++) {
        int fds[2];
        if (pipe(fds)) {
            perror("Can't create notify pipe");
            exit(1);
        }

        threads[i].notify_receive_fd = fds[0];
        threads[i].notify_send_fd = fds[1];

        setup_thread(&threads[i]);
    }

    /* Create threads after we've done all the libevent setup. */
    for (i = 0; i < nthreads; i++) {
        create_worker(worker_libevent, &threads[i]);
    }

    /* Wait for all the threads to set themselves up before returning. */
    pthread_mutex_lock(&init_lock);
    while (init_count < nthreads) {
        pthread_cond_wait(&init_cond, &init_lock);
    }
    pthread_mutex_unlock(&init_lock);
}
开发者ID:469306621,项目名称:Languages,代码行数:52,代码来源:thread.c


示例20: start_threads

static void start_threads(struct ev_loop *loop, int tcp_sd, int udp_sd) {
    printf("tcp_sd=%d udp_sd=%d\n", tcp_sd, udp_sd);
    // Block all signals using the pthreads interface while starting threads,
    //  which causes them to inherit the same mask.
    sigset_t sigmask_all, sigmask_prev;
    sigfillset(&sigmask_all);
    pthread_sigmask(SIG_SETMASK, &sigmask_all, &sigmask_prev);

    // system scope scheduling, joinable threads
    pthread_attr_t attribs;
    pthread_attr_init(&attribs);
    pthread_attr_setdetachstate(&attribs, PTHREAD_CREATE_JOINABLE);
    pthread_attr_setscope(&attribs, PTHREAD_SCOPE_SYSTEM);

    //unsigned num_addrs = 1;
    //threads = threadids = calloc(NUM_THREADS, sizeof(pthread_t));
    threads = calloc(NUM_THREADS, sizeof(LIBEV_THREAD));

    // Start UDP threads
    /*for(uintptr_t i = 0; i < num_addrs; i++) {
        const dns_addr_t* addrconf = &gconfig.dns_addrs[i];
        int pthread_err = pthread_create(&threadids[addrconf->udp_threadnum], &attribs, &dnsio_udp_start, (void*)addrconf);
        if(pthread_err) log_fatal("pthread_create() of UDP DNS thread failed: %s", logf_errnum(pthread_err));
    }*/

    // Start TCP threads
    uintptr_t i = 0;
    for(i = 0; i < NUM_THREADS; i++) {
        //const dns_addr_t* addrconf = &gconfig.dns_addrs[i];
        //int pthread_err = pthread_create(&threadids[i], &attribs, &dnsio_tcp_start, (void*)addrconf);
        //if(pthread_err) log_fatal("pthread_create() of TCP DNS thread failed: %d", pthread_err);
        threads[i].loop = loop;
        threads[i].tcp_sd = tcp_sd;
        threads[i].udp_sd = udp_sd;
        create_worker(worker_libev, &threads[i]);
    }

    // Invoke thread cleanup handlers at exit time
    //if(atexit(threads_cleanup))
    //    log_fatal("atexit(threads_cleanup) failed: %s", logf_errno());

    // Restore the original mask in the main thread, so
    //  we can continue handling signals like normal
    pthread_sigmask(SIG_SETMASK, &sigmask_prev, NULL);
    pthread_attr_destroy(&attribs);
}
开发者ID:nickflink,项目名称:libev-examples,代码行数:46,代码来源:multithreaded-echo-server.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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