From 8731b30bdef9d28b5981f3e0820a335dc75bb642 Mon Sep 17 00:00:00 2001 From: xsmq Date: Wed, 18 Nov 2020 21:15:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=20'Pull=20Request=20!8698=20?= =?UTF-8?q?:=20added=20libevent=20pthread'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mindspore/ccsrc/ps/core/http_server.cc | 28 +++++++------------------- mindspore/ccsrc/ps/core/http_server.h | 10 +-------- mindspore/ccsrc/ps/core/tcp_server.cc | 5 +---- 3 files changed, 9 insertions(+), 34 deletions(-) diff --git a/mindspore/ccsrc/ps/core/http_server.cc b/mindspore/ccsrc/ps/core/http_server.cc index 56c7852c4f..548e6ec1c6 100644 --- a/mindspore/ccsrc/ps/core/http_server.cc +++ b/mindspore/ccsrc/ps/core/http_server.cc @@ -49,13 +49,6 @@ bool HttpServer::InitServer() { MS_LOG(EXCEPTION) << "The http server ip:" << server_address_ << " is illegal!"; } - int result = evthread_use_pthreads(); - if (result != 0) { - MS_LOG(EXCEPTION) << "Use event pthread failed!"; - } - - is_stop_ = false; - event_base_ = event_base_new(); MS_EXCEPTION_IF_NULL(event_base_); event_http_ = evhttp_new(event_base_); @@ -153,20 +146,13 @@ bool HttpServer::Start() { void HttpServer::Stop() { MS_LOG(INFO) << "Stop http server!"; - if (!is_stop_.load()) { - int ret = event_base_loopbreak(event_base_); - if (ret != 0) { - MS_LOG(EXCEPTION) << "event base loop break failed!"; - } - if (event_http_) { - evhttp_free(event_http_); - event_http_ = nullptr; - } - if (event_base_) { - event_base_free(event_base_); - event_base_ = nullptr; - } - is_stop_ = true; + if (event_http_) { + evhttp_free(event_http_); + event_http_ = nullptr; + } + if (event_base_) { + event_base_free(event_base_); + event_base_ = nullptr; } } diff --git a/mindspore/ccsrc/ps/core/http_server.h b/mindspore/ccsrc/ps/core/http_server.h index 6e85e83ce2..acea23db65 100644 --- a/mindspore/ccsrc/ps/core/http_server.h +++ b/mindspore/ccsrc/ps/core/http_server.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -33,7 +32,6 @@ #include #include #include -#include namespace mindspore { namespace ps { @@ -57,12 +55,7 @@ class HttpServer { public: // Server address only support IPV4 now, and should be in format of "x.x.x.x" explicit HttpServer(const std::string &address, std::uint16_t port) - : server_address_(address), - server_port_(port), - event_base_(nullptr), - event_http_(nullptr), - is_init_(false), - is_stop_(true) {} + : server_address_(address), server_port_(port), event_base_(nullptr), event_http_(nullptr), is_init_(false) {} ~HttpServer(); @@ -91,7 +84,6 @@ class HttpServer { struct event_base *event_base_; struct evhttp *event_http_; bool is_init_; - std::atomic is_stop_; }; } // namespace core diff --git a/mindspore/ccsrc/ps/core/tcp_server.cc b/mindspore/ccsrc/ps/core/tcp_server.cc index 9093eec627..9a5c1b5987 100644 --- a/mindspore/ccsrc/ps/core/tcp_server.cc +++ b/mindspore/ccsrc/ps/core/tcp_server.cc @@ -198,10 +198,7 @@ void TcpServer::ListenerCallback(struct evconnlistener *, evutil_socket_t fd, st struct bufferevent *bev = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE); if (!bev) { MS_LOG(ERROR) << "Error constructing buffer event!"; - int ret = event_base_loopbreak(base); - if (ret != 0) { - MS_LOG(EXCEPTION) << "event base loop break failed!"; - } + event_base_loopbreak(base); return; }