remove lock in select_loop dispatcher

This commit is contained in:
Sukchan Lee 2017-12-17 10:02:08 +00:00
parent 1131166988
commit 487a4eb155
5 changed files with 37 additions and 11 deletions

View File

@ -5,6 +5,8 @@
#include "core_time.h"
#include "core_list.h"
#define NO_FD_LOCK 1 /* New experimental method */
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif

View File

@ -9,6 +9,14 @@
#define MAX_SOCK_POOL_SIZE 512
#define MAX_SOCK_NODE_POOL_SIZE 512
#if NO_FD_LOCK
#define FD_LOCK
#define FD_UNLOCK
#else
#define FD_LOCK mutex_lock(mutex);
#define FD_UNLOCK mutex_unlock(mutex);
#endif
static int max_fd;
static list_t fd_list;
static fd_set read_fds;
@ -659,7 +667,7 @@ status_t sock_register(sock_id id, sock_handler handler, void *data)
return CORE_ERROR;
}
mutex_lock(mutex);
FD_LOCK
if (sock->fd > max_fd)
{
@ -670,7 +678,7 @@ status_t sock_register(sock_id id, sock_handler handler, void *data)
list_append(&fd_list, sock);
mutex_unlock(mutex);
FD_UNLOCK
return CORE_OK;
}
@ -679,11 +687,11 @@ status_t sock_unregister(sock_id id)
{
d_assert(id, return CORE_ERROR,);
mutex_lock(mutex);
FD_LOCK
list_remove(&fd_list, id);
mutex_unlock(mutex);
FD_UNLOCK
return CORE_OK;
}
@ -693,19 +701,19 @@ int sock_is_registered(sock_id id)
sock_t *sock = (sock_t *)id;
sock_t *iter = NULL;
mutex_lock(mutex);
FD_LOCK
d_assert(id, return CORE_ERROR,);
for (iter = list_first(&fd_list); iter != NULL; iter = list_next(iter))
{
if (iter == sock)
{
mutex_unlock(mutex);
FD_UNLOCK
return 1;
}
}
mutex_unlock(mutex);
FD_UNLOCK
return 0;
}
@ -811,7 +819,7 @@ static void set_fds(fd_set *fds)
{
sock_t *sock = NULL;
mutex_lock(mutex);
FD_LOCK
FD_ZERO(fds);
for (sock = list_first(&fd_list); sock != NULL; sock = list_next(sock))
@ -819,14 +827,14 @@ static void set_fds(fd_set *fds)
FD_SET(sock->fd, fds);
}
mutex_unlock(mutex);
FD_UNLOCK
}
static void fd_dispatch(fd_set *fds)
{
sock_t *sock = NULL;
mutex_lock(mutex);
FD_LOCK
for (sock = list_first(&fd_list); sock != NULL; sock = list_next(sock))
{
@ -839,5 +847,5 @@ static void fd_dispatch(fd_set *fds)
}
}
mutex_unlock(mutex);
FD_UNLOCK
}

View File

@ -5,6 +5,7 @@
#include "core_lib.h"
#include "core_msgq.h"
#include "core_fsm.h"
#include "core_network.h"
#include <mongoc.h>
#include <yaml.h>
@ -1402,8 +1403,12 @@ status_t mme_enb_remove(mme_enb_t *enb)
enb_ue_remove_in_enb(enb);
#ifdef NO_FD_LOCK
#else
#error do not use lock in socket fd
if (enb->sock_type == SOCK_STREAM)
s1ap_delete(enb->sock);
#endif
core_free(enb->addr);
index_free(&mme_enb_pool, enb);

View File

@ -122,6 +122,10 @@ void mme_state_operational(fsm_t *s, event_t *e)
addr = (c_sockaddr_t *)event_get_param2(e);
d_assert(addr, break, "Null param");
#ifdef NO_FD_LOCK
enb = mme_enb_find_by_addr(addr);
#else
#error do not use lock in socket fd
/*
* <Connection Refused>
* if socket type is SOCK_STREAM,
@ -132,6 +136,7 @@ void mme_state_operational(fsm_t *s, event_t *e)
enb = mme_enb_find_by_sock(sock);
else
enb = mme_enb_find_by_addr(addr);
#endif
core_free(addr);
if (enb)

View File

@ -161,8 +161,14 @@ int s1ap_recv_handler(sock_id sock, void *data)
event_set(&e, MME_EVT_S1AP_LO_CONNREFUSED);
event_set_param1(&e, (c_uintptr_t)sock);
event_set_param2(&e, (c_uintptr_t)addr);
#ifdef NO_FD_LOCK
sock_delete(sock);
#else
#error do not use lock in socket fd
#endif
if (mme_event_send(&e) != CORE_OK)
{
d_error("Event MME_EVT_S1AP_LO_CONNREFUSED failed");
core_free(addr);
}