Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions mgmt/ProcessManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ read_management_message(int sockfd, MgmtMessageHdr **msg)
}

void
ProcessManager::start(std::function<void()> const &cb)
ProcessManager::start(std::function<TSThread()> const &cb_init, std::function<void(TSThread)> const &cb_destroy)
{
Debug("pmgmt", "starting process manager");

init = cb;
init = cb_init;
destroy = cb_destroy;

ink_release_assert(running == 0);
ink_atomic_increment(&running, 1);
Expand Down Expand Up @@ -153,7 +154,7 @@ ProcessManager::processManagerThread(void *arg)
}

if (pmgmt->init) {
pmgmt->init();
pmgmt->managerThread = pmgmt->init();
}

// Start pumping messages between the local process and the process
Expand All @@ -178,6 +179,11 @@ ProcessManager::processManagerThread(void *arg)
}
}

if (pmgmt->destroy && pmgmt->managerThread != nullptr) {
pmgmt->destroy(pmgmt->managerThread);
pmgmt->managerThread = nullptr;
}

return ret;
}

Expand Down
9 changes: 7 additions & 2 deletions mgmt/ProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <functional>
#include <string_view>

#include <ts/apidefs.h>

#include "MgmtUtils.h"
#include "BaseManager.h"
#include "tscore/ink_sock.h"
Expand All @@ -49,7 +51,8 @@ class ProcessManager : public BaseManager
// Start a thread for the process manager. If @a cb is set then it
// is called after the thread is started and before any messages are
// processed.
void start(std::function<void()> const &cb = std::function<void()>());
void start(std::function<TSThread()> const &cb_init = std::function<TSThread()>(),
std::function<void(TSThread)> const &cb_destroy = std::function<void(TSThread)>());

// Stop the process manager, dropping any unprocessed messages.
void stop();
Expand Down Expand Up @@ -94,7 +97,9 @@ class ProcessManager : public BaseManager

/// Thread initialization callback.
/// This allows @c traffic_server and @c traffic_manager to perform different initialization in the thread.
std::function<void()> init;
std::function<TSThread()> init;
std::function<void(TSThread)> destroy;
TSThread managerThread = nullptr;

int local_manager_sockfd;
#if HAVE_EVENTFD
Expand Down
4 changes: 2 additions & 2 deletions src/traffic_server/traffic_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,8 +662,8 @@ initialize_process_manager()
pmgmt = new ProcessManager(remote_management_flag);

// Lifecycle callbacks can potentially be invoked from this thread, so force thread initialization
// to make the TS API work. Use a lambda to avoid dealing with compiler dependent casting issues.
pmgmt->start([]() -> void { TSThreadInit(); });
// to make the TS API work.
pmgmt->start(TSThreadInit, TSThreadDestroy);

RecProcessInitMessage(remote_management_flag ? RECM_CLIENT : RECM_STAND_ALONE);
pmgmt->reconfigure();
Expand Down