msgq empty status is checked when thread needs to be stopped

This commit is contained in:
Sukchan Lee 2017-02-15 09:05:34 +09:00
parent a079c6dcfe
commit 4da3365767
4 changed files with 30 additions and 5 deletions

View File

@ -79,6 +79,15 @@ CORE_DECLARE(int) msgq_recv(msgq_id id, char *msg, int msglen);
CORE_DECLARE(int) msgq_timedrecv(msgq_id id, char *msg, int msglen,
c_time_t timeout);
/**
* @param id
*
* @return 1(true) or 0(false)
* If ring buffer is empty, return 1(true)
* If ring buffer is not empty, return 0(false)
*/
CORE_DECLARE(int) msgq_is_empty(msgq_id id);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -309,3 +309,23 @@ int msgq_timedrecv(msgq_id id, char *msg, int msglen, c_time_t timeout)
return len;
}
int msgq_is_empty(msgq_id id)
{
msg_desc_t *md = (msg_desc_t*)id;
int n;
mutex_lock(md->mut_r);
n = rbuf_bytes(&md->rbuf);
if (n < md->msgsize + 2)
{
mutex_unlock(md->mut_r);
return 1;
}
else
{
mutex_unlock(md->mut_r);
return 0;
}
}

View File

@ -55,7 +55,7 @@ void *THREAD_FUNC mme_main(void *data)
prev_tm = time_now();
while (!thread_should_stop())
while ((!thread_should_stop()) || (!msgq_is_empty(queue_id)))
{
r = event_timedrecv(queue_id, &event, EVENT_WAIT_TIMEOUT);

View File

@ -110,8 +110,6 @@ static void enb_setup_test1(abts_case *tc, void *data)
}
pkbuf_free(recvbuf);
core_sleep(time_from_msec(300));
}
#define NUM_OF_TEST_ENB 32
@ -158,8 +156,6 @@ static void enb_setup_test2(abts_case *tc, void *data)
}
pkbuf_free(recvbuf);
core_sleep(time_from_sec(1));
}
abts_suite *test_enb_setup(abts_suite *suite)