本文整理汇总了C++中pj_thread_create函数的典型用法代码示例。如果您正苦于以下问题:C++ pj_thread_create函数的具体用法?C++ pj_thread_create怎么用?C++ pj_thread_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pj_thread_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: init_stack
static pj_status_t init_stack()
{
pj_sockaddr addr;
pjsip_inv_callback inv_cb;
pj_status_t status;
pj_log_set_level(5);
status = pj_init();
CHECK_STATUS();
pj_log_set_level(3);
status = pjlib_util_init();
CHECK_STATUS();
pj_caching_pool_init(&app.cp, NULL, 0);
app.pool = pj_pool_create( &app.cp.factory, "sipecho", 512, 512, 0);
status = pjsip_endpt_create(&app.cp.factory, NULL, &app.sip_endpt);
CHECK_STATUS();
pj_log_set_level(4);
pj_sockaddr_init(AF, &addr, NULL, (pj_uint16_t)SIP_PORT);
if (AF == pj_AF_INET()) {
status = pjsip_udp_transport_start( app.sip_endpt, &addr.ipv4, NULL,
1, NULL);
} else if (AF == pj_AF_INET6()) {
status = pjsip_udp_transport_start6(app.sip_endpt, &addr.ipv6, NULL,
1, NULL);
} else {
status = PJ_EAFNOTSUP;
}
pj_log_set_level(3);
CHECK_STATUS();
status = pjsip_tsx_layer_init_module(app.sip_endpt) ||
pjsip_ua_init_module( app.sip_endpt, NULL );
CHECK_STATUS();
pj_bzero(&inv_cb, sizeof(inv_cb));
inv_cb.on_state_changed = &call_on_state_changed;
inv_cb.on_new_session = &call_on_forked;
inv_cb.on_media_update = &call_on_media_update;
inv_cb.on_rx_offer = &call_on_rx_offer;
status = pjsip_inv_usage_init(app.sip_endpt, &inv_cb) ||
pjsip_100rel_init_module(app.sip_endpt) ||
pjsip_endpt_register_module( app.sip_endpt, &mod_sipecho) ||
pjsip_endpt_register_module( app.sip_endpt, &msg_logger) ||
//pjmedia_endpt_create(&app.cp.factory,
// pjsip_endpt_get_ioqueue(app.sip_endpt),
// 0, &app.med_endpt) ||
pj_thread_create(app.pool, "sipecho", &worker_proc, NULL, 0, 0,
&app.worker_thread);
CHECK_STATUS();
return PJ_SUCCESS;
}
开发者ID:xhook,项目名称:asterisk-v11,代码行数:60,代码来源:sipecho.c
示例2: job_queue_create
static pj_status_t job_queue_create(pj_pool_t *pool, job_queue **pjq)
{
unsigned i;
pj_status_t status;
job_queue *jq = PJ_POOL_ZALLOC_T(pool, job_queue);
jq->size = MAX_JOBS;
status = pj_sem_create(pool, "thread_sem", 0, jq->size + 1, &jq->sem);
if (status != PJ_SUCCESS)
goto on_error;
for (i = 0; i < jq->size; i++) {
status = pj_sem_create(pool, "job_sem", 0, 1, &jq->job_sem[i]);
if (status != PJ_SUCCESS)
goto on_error;
}
status = pj_mutex_create_recursive(pool, "job_mutex", &jq->mutex);
if (status != PJ_SUCCESS)
goto on_error;
status = pj_thread_create(pool, "job_th", job_thread, jq, 0, 0,
&jq->thread);
if (status != PJ_SUCCESS)
goto on_error;
*pjq = jq;
return PJ_SUCCESS;
on_error:
job_queue_destroy(jq);
return status;
}
开发者ID:CloudStyleStudio,项目名称:csip,代码行数:33,代码来源:android_opengl.c
示例3: m_global
pjs_frame_processor::pjs_frame_processor(pjs_global& global,
unsigned capacity, unsigned samples_per_frame) :
m_global(global), m_samples_per_frame(samples_per_frame)
{
m_started = false;
m_thread = NULL;
m_ready = false;
m_exit = false;
m_pool = pj_pool_create(m_global.get_pool_factory(), "pjs_frame_processor",
128, 128, NULL);
m_lock = new PPJ_SemaphoreLock(m_pool, NULL, 1, 1);
pj_status_t status = pjmedia_circ_buf_create(m_pool, capacity, &m_buffer);
if (status == PJ_SUCCESS)
{
status = pj_thread_create(m_pool, "frame processor thread",
(pj_thread_proc*) &s_thread_proc, this, PJ_THREAD_DEFAULT_STACK_SIZE, PJ_THREAD_SUSPENDED,
&m_thread);
if (status != PJ_SUCCESS)
m_thread = NULL;
else
m_ready = true;
}
else
m_buffer = NULL;
}
开发者ID:ddv2005,项目名称:intercom,代码行数:26,代码来源:pjs_frame_processor.cpp
示例4: PJ_DEF
/*
* Start the clock.
*/
PJ_DEF(pj_status_t) pjmedia_clock_start(pjmedia_clock *clock)
{
pj_timestamp now;
pj_status_t status;
PJ_ASSERT_RETURN(clock != NULL, PJ_EINVAL);
if (clock->running)
return PJ_SUCCESS;
status = pj_get_timestamp(&now);
if (status != PJ_SUCCESS)
return status;
clock->next_tick.u64 = now.u64 + clock->interval.u64;
clock->running = PJ_TRUE;
clock->quitting = PJ_FALSE;
if ((clock->options & PJMEDIA_CLOCK_NO_ASYNC) == 0 && !clock->thread) {
status = pj_thread_create(clock->pool, "clock", &clock_thread, clock,
0, 0, &clock->thread);
if (status != PJ_SUCCESS) {
pj_lock_destroy(clock->lock);
return status;
}
}
return PJ_SUCCESS;
}
开发者ID:conght,项目名称:BLM-Lib,代码行数:32,代码来源:clock_thread.c
示例5: udp_echo_srv_ioqueue
int udp_echo_srv_ioqueue(void)
{
pj_pool_t *pool;
pj_sock_t sock;
pj_ioqueue_t *ioqueue;
pj_ioqueue_callback callback;
int i;
pj_thread_t *thread[ECHO_SERVER_MAX_THREADS];
pj_status_t rc;
pj_bzero(&callback, sizeof(callback));
callback.on_read_complete = &on_read_complete;
callback.on_write_complete = &on_write_complete;
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
if (!pool)
return -10;
rc = pj_ioqueue_create(pool, 2, &ioqueue);
if (rc != PJ_SUCCESS) {
app_perror("...pj_ioqueue_create error", rc);
return -20;
}
rc = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0,
ECHO_SERVER_START_PORT, &sock);
if (rc != PJ_SUCCESS) {
app_perror("...app_socket error", rc);
return -30;
}
rc = pj_ioqueue_register_sock(pool, ioqueue, sock, NULL,
&callback, &key);
if (rc != PJ_SUCCESS) {
app_perror("...error registering socket", rc);
return -40;
}
rc = pj_atomic_create(pool, 0, &total_bytes);
if (rc != PJ_SUCCESS) {
app_perror("...error creating atomic variable", rc);
return -45;
}
for (i=0; i<ECHO_SERVER_MAX_THREADS; ++i) {
rc = pj_thread_create(pool, NULL, &worker_thread, ioqueue,
PJ_THREAD_DEFAULT_STACK_SIZE, 0,
&thread[i]);
if (rc != PJ_SUCCESS) {
app_perror("...create thread error", rc);
return -50;
}
}
echo_srv_common_loop(total_bytes);
return 0;
}
开发者ID:AbhaySingh,项目名称:pjproject,代码行数:58,代码来源:udp_echo_srv_ioqueue.c
示例6: create
//
// Create a thread.
//
static pj_status_t create( Pj_Pool *pool, pj_thread_t **thread,
pj_thread_proc *proc, void *arg,
unsigned flags = 0,
const char *name = NULL,
pj_size_t stack_size = 0 )
{
return pj_thread_create(pool->pool_(), name, proc, arg, stack_size,
flags, thread);
}
开发者ID:0x0B501E7E,项目名称:pjproject,代码行数:12,代码来源:os.hpp
示例7: strm_start
/* API: start stream. */
static pj_status_t strm_start(pjmedia_aud_stream *s)
{
struct android_aud_stream *stream = (struct android_aud_stream*)s;
PJ_LOG(4,(THIS_FILE, "Starting %s stream..", stream->name.ptr));
stream->quit_flag = 0;
JNIEnv *jni_env = 0;
ATTACH_JVM(jni_env);
pj_status_t status;
//Start threads
if(stream->record){
status = pj_thread_create(stream->pool, "android_recorder", &AndroidRecorderCallback, stream, 0, 0, &stream->rec_thread);
if (status != PJ_SUCCESS) {
goto on_error;
}
// pj_sem_wait(stream->audio_launch_sem);
}
if(stream->track){
status = pj_thread_create(stream->pool, "android_track", &AndroidTrackCallback, stream, 0, 0, &stream->play_thread);
if (status != PJ_SUCCESS) {
goto on_error;
}
// pj_sem_wait(stream->audio_launch_sem);
}
PJ_LOG(4,(THIS_FILE, "Starting done"));
status = PJ_SUCCESS;
on_error:
DETACH_JVM(jni_env);
if(status != PJ_SUCCESS){
strm_destroy(&stream->base);
}
return status;
}
开发者ID:RockHardJim,项目名称:idphone,代码行数:43,代码来源:android_jni_dev.cpp
示例8: PJ_DEF
/*
* Create media clock.
*/
PJ_DEF(pj_status_t) pjmedia_clock_create( pj_pool_t *pool,
unsigned clock_rate,
unsigned channel_count,
unsigned samples_per_frame,
unsigned options,
pjmedia_clock_callback *cb,
void *user_data,
pjmedia_clock **p_clock)
{
pjmedia_clock *clock;
pj_status_t status;
PJ_ASSERT_RETURN(pool && clock_rate && samples_per_frame && p_clock,
PJ_EINVAL);
clock = PJ_POOL_ALLOC_T(pool, pjmedia_clock);
status = pj_get_timestamp_freq(&clock->freq);
if (status != PJ_SUCCESS)
return status;
clock->interval.u64 = samples_per_frame * clock->freq.u64 /
channel_count / clock_rate;
clock->next_tick.u64 = 0;
clock->timestamp.u64 = 0;
clock->max_jump = MAX_JUMP_MSEC * clock->freq.u64 / 1000;
clock->timestamp_inc = samples_per_frame / channel_count;
clock->options = options;
clock->cb = cb;
clock->user_data = user_data;
clock->thread = NULL;
clock->running = PJ_FALSE;
clock->quitting = PJ_FALSE;
/* I don't think we need a mutex, so we'll use null. */
status = pj_lock_create_null_mutex(pool, "clock", &clock->lock);
if (status != PJ_SUCCESS)
return status;
if ((clock->options & PJMEDIA_CLOCK_NO_ASYNC) == 0) {
status = pj_thread_create(pool, "clock", &clock_thread, clock,
0, 0, &clock->thread);
if (status != PJ_SUCCESS) {
pj_lock_destroy(clock->lock);
return status;
}
}
*p_clock = clock;
return PJ_SUCCESS;
}
开发者ID:Agostin,项目名称:csipsimple,代码行数:57,代码来源:clock_thread.c
示例9: start_stack
pj_status_t start_stack()
{
pj_status_t status = PJ_SUCCESS;
quit_flag = PJ_FALSE;
// Create worker threads first as they take work from the PJSIP threads so
// need to be ready.
for (size_t ii = 0; ii < worker_threads.size(); ++ii)
{
pj_thread_t* thread;
status = pj_thread_create(stack_data.pool, "worker", &worker_thread,
NULL, 0, 0, &thread);
if (status != PJ_SUCCESS)
{
LOG_ERROR("Error creating worker thread, %s",
PJUtils::pj_status_to_string(status).c_str());
return 1;
}
worker_threads[ii] = thread;
}
// Now create the PJSIP threads.
for (size_t ii = 0; ii < pjsip_threads.size(); ++ii)
{
pj_thread_t* thread;
status = pj_thread_create(stack_data.pool, "pjsip", &pjsip_thread,
NULL, 0, 0, &thread);
if (status != PJ_SUCCESS)
{
LOG_ERROR("Error creating PJSIP thread, %s",
PJUtils::pj_status_to_string(status).c_str());
return 1;
}
pjsip_threads[ii] = thread;
}
return status;
}
开发者ID:gangbanlau,项目名称:sprout,代码行数:39,代码来源:stack.cpp
示例10: PJ_DEF
/*
* Create media clock.
*/
PJ_DEF(pj_status_t) pjmedia_clock_create( pj_pool_t *pool,
unsigned clock_rate,
unsigned samples_per_frame,
unsigned options,
pjmedia_clock_callback *cb,
void *user_data,
pjmedia_clock **p_clock)
{
pjmedia_clock *clock;
pj_status_t status;
PJ_ASSERT_RETURN(pool && clock_rate && samples_per_frame && p_clock,
PJ_EINVAL);
clock = pj_pool_alloc(pool, sizeof(pjmedia_clock));
status = pj_get_timestamp_freq(&clock->freq);
if (status != PJ_SUCCESS)
return status;
clock->interval.u64 = samples_per_frame * clock->freq.u64 / clock_rate;
clock->next_tick.u64 = 0;
clock->timestamp.u64 = 0;
clock->samples_per_frame = samples_per_frame;
clock->options = options;
clock->cb = cb;
clock->user_data = user_data;
clock->thread = NULL;
clock->running = PJ_FALSE;
clock->quitting = PJ_FALSE;
/* I don't think we need a mutex, so we'll use null. */
status = pj_lock_create_null_mutex(pool, "clock", &clock->lock);
if (status != PJ_SUCCESS)
return status;
status = pj_thread_create(pool, "clock", &clock_thread, clock,
0, 0, &clock->thread);
if (status != PJ_SUCCESS) {
pj_lock_destroy(clock->lock);
return status;
}
*p_clock = clock;
return PJ_SUCCESS;
}
开发者ID:svn2github,项目名称:pjproject,代码行数:52,代码来源:clock_thread.c
示例11: alsa_stream_start
/* API: start stream */
static pj_status_t alsa_stream_start (pjmedia_aud_stream *s)
{
struct alsa_stream *stream = (struct alsa_stream*)s;
pj_status_t status = PJ_SUCCESS;
stream->quit = 0;
if (stream->param.dir & PJMEDIA_DIR_PLAYBACK) {
status = pj_thread_create (stream->pool,
"alsasound_playback",
pb_thread_func,
stream,
0, //ZERO,
0,
&stream->pb_thread);
if (status != PJ_SUCCESS)
return status;
}
if (stream->param.dir & PJMEDIA_DIR_CAPTURE) {
status = pj_thread_create (stream->pool,
"alsasound_playback",
ca_thread_func,
stream,
0, //ZERO,
0,
&stream->ca_thread);
if (status != PJ_SUCCESS) {
stream->quit = PJ_TRUE;
pj_thread_join(stream->pb_thread);
pj_thread_destroy(stream->pb_thread);
stream->pb_thread = NULL;
}
}
return status;
}
开发者ID:elimelec,项目名称:pjproject,代码行数:37,代码来源:alsa_dev.c
示例12: echo_srv_sync
int echo_srv_sync(void)
{
pj_pool_t *pool;
pj_sock_t sock;
pj_thread_t *thread[ECHO_SERVER_MAX_THREADS];
pj_status_t rc;
int i;
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
if (!pool)
return -5;
rc = pj_atomic_create(pool, 0, &total_bytes);
if (rc != PJ_SUCCESS) {
app_perror("...unable to create atomic_var", rc);
return -6;
}
rc = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(),0, ECHO_SERVER_START_PORT, &sock);
if (rc != PJ_SUCCESS) {
app_perror("...socket error", rc);
return -10;
}
for (i=0; i<ECHO_SERVER_MAX_THREADS; ++i) {
rc = pj_thread_create(pool, NULL, &worker_thread, (void*)sock,
PJ_THREAD_DEFAULT_STACK_SIZE, 0,
&thread[i]);
if (rc != PJ_SUCCESS) {
app_perror("...unable to create thread", rc);
return -20;
}
}
PJ_LOG(3,("", "...UDP echo server running with %d threads at port %d",
ECHO_SERVER_MAX_THREADS, ECHO_SERVER_START_PORT));
PJ_LOG(3,("", "...Press Ctrl-C to abort"));
echo_srv_common_loop(total_bytes);
return 0;
}
开发者ID:LuLei2013,项目名称:pjproject,代码行数:41,代码来源:udp_echo_srv_sync.c
示例13: PJ_DEF
PJ_DEF(pj_status_t) pjmedia_event_mgr_create(pj_pool_t *pool,
unsigned options,
pjmedia_event_mgr **p_mgr)
{
pjmedia_event_mgr *mgr;
pj_status_t status;
mgr = PJ_POOL_ZALLOC_T(pool, pjmedia_event_mgr);
mgr->pool = pj_pool_create(pool->factory, "evt mgr", 500, 500, NULL);
pj_list_init(&mgr->esub_list);
pj_list_init(&mgr->free_esub_list);
if (!(options & PJMEDIA_EVENT_MGR_NO_THREAD)) {
status = pj_sem_create(mgr->pool, "ev_sem", 0, MAX_EVENTS + 1,
&mgr->sem);
if (status != PJ_SUCCESS)
return status;
status = pj_thread_create(mgr->pool, "ev_thread",
&event_worker_thread,
mgr, 0, 0, &mgr->thread);
if (status != PJ_SUCCESS) {
pjmedia_event_mgr_destroy(mgr);
return status;
}
}
status = pj_mutex_create_recursive(mgr->pool, "ev_mutex", &mgr->mutex);
if (status != PJ_SUCCESS) {
pjmedia_event_mgr_destroy(mgr);
return status;
}
if (!event_manager_instance)
event_manager_instance = mgr;
if (p_mgr)
*p_mgr = mgr;
return PJ_SUCCESS;
}
开发者ID:LuLei2013,项目名称:pjproject,代码行数:41,代码来源:event.c
示例14: start_pjsip_threads
pj_status_t start_pjsip_threads()
{
pj_status_t status = PJ_SUCCESS;
for (size_t ii = 0; ii < pjsip_threads.size(); ++ii)
{
pj_thread_t* thread;
status = pj_thread_create(stack_data.pool, "pjsip", &pjsip_thread_func,
NULL, 0, 0, &thread);
if (status != PJ_SUCCESS)
{
LOG_ERROR("Error creating PJSIP thread, %s",
PJUtils::pj_status_to_string(status).c_str());
return 1;
}
pjsip_threads[ii] = thread;
}
return PJ_SUCCESS;
}
开发者ID:matt-williams,项目名称:sprout,代码行数:21,代码来源:stack.cpp
示例15: create_connection
void ConnectionPool::init()
{
// Create an initial set of connections.
for (int ii = 0; ii < _num_connections; ++ii)
{
create_connection(ii);
}
if (_recycle_period != 0)
{
// Spawn a thread to recycle connections
pj_status_t status = pj_thread_create(_pool, "recycler",
&recycle_thread,
(void*)this, 0, 0, &_recycler);
if (status != PJ_SUCCESS)
{
TRC_ERROR("Error creating recycler thread, %s",
PJUtils::pj_status_to_string(status).c_str());
}
}
TRC_DEBUG("Started %d connections to %.*s:%d", _num_connections, _target.host.slen, _target.host.ptr, _target.port);
}
开发者ID:AiprNick,项目名称:sprout,代码行数:23,代码来源:connection_pool.cpp
示例16: main
int main() {
pj_caching_pool cp;
pj_pool_t *pool;
int i;
pj_thread_t *thread1;
pj_log_set_level(3);
CHECK(__FILE__, pj_init());
pj_srand(123765);
pj_caching_pool_init(&cp, NULL, 1024);
pool = pj_pool_create(&cp.factory, "objpool", 128, 128, NULL);
pj_thread_create(pool, "thread1", &do_test, pool, PJ_THREAD_DEFAULT_STACK_SIZE, 0, &thread1);
pj_thread_sleep(500);
do_test(pool);
pj_thread_join(thread1);
pj_pool_release(pool);
pj_caching_pool_destroy(&cp);
pj_shutdown();
return 0;
}
开发者ID:mocidis,项目名称:object-pool,代码行数:24,代码来源:main.c
示例17: create_std_server
/* Instantiate standard server */
static int create_std_server(pj_stun_auth_type auth_type,
pj_bool_t responding)
{
pj_pool_t *pool;
pj_stun_session_cb sess_cb;
pj_stun_auth_cred cred;
pj_status_t status;
/* Create server */
pool = pj_pool_create(mem, "server", 1000, 1000, NULL);
server = PJ_POOL_ZALLOC_T(pool, struct server);
server->pool = pool;
server->auth_type = auth_type;
server->responding = responding;
/* Create STUN session */
pj_bzero(&sess_cb, sizeof(sess_cb));
sess_cb.on_rx_request = &server_on_rx_request;
sess_cb.on_send_msg = &server_send_msg;
status = pj_stun_session_create(&stun_cfg, "server", &sess_cb, PJ_FALSE, NULL, &server->sess);
if (status != PJ_SUCCESS) {
destroy_server();
return -10;
}
/* Configure credential */
pj_bzero(&cred, sizeof(cred));
cred.type = PJ_STUN_AUTH_CRED_DYNAMIC;
cred.data.dyn_cred.get_auth = &server_get_auth;
cred.data.dyn_cred.get_password = &server_get_password;
cred.data.dyn_cred.verify_nonce = &server_verify_nonce;
status = pj_stun_session_set_credential(server->sess, auth_type, &cred);
if (status != PJ_SUCCESS) {
destroy_server();
return -20;
}
/* Create socket */
status = pj_sock_socket(pj_AF_INET(), pj_SOCK_DGRAM(), 0, &server->sock);
if (status != PJ_SUCCESS) {
destroy_server();
return -30;
}
/* Bind */
pj_sockaddr_in_init(&server->addr.ipv4, NULL, 0);
status = pj_sock_bind(server->sock, &server->addr, pj_sockaddr_get_len(&server->addr));
if (status != PJ_SUCCESS) {
destroy_server();
return -40;
} else {
/* Get the bound IP address */
int namelen = sizeof(server->addr);
pj_sockaddr addr;
status = pj_sock_getsockname(server->sock, &server->addr, &namelen);
if (status != PJ_SUCCESS) {
destroy_server();
return -43;
}
status = pj_gethostip(pj_AF_INET(), &addr);
if (status != PJ_SUCCESS) {
destroy_server();
return -45;
}
pj_sockaddr_copy_addr(&server->addr, &addr);
}
/* Create worker thread */
status = pj_thread_create(pool, "server", &server_thread, 0, 0, 0, &server->thread);
if (status != PJ_SUCCESS) {
destroy_server();
return -30;
}
return 0;
}
开发者ID:Antares84,项目名称:asuswrt-merlin,代码行数:81,代码来源:sess_auth.c
示例18: timeslice_test
/*
* timeslice_test()
*/
static int timeslice_test(void)
{
enum { NUM_THREADS = 4 };
pj_pool_t *pool;
pj_uint32_t counter[NUM_THREADS], lowest, highest, diff;
pj_thread_t *thread[NUM_THREADS];
unsigned i;
pj_status_t rc;
quit_flag = 0;
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
if (!pool)
return -10;
PJ_LOG(3,(THIS_FILE, "..timeslice testing with %d threads", NUM_THREADS));
/* Create all threads in suspended mode. */
for (i=0; i<NUM_THREADS; ++i) {
counter[i] = i;
rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc,
&counter[i],
PJ_THREAD_DEFAULT_STACK_SIZE,
PJ_THREAD_SUSPENDED,
&thread[i]);
if (rc!=PJ_SUCCESS) {
app_perror("...ERROR in pj_thread_create()", rc);
return -20;
}
}
/* Sleep for 1 second.
* The purpose of this is to test whether all threads are suspended.
*/
TRACE__((THIS_FILE, " Main thread waiting.."));
pj_thread_sleep(1000);
TRACE__((THIS_FILE, " Main thread resuming.."));
/* Check that all counters are still zero. */
for (i=0; i<NUM_THREADS; ++i) {
if (counter[i] > i) {
PJ_LOG(3,(THIS_FILE, "....ERROR! Thread %d-th is not suspended!",
i));
return -30;
}
}
/* Now resume all threads. */
for (i=0; i<NUM_THREADS; ++i) {
TRACE__((THIS_FILE, " Resuming thread %d [%p]..", i, thread[i]));
rc = pj_thread_resume(thread[i]);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR in pj_thread_resume()", rc);
return -40;
}
}
/* Main thread sleeps for some time to allow threads to run.
* The longer we sleep, the more accurate the calculation will be,
* but it'll make user waits for longer for the test to finish.
*/
TRACE__((THIS_FILE, " Main thread waiting (5s).."));
pj_thread_sleep(5000);
TRACE__((THIS_FILE, " Main thread resuming.."));
/* Signal all threads to quit. */
quit_flag = 1;
/* Wait until all threads quit, then destroy. */
for (i=0; i<NUM_THREADS; ++i) {
TRACE__((THIS_FILE, " Main thread joining thread %d [%p]..",
i, thread[i]));
rc = pj_thread_join(thread[i]);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR in pj_thread_join()", rc);
return -50;
}
TRACE__((THIS_FILE, " Destroying thread %d [%p]..", i, thread[i]));
rc = pj_thread_destroy(thread[i]);
if (rc != PJ_SUCCESS) {
app_perror("...ERROR in pj_thread_destroy()", rc);
return -60;
}
}
TRACE__((THIS_FILE, " Main thread calculating time slices.."));
/* Now examine the value of the counters.
* Check that all threads had equal proportion of processing.
*/
lowest = 0xFFFFFFFF;
highest = 0;
for (i=0; i<NUM_THREADS; ++i) {
if (counter[i] < lowest)
lowest = counter[i];
if (counter[i] > highest)
highest = counter[i];
//.........这里部分代码省略.........
开发者ID:avble,项目名称:natClientEx,代码行数:101,代码来源:thread.c
示例19: simple_thread
/*
* simple_thread()
*/
static int simple_thread(const char *title, unsigned flags)
{
pj_pool_t *pool;
pj_thread_t *thread;
pj_status_t rc;
pj_uint32_t counter = 0;
PJ_LOG(3,(THIS_FILE, "..%s", title));
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
if (!pool)
return -1000;
quit_flag = 0;
TRACE__((THIS_FILE, " Creating thread 0.."));
rc = pj_thread_create(pool, "thread", (pj_thread_proc*)&thread_proc,
&counter,
PJ_THREAD_DEFAULT_STACK_SIZE,
flags,
&thread);
if (rc != PJ_SUCCESS) {
app_perror("...error: unable to create thread", rc);
return -1010;
}
TRACE__((THIS_FILE, " Main thread waiting.."));
pj_thread_sleep(1500);
TRACE__((THIS_FILE, " Main thread resuming.."));
if (flags & PJ_THREAD_SUSPENDED) {
/* Check that counter is still zero */
if (counter != 0) {
PJ_LOG(3,(THIS_FILE, "...error: thread is not suspended"));
return -1015;
}
rc = pj_thread_resume(thread);
if (rc != PJ_SUCCESS) {
app_perror("...error: resume thread error", rc);
return -1020;
}
}
PJ_LOG(3,(THIS_FILE, "..waiting for thread to quit.."));
pj_thread_sleep(1500);
quit_flag = 1;
pj_thread_join(thread);
pj_pool_release(pool);
if (counter == 0) {
PJ_LOG(3,(THIS_FILE, "...error: thread is not running"));
return -1025;
}
PJ_LOG(3,(THIS_FILE, "...%s success", title));
return PJ_SUCCESS;
}
开发者ID:avble,项目名称:natClientEx,代码行数:66,代码来源:thread.c
示例20: perform_test
//.........这里部分代码省略.........
/* Start reading. */
TRACE_((THIS_FILE, " pj_ioqueue_recv.."));
bytes = items[i].buffer_size;
rc = pj_ioqueue_recv(items[i].server_key, &items[i].recv_op,
items[i].incoming_buffer, &bytes,
0);
if (rc != PJ_EPENDING) {
app_perror("...error: pj_ioqueue_recv", rc);
return -73;
}
/* Start writing. */
TRACE_((THIS_FILE, " pj_ioqueue_write.."));
bytes = items[i].buffer_size;
rc = pj_ioqueue_send(items[i].client_key, &items[i].send_op,
items[i].outgoing_buffer, &bytes, 0);
if (rc != PJ_SUCCESS && rc != PJ_EPENDING) {
app_perror("...error: pj_ioqueue_write", rc);
return -76;
}
items[i].has_pending_send = (rc==PJ_EPENDING);
}
/* Create the threads. */
for (i=0; i<thread_cnt; ++i) {
struct thread_arg *arg;
arg = (struct thread_arg*) pj_pool_zalloc(pool, sizeof(*arg));
arg->id = i;
arg->ioqueue = ioqueue;
arg->counter = 0;
rc = pj_thread_create( pool, NULL,
&worker_thread,
arg,
PJ_THREAD_DEFAULT_STACK_SIZE,
PJ_THREAD_SUSPENDED, &thread[i] );
if (rc != PJ_SUCCESS) {
app_perror("...error: unable to create thread", rc);
return -80;
}
}
/* Mark start time. */
rc = pj_get_timestamp(&start);
if (rc != PJ_SUCCESS)
return -90;
/* Start the thread. */
TRACE_((THIS_FILE, " resuming all threads.."));
for (i=0; i<thread_cnt; ++i) {
rc = pj_thread_resume(thread[i]);
if (rc != 0)
return -100;
}
/* Wait for MSEC_DURATION seconds.
* This should be as simple as pj_thread_sleep(MSEC_DURATION) actually,
* but unfortunately it doesn't work when system doesn't employ
* timeslicing for threads.
*/
TRACE_((THIS_FILE, " wait for few seconds.."));
do {
pj_thread_sleep(1);
开发者ID:RyanLee27,项目名称:pjproject,代码行数:66,代码来源:ioq_perf.c
注:本文中的pj_thread_create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论