update it

This commit is contained in:
Sukchan Lee 2017-03-27 10:22:30 +09:00
parent 126475b83d
commit 5fdc359bec
15 changed files with 67 additions and 99 deletions

View File

@ -64,7 +64,7 @@ CORE_DECLARE(status_t) event_delete(msgq_id queue_id);
* @return If success, return the size to be sent.
* If else, return -1
*/
CORE_DECLARE(int) event_send(msgq_id queue_id, event_t *e);
CORE_DECLARE(status_t) event_send(msgq_id queue_id, event_t *e);
/**
* Receive a event from event queue with timeout
@ -73,7 +73,7 @@ CORE_DECLARE(int) event_send(msgq_id queue_id, event_t *e);
* If timout occurs, return CORE_TIMEUP.
* If else, return -1.
*/
CORE_DECLARE(int) event_timedrecv(
CORE_DECLARE(status_t) event_timedrecv(
msgq_id queue_id, event_t *e, c_time_t timeout);
/**

View File

@ -55,7 +55,7 @@ CORE_DECLARE(status_t) msgq_delete(msgq_id id);
* @return the number of bytes to be sent. If there is insufficient room in
* ring buffer, return CORE_EAGAIN. If any error, CORE_ERROR.
*/
CORE_DECLARE(int) msgq_send(msgq_id id, const char *msg, int msglen);
CORE_DECLARE(status_t) msgq_send(msgq_id id, const char *msg, int msglen);
/**
* @param id
@ -65,7 +65,7 @@ CORE_DECLARE(int) msgq_send(msgq_id id, const char *msg, int msglen);
* @return the number of bytes to be read. If any error, CORE_ERROR.
* If ring buffer is empty and MSGQ_O_NONBLOCK set, CORE_EAGAIN.
*/
CORE_DECLARE(int) msgq_recv(msgq_id id, char *msg, int msglen);
CORE_DECLARE(status_t) msgq_recv(msgq_id id, char *msg, int msglen);
/**
* @param id
@ -76,18 +76,9 @@ CORE_DECLARE(int) msgq_recv(msgq_id id, char *msg, int msglen);
* If ring buffer is empty and MSGQ_O_NONBLOCK set, CORE_EAGAIN.
* If time out with empty buffer, CORE_TIMEUP.
*/
CORE_DECLARE(int) msgq_timedrecv(msgq_id id, char *msg, int msglen,
CORE_DECLARE(status_t) 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

@ -34,55 +34,57 @@ status_t event_delete(msgq_id queue_id)
return CORE_OK;
}
int event_send(msgq_id queue_id, event_t *e)
status_t event_send(msgq_id queue_id, event_t *e)
{
int r = 0;
status_t rv;
d_assert(e, return -1, "Null param");
d_assert(queue_id, return -1, "event queue isn't initialized");
r = msgq_send(queue_id, (const char*)e, EVENT_SIZE);
if (r != EVENT_SIZE)
rv = msgq_send(queue_id, (const char*)e, EVENT_SIZE);
if (rv == CORE_EAGAIN)
{
d_warn("msgq_send() failed");
return -1;
d_warn("msgq_send full");
}
else if (rv == CORE_ERROR)
{
d_error("msgq_send failed");
}
return r;
return rv;
}
int event_timedrecv(msgq_id queue_id, event_t *e, c_time_t timeout)
status_t event_timedrecv(msgq_id queue_id, event_t *e, c_time_t timeout)
{
int r;
status_t rv;
d_assert(e, return -1, "Null param");
d_assert(queue_id, return -1, "event queue isn't initialized");
r = msgq_timedrecv(queue_id, (char*)e, EVENT_SIZE, timeout);
if (r != CORE_TIMEUP && r != EVENT_SIZE)
rv = msgq_timedrecv(queue_id, (char*)e, EVENT_SIZE, timeout);
if (rv == CORE_ERROR)
{
d_warn("msgq_timedrecv() failed");
return -1;
d_error("msgq_timedrecv failed", rv);
}
return r;
return rv;
}
void* event_timer_expire_func(
c_uintptr_t queue_id, c_uintptr_t event, c_uintptr_t param)
{
event_t e;
int r;
status_t rv;
d_assert(queue_id, return NULL, "Null param");
event_set(&e, event);
event_set_param1(&e, param);
r = msgq_send(queue_id, (const char*)&e, EVENT_SIZE);
if (r <= 0)
rv = event_send(queue_id, &e);
if (rv != CORE_OK)
{
d_warn("msgq_send() failed");
}
d_error("event_send error:%d", rv);
}
return NULL;
}

View File

@ -17,11 +17,11 @@ typedef struct _msq_desc_t {
unsigned char *pool;
} msg_desc_t;
pool_declare(msgqpool, msg_desc_t, 16);
pool_declare(msgqpool, msg_desc_t, 4);
status_t msgq_init(void)
{
pool_init(&msgqpool, 3);
pool_init(&msgqpool, 4);
return CORE_OK;
}
@ -103,7 +103,7 @@ status_t msgq_delete(msgq_id id)
return CORE_OK;
}
int msgq_send(msgq_id id, const char *msg, int msglen)
status_t msgq_send(msgq_id id, const char *msg, int msglen)
{
msg_desc_t *md = (msg_desc_t*)id;
int n;
@ -138,10 +138,10 @@ int msgq_send(msgq_id id, const char *msg, int msglen)
cond_signal(md->cond);
mutex_unlock(md->mut_c);
return msglen;
return CORE_OK;
}
int msgq_recv(msgq_id id, char *msg, int msglen)
status_t msgq_recv(msgq_id id, char *msg, int msglen)
{
msg_desc_t *md = (msg_desc_t*)id;
int n;
@ -188,10 +188,10 @@ int msgq_recv(msgq_id id, char *msg, int msglen)
mutex_unlock(md->mut_r);
return msglen;
return CORE_OK;
}
int msgq_timedrecv(msgq_id id, char *msg, int msglen, c_time_t timeout)
status_t msgq_timedrecv(msgq_id id, char *msg, int msglen, c_time_t timeout)
{
msg_desc_t *md = (msg_desc_t*)id;
int n;
@ -244,5 +244,5 @@ int msgq_timedrecv(msgq_id id, char *msg, int msglen, c_time_t timeout)
mutex_unlock(md->mut_r);
return msglen;
return CORE_OK;
}

View File

@ -141,10 +141,10 @@ static void msgq_test3(abts_case *tc, void *data)
for (i = 0; i < 16; i++)
{
n = msgq_send(md, msg[i], 24);
ABTS_INT_EQUAL(tc, 24, n);
ABTS_INT_EQUAL(tc, CORE_OK, n);
n = msgq_recv(md, rmsg[i], 24);
ABTS_INT_EQUAL(tc, 24, n);
ABTS_INT_EQUAL(tc, CORE_OK, n);
n = memcmp(msg[i], rmsg[i], 24);
ABTS_INT_EQUAL(tc, 0, n);
@ -179,7 +179,7 @@ static void *THREAD_FUNC producer_main(thread_id id, void *data)
{
test_param_t *param = (test_param_t *)data;
abts_case *tc = param->tc;
int r;
status_t rv;
int i = 0;
unsigned int full = 0;
@ -191,14 +191,14 @@ static void *THREAD_FUNC producer_main(thread_id id, void *data)
te.b = i+2;
te.c[28] = 'X';
te.c[29] = 'Y';
r = msgq_send(md, (char*)&te, TEST_EVT_SIZE);
if (r == CORE_EAGAIN)
rv = msgq_send(md, (char*)&te, TEST_EVT_SIZE);
if (rv == CORE_EAGAIN)
{
full++;
thread_yield();
continue;
}
ABTS_ASSERT(tc, "producer error", r == TEST_EVT_SIZE);
ABTS_ASSERT(tc, "producer error", rv == CORE_OK);
}
thread_exit(id, exit_ret_val);
@ -209,7 +209,7 @@ static void *THREAD_FUNC consumer_main(thread_id id, void *data)
{
test_param_t *param = (test_param_t *)data;
abts_case *tc = param->tc;
int r;
status_t rv;
int i = 0;
while (!thread_should_stop())
@ -220,15 +220,15 @@ static void *THREAD_FUNC consumer_main(thread_id id, void *data)
pthread_testcancel();
if (param->timed)
r = msgq_timedrecv(md, (char*)&te, TEST_EVT_SIZE, 10000);
rv = msgq_timedrecv(md, (char*)&te, TEST_EVT_SIZE, 10000);
else
r = msgq_recv(md, (char*)&te, TEST_EVT_SIZE);
if (r == CORE_EAGAIN || r == CORE_TIMEUP)
rv = msgq_recv(md, (char*)&te, TEST_EVT_SIZE);
if (rv == CORE_EAGAIN || rv == CORE_TIMEUP)
{
thread_yield();
continue;
}
ABTS_ASSERT(tc, "consumer error", r == TEST_EVT_SIZE);
ABTS_ASSERT(tc, "consumer error", rv == CORE_OK);
ABTS_ASSERT(tc, "consumer error", te.c[28] == 'X' && te.c[29] == 'Y');
i++;
}

View File

@ -49,24 +49,6 @@ char* mme_event_get_name(event_t *e)
return EVT_NAME_UNKNOWN;
}
status_t mme_event_send(event_t *e)
{
#if 0 /* FIXME */
int rc = event_send(mme_self()->queue_id, e);
if (rc < 0)
{
d_error("mme_event_send error:%d\n", rc);
return CORE_ERROR;
}
return CORE_OK;
#else
event_send(mme_self()->queue_id, e);
return CORE_OK;
#endif
}
void mme_event_s1ap_to_nas(ue_ctx_t *ue, S1ap_NAS_PDU_t *nasPdu)
{
pkbuf_t *sendbuf = NULL;

View File

@ -28,9 +28,10 @@ typedef enum {
} event_e;
#define mme_event_send(__ptr_e) event_send(mme_self()->queue_id, (__ptr_e))
CORE_DECLARE(char*) mme_event_get_name(event_t *e);
CORE_DECLARE(status_t) mme_event_send(event_t *e);
CORE_DECLARE(void) mme_event_s1ap_to_nas(ue_ctx_t *ue, S1ap_NAS_PDU_t *nasPdu);
CORE_DECLARE(void) mme_event_nas_to_s1ap(ue_ctx_t *ue, pkbuf_t *pkbuf);

View File

@ -41,7 +41,7 @@ void *THREAD_FUNC mme_sm_main(thread_id id, void *data)
event_t event;
mme_sm_t mme_sm;
c_time_t prev_tm, now_tm;
int r;
status_t rv;
memset(&event, 0, sizeof(event_t));
@ -59,9 +59,9 @@ void *THREAD_FUNC mme_sm_main(thread_id id, void *data)
while ((!thread_should_stop()))
{
r = event_timedrecv(mme_self()->queue_id, &event, EVENT_WAIT_TIMEOUT);
rv = event_timedrecv(mme_self()->queue_id, &event, EVENT_WAIT_TIMEOUT);
d_assert(r != CORE_ERROR, continue,
d_assert(rv != CORE_ERROR, continue,
"While receiving a event message, error occurs");
now_tm = time_now();
@ -75,7 +75,7 @@ void *THREAD_FUNC mme_sm_main(thread_id id, void *data)
prev_tm = now_tm;
}
if (r == CORE_TIMEUP)
if (rv == CORE_TIMEUP)
{
continue;
}

View File

@ -33,7 +33,6 @@ static int _mme_s11_recv_cb(net_sock_t *net_sock, void *data)
event_set(&e, EVT_MSG_MME_S11);
event_set_param1(&e, (c_uintptr_t)gnode);
event_set_param2(&e, (c_uintptr_t)pkbuf);
rv = mme_event_send(&e);
if (rv != CORE_OK)
{

View File

@ -70,6 +70,7 @@ static int _s1ap_accept_cb(net_sock_t *net_sock, void *data)
event_t e;
event_set(&e, EVT_LO_ENB_S1AP_ACCEPT);
event_set_param1(&e, (c_uintptr_t)remote_sock);
/* FIXME : how to close remote_sock */
mme_event_send(&e);
}
else
@ -146,7 +147,7 @@ int _s1ap_recv_cb(net_sock_t *net_sock, void *data)
pkbuf->len = r;
rv = s1ap_recv(net_sock, pkbuf);
if (rv == CORE_ERROR)
if (rv != CORE_OK)
{
pkbuf_free(pkbuf);
d_error("s1_recv() failed");

View File

@ -215,8 +215,12 @@ static void s6a_aia_cb(void *data, struct msg **msg)
event_set(&e, EVT_MSG_UE_EMM);
event_set_param1(&e, (c_uintptr_t)ue);
event_set_param2(&e, (c_uintptr_t)sendbuf);
mme_event_send(&e);
if (mme_event_send(&e) != CORE_OK)
{
d_error("mme_event_send failed");
pkbuf_free(sendbuf);
error++;
}
out:
/* Free the message */
d_assert(pthread_mutex_lock(&s6a_config->stats_lock) == 0,,);

View File

@ -27,20 +27,3 @@ char* sgw_event_get_name(event_t *e)
return EVT_NAME_UNKNOWN;
}
status_t sgw_event_send(event_t *e)
{
#if 0
int rc = event_send(sgw_self()->queue_id, e);
if (rc < 0)
{
d_error("event_send error:%d\n", rc);
return CORE_ERROR;
}
return CORE_OK;
#else
event_send(sgw_self()->queue_id, e);
return CORE_OK;
#endif
}

View File

@ -17,9 +17,9 @@ typedef enum {
} event_e;
CORE_DECLARE(char*) sgw_event_get_name(event_t *e);
#define sgw_event_send(__ptr_e) event_send(sgw_self()->queue_id, (__ptr_e))
CORE_DECLARE(status_t) sgw_event_send(event_t *e);
CORE_DECLARE(char*) sgw_event_get_name(event_t *e);
#ifdef __cplusplus
}

View File

@ -6,11 +6,14 @@
#include "context.h"
#include "event.h"
#if 0
static thread_id sgw_sm_thread;
#endif
void *THREAD_FUNC sgw_sm_main(thread_id id, void *data);
status_t sgw_initialize()
{
#if 0
status_t rv;
rv = sgw_ctx_init();
@ -18,15 +21,18 @@ status_t sgw_initialize()
rv = thread_create(&sgw_sm_thread, NULL, sgw_sm_main, NULL);
if (rv != CORE_OK) return rv;
#endif
return CORE_OK;
}
void sgw_terminate(void)
{
#if 0
thread_delete(sgw_sm_thread);
sgw_ctx_final();
#endif
}
void *THREAD_FUNC sgw_sm_main(thread_id id, void *data)

View File

@ -45,7 +45,6 @@ static int _gtpv2_c_recv_cb(net_sock_t *net_sock, void *data)
event_set_param1(&e, (c_uintptr_t)gnode);
event_set_param2(&e, (c_uintptr_t)pkbuf);
rv = sgw_event_send(&e);
if (rv != CORE_OK)
{