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