Skip to content

Commit

Permalink
lock mutex on reading program status
Browse files Browse the repository at this point in the history
  • Loading branch information
Przemyslaw Susko committed Oct 25, 2023
1 parent 662f7b6 commit 89d7070
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ebpfdiscoverysrv/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ static void initLibbpf() {
libbpf_set_print(libbpfPrintFn);
}

bool isProgramRunning() {
std::lock_guard<std::mutex> lock(programStatusMutex);
return programStatus == ProgramStatus::Running;
}

void servicesProvidingLoop(ebpfdiscovery::Discovery& discoveryInstance, std::chrono::seconds interval) {
while (programStatus == ProgramStatus::Running) {
while (isProgramRunning()) {
if (auto services = discoveryInstance.popServices(); !services.empty()) {
auto servicesProto = proto::internalToProto(services);
LOG_DEBUG("Services list:\n{}\n", servicesProto.DebugString());
Expand Down

0 comments on commit 89d7070

Please sign in to comment.