summaryrefslogtreecommitdiff
path: root/pjlib/src/pjlib-test
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2009-07-02 08:24:22 +0000
committerBenny Prijono <bennylp@teluu.com>2009-07-02 08:24:22 +0000
commite9ad8e85add5d5efce32e1efb539c71a88c9c021 (patch)
treeab22e8d6d0ac9bfdf54a29f044dbe0c93ebb8455 /pjlib/src/pjlib-test
parent5b976613819b6e2eb8c84fcf419633b33709f9ed (diff)
Ticket #913: Concurrency problem in select ioqueue may corrupt descriptor set
- fixed the concurrency problem - also fixed ioqueue unregister test in pjlib-test git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2826 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pjlib-test')
-rw-r--r--pjlib/src/pjlib-test/ioq_unreg.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/pjlib/src/pjlib-test/ioq_unreg.c b/pjlib/src/pjlib-test/ioq_unreg.c
index 5b320964..6b19ed1f 100644
--- a/pjlib/src/pjlib-test/ioq_unreg.c
+++ b/pjlib/src/pjlib-test/ioq_unreg.c
@@ -93,9 +93,6 @@ static void on_read_complete(pj_ioqueue_key_t *key,
if (PJ_TIME_VAL_GTE(now, time_to_unregister)) {
sock_data.unregistered = 1;
pj_ioqueue_unregister(key);
- pj_mutex_destroy(sock_data.mutex);
- pj_pool_release(sock_data.pool);
- sock_data.pool = NULL;
return;
}
}
@@ -243,31 +240,30 @@ static int perform_unreg_test(pj_ioqueue_t *ioqueue,
/* Loop until test time ends */
for (;;) {
pj_time_val now, timeout;
+ int n;
pj_gettimeofday(&now);
if (test_method == UNREGISTER_IN_APP &&
PJ_TIME_VAL_GTE(now, time_to_unregister) &&
- sock_data.pool)
+ !sock_data.unregistered)
{
- //Can't do this otherwise it'll deadlock
- //pj_mutex_lock(sock_data.mutex);
-
sock_data.unregistered = 1;
+ /* Wait (as much as possible) for callback to complete */
+ pj_mutex_lock(sock_data.mutex);
+ pj_mutex_unlock(sock_data.mutex);
pj_ioqueue_unregister(sock_data.key);
- //pj_mutex_unlock(sock_data.mutex);
- pj_mutex_destroy(sock_data.mutex);
- pj_pool_release(sock_data.pool);
- sock_data.pool = NULL;
}
if (PJ_TIME_VAL_GT(now, end_time) && sock_data.unregistered)
break;
timeout.sec = 0; timeout.msec = 10;
- pj_ioqueue_poll(ioqueue, &timeout);
- //pj_thread_sleep(1);
-
+ n = pj_ioqueue_poll(ioqueue, &timeout);
+ if (n < 0) {
+ app_perror("pj_ioqueue_poll error", -n);
+ pj_thread_sleep(1);
+ }
}
thread_quitting = 1;
@@ -277,6 +273,11 @@ static int perform_unreg_test(pj_ioqueue_t *ioqueue,
pj_thread_destroy(thread[i]);
}
+ /* Destroy data */
+ pj_mutex_destroy(sock_data.mutex);
+ pj_pool_release(sock_data.pool);
+ sock_data.pool = NULL;
+
if (other_socket) {
pj_ioqueue_unregister(osd.key);
}
@@ -314,7 +315,7 @@ static int udp_ioqueue_unreg_test_imp(pj_bool_t allow_concur)
return -12;
}
- PJ_LOG(3, (THIS_FILE, "...ioqueue unregister stress test 0/3 (%s)",
+ PJ_LOG(3, (THIS_FILE, "...ioqueue unregister stress test 0/3, unregister in app (%s)",
pj_ioqueue_name()));
for (i=0; i<LOOP; ++i) {
pj_ansi_sprintf(title, "repeat %d/%d", i, LOOP);
@@ -324,7 +325,7 @@ static int udp_ioqueue_unreg_test_imp(pj_bool_t allow_concur)
}
- PJ_LOG(3, (THIS_FILE, "...ioqueue unregister stress test 1/3 (%s)",
+ PJ_LOG(3, (THIS_FILE, "...ioqueue unregister stress test 1/3, unregister in app (%s)",
pj_ioqueue_name()));
for (i=0; i<LOOP; ++i) {
pj_ansi_sprintf(title, "repeat %d/%d", i, LOOP);
@@ -335,7 +336,7 @@ static int udp_ioqueue_unreg_test_imp(pj_bool_t allow_concur)
test_method = UNREGISTER_IN_CALLBACK;
- PJ_LOG(3, (THIS_FILE, "...ioqueue unregister stress test 2/3 (%s)",
+ PJ_LOG(3, (THIS_FILE, "...ioqueue unregister stress test 2/3, unregister in cb (%s)",
pj_ioqueue_name()));
for (i=0; i<LOOP; ++i) {
pj_ansi_sprintf(title, "repeat %d/%d", i, LOOP);
@@ -345,7 +346,7 @@ static int udp_ioqueue_unreg_test_imp(pj_bool_t allow_concur)
}
- PJ_LOG(3, (THIS_FILE, "...ioqueue unregister stress test 3/3 (%s)",
+ PJ_LOG(3, (THIS_FILE, "...ioqueue unregister stress test 3/3, unregister in cb (%s)",
pj_ioqueue_name()));
for (i=0; i<LOOP; ++i) {
pj_ansi_sprintf(title, "repeat %d/%d", i, LOOP);
@@ -366,7 +367,7 @@ int udp_ioqueue_unreg_test(void)
rc = udp_ioqueue_unreg_test_imp(PJ_TRUE);
if (rc != 0)
- return rc;
+ return rc;
rc = udp_ioqueue_unreg_test_imp(PJ_FALSE);
if (rc != 0)