-
Notifications
You must be signed in to change notification settings - Fork 389
/
Copy pathWdtThread.h
79 lines (63 loc) · 2.1 KB
/
WdtThread.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* 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. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#pragma once
#include "Reporting.h"
#include "ErrorCodes.h"
#include "ThreadsController.h"
#include <thread>
#include <memory>
namespace facebook {
namespace wdt {
class ThreadsController;
class WdtThread {
public:
/// Constructor for wdt thread
WdtThread(int threadIndex, int protocolVersion, ThreadsController *controller)
: threadIndex_(threadIndex), threadProtocolVersion_(protocolVersion) {
controller_ = controller;
}
/// Starts a thread which runs the wdt functionality
void startThread();
/// Get the perf stats of the transfer for this thread
const PerfStatReport &getPerfReport() const;
/// Initializes the wdt thread before starting
virtual ErrorCode init() = 0;
/// Conclude the thread transfer
virtual ErrorCode finish();
/// Moves the local stats into a new instance
TransferStats moveStats();
/// Get the transfer stats recorded by this thread
const TransferStats &getTransferStats() const;
/// Reset the wdt thread
virtual void reset() = 0;
/// Get the port this thread is running on
virtual int getPort() const = 0;
// TODO remove this function
virtual int getNegotiatedProtocol() const {
return threadProtocolVersion_;
}
virtual ~WdtThread();
protected:
/// The main entry point of the thread
virtual void start() = 0;
/// Index of this thread with respect to other threads
const int threadIndex_;
/// Copy of the protocol version that might be changed
int threadProtocolVersion_;
/// Transfer stats for this thread
TransferStats threadStats_{true};
/// Perf stats report for this thread
PerfStatReport perfReport_;
/// Thread controller for all the sender threads
ThreadsController *controller_{nullptr};
/// Pointer to the std::thread executing the transfer
std::unique_ptr<std::thread> threadPtr_{nullptr};
};
}
}