@@ -54,19 +54,18 @@ Server::Server(Engine::Storage *storage, Config *config) :
54
54
cluster_ = std::unique_ptr<Cluster>(new Cluster (this , config_->binds , config_->port ));
55
55
56
56
for (int i = 0 ; i < config->workers ; i++) {
57
- auto worker = new Worker (this , config);
57
+ auto worker = Util::MakeUnique< Worker> (this , config);
58
58
// multiple workers can't listen to the same unix socket, so
59
59
// listen unix socket only from a single worker - the first one
60
60
if (!config->unixsocket .empty () && i == 0 ) {
61
61
Status s = worker->ListenUnixSocket (config->unixsocket , config->unixsocketperm , config->backlog );
62
62
if (!s.IsOK ()) {
63
63
LOG (ERROR) << " [server] Failed to listen on unix socket: " << config->unixsocket
64
64
<< " , encounter error: " << s.Msg ();
65
- delete worker;
66
65
exit (1 );
67
66
}
68
67
}
69
- worker_threads_.emplace_back (new WorkerThread ( worker));
68
+ worker_threads_.emplace_back (Util::MakeUnique< WorkerThread>( std::move ( worker) ));
70
69
}
71
70
AdjustOpenFilesLimit ();
72
71
slow_log_.SetMaxEntries (config->slowlog_max_len );
@@ -79,9 +78,6 @@ Server::Server(Engine::Storage *storage, Config *config) :
79
78
}
80
79
81
80
Server::~Server () {
82
- for (const auto &worker_thread : worker_threads_) {
83
- delete worker_thread;
84
- }
85
81
for (const auto &iter : conn_ctxs_) {
86
82
delete iter.first ;
87
83
}
@@ -121,7 +117,7 @@ Status Server::Start() {
121
117
}
122
118
}
123
119
124
- for (const auto worker : worker_threads_) {
120
+ for (const auto & worker : worker_threads_) {
125
121
worker->Start ();
126
122
}
127
123
task_runner_.Start ();
@@ -175,7 +171,7 @@ Status Server::Start() {
175
171
void Server::Stop () {
176
172
stop_ = true ;
177
173
if (replication_thread_) replication_thread_->Stop ();
178
- for (const auto worker : worker_threads_) {
174
+ for (const auto & worker : worker_threads_) {
179
175
worker->Stop ();
180
176
}
181
177
DisconnectSlaves ();
@@ -184,7 +180,7 @@ void Server::Stop() {
184
180
}
185
181
186
182
void Server::Join () {
187
- for (const auto worker : worker_threads_) {
183
+ for (const auto & worker : worker_threads_) {
188
184
worker->Join ();
189
185
}
190
186
task_runner_.Join ();
0 commit comments