Descriptive name for thread index
This commit is contained in:
24
src/main.cpp
24
src/main.cpp
@@ -300,13 +300,15 @@ int main(int argc, char *argv[]) {
|
|||||||
// Network threads from configuration
|
// Network threads from configuration
|
||||||
int networkThreads = config->server.network_threads;
|
int networkThreads = config->server.network_threads;
|
||||||
|
|
||||||
for (int i = 0; i < networkThreads; ++i) {
|
for (int networkThreadId = 0; networkThreadId < networkThreads;
|
||||||
|
++networkThreadId) {
|
||||||
threads.emplace_back(
|
threads.emplace_back(
|
||||||
[network_epollfd, i,
|
[network_epollfd, networkThreadId,
|
||||||
max_request_size = config->server.max_request_size_bytes,
|
max_request_size = config->server.max_request_size_bytes,
|
||||||
event_batch_size = config->server.event_batch_size]() {
|
event_batch_size = config->server.event_batch_size]() {
|
||||||
pthread_setname_np(pthread_self(),
|
pthread_setname_np(
|
||||||
("network-" + std::to_string(i)).c_str());
|
pthread_self(),
|
||||||
|
("network-" + std::to_string(networkThreadId)).c_str());
|
||||||
std::vector<struct epoll_event> events(event_batch_size);
|
std::vector<struct epoll_event> events(event_batch_size);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int eventCount = epoll_wait(network_epollfd, events.data(),
|
int eventCount = epoll_wait(network_epollfd, events.data(),
|
||||||
@@ -397,12 +399,14 @@ int main(int argc, char *argv[]) {
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < acceptThreads; ++i) {
|
for (int acceptThreadId = 0; acceptThreadId < acceptThreads;
|
||||||
threads.emplace_back([network_epollfd, i, sockfd, &connectionId,
|
++acceptThreadId) {
|
||||||
|
threads.emplace_back([network_epollfd, acceptThreadId, sockfd,
|
||||||
|
&connectionId,
|
||||||
max_connections = config->server.max_connections,
|
max_connections = config->server.max_connections,
|
||||||
accept_epollfd]() {
|
accept_epollfd]() {
|
||||||
pthread_setname_np(pthread_self(),
|
pthread_setname_np(pthread_self(),
|
||||||
("accept-" + std::to_string(i)).c_str());
|
("accept-" + std::to_string(acceptThreadId)).c_str());
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct epoll_event events[2]; // listen socket + shutdown eventfd
|
struct epoll_event events[2]; // listen socket + shutdown eventfd
|
||||||
@@ -415,13 +419,13 @@ int main(int argc, char *argv[]) {
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < ready; ++j) {
|
for (int i = 0; i < ready; ++i) {
|
||||||
if (events[j].data.fd == shutdown_eventfd) {
|
if (events[i].data.fd == shutdown_eventfd) {
|
||||||
// Don't read eventfd - all threads need to see shutdown signal
|
// Don't read eventfd - all threads need to see shutdown signal
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (events[j].data.fd == sockfd) {
|
if (events[i].data.fd == sockfd) {
|
||||||
// Listen socket ready - accept connections
|
// Listen socket ready - accept connections
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct sockaddr_storage addr;
|
struct sockaddr_storage addr;
|
||||||
|
|||||||
Reference in New Issue
Block a user