Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
miniob
提交
3b7870b4
M
miniob
项目概览
oceanbase
/
miniob
1 年多 前同步成功
通知
74
Star
1521
Fork
537
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
M
miniob
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
未验证
提交
3b7870b4
编写于
9月 02, 2022
作者:
羽飞
提交者:
GitHub
9月 02, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix exit bug (#57)
修复进程退出时,libevent 无法正常结束循环的BUG
上级
9ea8409a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
108 addition
and
16 deletion
+108
-16
1.patch
1.patch
+91
-0
src/observer/CMakeLists.txt
src/observer/CMakeLists.txt
+1
-1
src/observer/main.cpp
src/observer/main.cpp
+2
-2
src/observer/net/server.cpp
src/observer/net/server.cpp
+14
-13
未找到文件。
1.patch
0 → 100644
浏览文件 @
3b7870b4
diff --git a/src/observer/CMakeLists.txt b/src/observer/CMakeLists.txt
index 1e156f2..37f5f86 100644
--- a/src/observer/CMakeLists.txt
+++ b/src/observer/CMakeLists.txt
@@ -24,7 +24,7 @@
FOREACH (F ${ALL_SRC})
ENDFOREACH (F)
-SET(LIBRARIES common pthread dl event jsoncpp)
+SET(LIBRARIES common pthread dl event_pthreads event jsoncpp)
# 指定目标文件位置
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../../bin)
diff --git a/src/observer/main.cpp b/src/observer/main.cpp
index 4fff6da..112255e 100644
--- a/src/observer/main.cpp
+++ b/src/observer/main.cpp
@@ -137,8 +137,6 @@
void *quit_thread_func(void *_signum)
LOG_INFO("Receive signal: %ld", signum);
if (g_server) {
g_server->shutdown();
- delete g_server;
- g_server = nullptr;
}
return nullptr;
}
@@ -169,4 +167,6 @@
int main(int argc, char **argv)
LOG_INFO("Server stopped");
cleanup();
+
+ delete g_server;
}
diff --git a/src/observer/net/server.cpp b/src/observer/net/server.cpp
index e87ad0d..2c6cef6 100644
--- a/src/observer/net/server.cpp
+++ b/src/observer/net/server.cpp
@@ -26,6 +26,7 @@
See the Mulan PSL v2 for more details. */
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>
+#include <event2/thread.h>
#include "common/lang/mutex.h"
#include "common/log/log.h"
@@ -411,6 +412,7 @@
int Server::start_unix_socket_server()
int Server::serve()
{
+ evthread_use_pthreads();
event_base_ = event_base_new();
if (event_base_ == nullptr) {
LOG_ERROR("Failed to create event base, %s.", strerror(errno));
@@ -425,19 +427,6 @@
int Server::serve()
event_base_dispatch(event_base_);
- return 0;
-}
-
-void Server::shutdown()
-{
- LOG_INFO("Server shutting down");
-
- // cleanup
- struct timeval exit_time;
- gettimeofday(&exit_time, nullptr);
- exit_time.tv_sec += 10;
- event_base_loopexit(event_base_, &exit_time);
-
if (listen_ev_ != nullptr) {
event_del(listen_ev_);
event_free(listen_ev_);
@@ -451,4 +440,16 @@
void Server::shutdown()
started_ = false;
LOG_INFO("Server quit");
+ return 0;
+}
+
+void Server::shutdown()
+{
+ LOG_INFO("Server shutting down");
+
+ // cleanup
+ if (event_base_ != nullptr && started_) {
+ started_ = false;
+ event_base_loopexit(event_base_, nullptr);
+ }
}
src/observer/CMakeLists.txt
浏览文件 @
3b7870b4
...
@@ -24,7 +24,7 @@ FOREACH (F ${ALL_SRC})
...
@@ -24,7 +24,7 @@ FOREACH (F ${ALL_SRC})
ENDFOREACH
(
F
)
ENDFOREACH
(
F
)
SET
(
LIBRARIES common pthread dl event jsoncpp
)
SET
(
LIBRARIES common pthread dl event
_pthreads event
jsoncpp
)
# 指定目标文件位置
# 指定目标文件位置
SET
(
EXECUTABLE_OUTPUT_PATH
${
PROJECT_BINARY_DIR
}
/../../bin
)
SET
(
EXECUTABLE_OUTPUT_PATH
${
PROJECT_BINARY_DIR
}
/../../bin
)
...
...
src/observer/main.cpp
浏览文件 @
3b7870b4
...
@@ -137,8 +137,6 @@ void *quit_thread_func(void *_signum)
...
@@ -137,8 +137,6 @@ void *quit_thread_func(void *_signum)
LOG_INFO
(
"Receive signal: %ld"
,
signum
);
LOG_INFO
(
"Receive signal: %ld"
,
signum
);
if
(
g_server
)
{
if
(
g_server
)
{
g_server
->
shutdown
();
g_server
->
shutdown
();
delete
g_server
;
g_server
=
nullptr
;
}
}
return
nullptr
;
return
nullptr
;
}
}
...
@@ -169,4 +167,6 @@ int main(int argc, char **argv)
...
@@ -169,4 +167,6 @@ int main(int argc, char **argv)
LOG_INFO
(
"Server stopped"
);
LOG_INFO
(
"Server stopped"
);
cleanup
();
cleanup
();
delete
g_server
;
}
}
src/observer/net/server.cpp
浏览文件 @
3b7870b4
...
@@ -26,6 +26,7 @@ See the Mulan PSL v2 for more details. */
...
@@ -26,6 +26,7 @@ See the Mulan PSL v2 for more details. */
#include <sys/types.h>
#include <sys/types.h>
#include <sys/un.h>
#include <sys/un.h>
#include <unistd.h>
#include <unistd.h>
#include <event2/thread.h>
#include "common/lang/mutex.h"
#include "common/lang/mutex.h"
#include "common/log/log.h"
#include "common/log/log.h"
...
@@ -411,6 +412,7 @@ int Server::start_unix_socket_server()
...
@@ -411,6 +412,7 @@ int Server::start_unix_socket_server()
int
Server
::
serve
()
int
Server
::
serve
()
{
{
evthread_use_pthreads
();
event_base_
=
event_base_new
();
event_base_
=
event_base_new
();
if
(
event_base_
==
nullptr
)
{
if
(
event_base_
==
nullptr
)
{
LOG_ERROR
(
"Failed to create event base, %s."
,
strerror
(
errno
));
LOG_ERROR
(
"Failed to create event base, %s."
,
strerror
(
errno
));
...
@@ -425,19 +427,6 @@ int Server::serve()
...
@@ -425,19 +427,6 @@ int Server::serve()
event_base_dispatch
(
event_base_
);
event_base_dispatch
(
event_base_
);
return
0
;
}
void
Server
::
shutdown
()
{
LOG_INFO
(
"Server shutting down"
);
// cleanup
struct
timeval
exit_time
;
gettimeofday
(
&
exit_time
,
nullptr
);
exit_time
.
tv_sec
+=
10
;
event_base_loopexit
(
event_base_
,
&
exit_time
);
if
(
listen_ev_
!=
nullptr
)
{
if
(
listen_ev_
!=
nullptr
)
{
event_del
(
listen_ev_
);
event_del
(
listen_ev_
);
event_free
(
listen_ev_
);
event_free
(
listen_ev_
);
...
@@ -451,4 +440,16 @@ void Server::shutdown()
...
@@ -451,4 +440,16 @@ void Server::shutdown()
started_
=
false
;
started_
=
false
;
LOG_INFO
(
"Server quit"
);
LOG_INFO
(
"Server quit"
);
return
0
;
}
void
Server
::
shutdown
()
{
LOG_INFO
(
"Server shutting down"
);
// cleanup
if
(
event_base_
!=
nullptr
&&
started_
)
{
started_
=
false
;
event_base_loopexit
(
event_base_
,
nullptr
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录