-
Notifications
You must be signed in to change notification settings - Fork 387
/
WdtThread.cpp
58 lines (50 loc) · 1.4 KB
/
WdtThread.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <wdt/WdtThread.h>
using namespace std;
namespace facebook {
namespace wdt {
TransferStats WdtThread::moveStats() {
return std::move(threadStats_);
}
const PerfStatReport &WdtThread::getPerfReport() const {
return threadCtx_->getPerfReport();
}
const TransferStats &WdtThread::getTransferStats() const {
return threadStats_;
}
void WdtThread::startThread() {
if (threadPtr_) {
WDT_CHECK(false) << "There is a already a thread running " << threadIndex_
<< " " << getPort();
}
auto state = controller_->getState(threadIndex_);
// Check the state should be running here
WDT_CHECK_EQ(state, RUNNING);
threadPtr_.reset(new std::thread(&WdtThread::start, this));
}
ErrorCode WdtThread::finish() {
if (!threadPtr_) {
WLOG(ERROR) << "Finish called on an instance while no thread has been "
<< " created to do any work";
return ERROR;
}
threadPtr_->join();
threadPtr_.reset();
return OK;
}
WdtThread::~WdtThread() {
if (threadPtr_) {
WLOG(INFO) << threadIndex_
<< " has an alive thread while the instance is being "
<< "destructed";
finish();
}
}
} // namespace wdt
} // namespace facebook