Signed-off-by: jiwon44.park <jiwon44park@jiwon44.park>
Change-Id: I494eea5f50f9c267a52fa20a86810747393ea363
if (handle->fd != -1)
close(handle->fd);
if (handle->fd != -1)
close(handle->fd);
+ pthread_mutex_unlock(&__gmutex);
if (handle->io_thread)
pthread_join(handle->io_thread, NULL);
if (handle->io_thread)
pthread_join(handle->io_thread, NULL);
+ pthread_mutex_lock(&__gmutex);
g_free(handle->id);
g_free(handle->service);
g_free(handle->id);
g_free(handle->service);
epfd = epoll_create(MAX_EPOLL_EVENT);
epfd = epoll_create(MAX_EPOLL_EVENT);
+ pthread_mutex_lock(&__gmutex);
+
ev.events = EPOLLIN | EPOLLHUP;
ev.data.fd = handle->fd;
ret = epoll_ctl(epfd, EPOLL_CTL_ADD, handle->fd, &ev);
WARN_IF(ret != 0, "listen error :%d", ret);
ev.events = EPOLLIN | EPOLLHUP;
ev.data.fd = handle->fd;
ret = epoll_ctl(epfd, EPOLL_CTL_ADD, handle->fd, &ev);
WARN_IF(ret != 0, "listen error :%d", ret);
+ pthread_mutex_unlock(&__gmutex);
+
- while (!handle->epoll_stop_thread) {
+
+ pthread_mutex_lock(&__gmutex);
+
+ if (handle->epoll_stop_thread) {
+ pthread_mutex_unlock(&__gmutex);
+ break;
+ }
+ pthread_mutex_unlock(&__gmutex);
+
struct epoll_event events[MAX_EPOLL_EVENT] = {{0}, };
int event_num = epoll_wait(epfd, events, MAX_EPOLL_EVENT, 50);
struct epoll_event events[MAX_EPOLL_EVENT] = {{0}, };
int event_num = epoll_wait(epfd, events, MAX_EPOLL_EVENT, 50);
- if (handle->epoll_stop_thread)
+ pthread_mutex_lock(&__gmutex);
+
+ if (handle->epoll_stop_thread) {
+ pthread_mutex_unlock(&__gmutex);
+ }
+ pthread_mutex_unlock(&__gmutex);
if (event_num == -1) {
if (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK) {
if (event_num == -1) {
if (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK) {
+ pthread_mutex_lock(&__gmutex);
for (i = 0; i < event_num; i++) {
if (events[i].events & EPOLLHUP) {
ERROR("server fd closed");
for (i = 0; i < event_num; i++) {
if (events[i].events & EPOLLHUP) {
ERROR("server fd closed");
if(__subscribe_data(handle) < 0) {
ERROR("server fd closed");
g_idle_add(__hung_up_cb, NULL);
if(__subscribe_data(handle) < 0) {
ERROR("server fd closed");
g_idle_add(__hung_up_cb, NULL);
+ handle->epoll_stop_thread = true;
+ pthread_mutex_unlock(&__gmutex);