Skip to content

Replace semaphore with a state flag on zos #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 23 additions & 2 deletions src/ibmras/monitoring/agent/threads/WorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ namespace threads {

extern IBMRAS_DECLARE_LOGGER;


#if defined(_ZOS)
WorkerThread::WorkerThread(pullsource* pullSource) : data(threadEntry, cleanUp), countdown(0) {
#else
WorkerThread::WorkerThread(pullsource* pullSource) : semaphore(0, 1, pullSource->header.name), data(threadEntry, cleanUp), countdown(0) {
#endif
source = pullSource;
running = false;
stopped = true;
#if defined(_ZOS)
isDataPullAllowed = false;
#endif
data.setArgs(this);
}

Expand All @@ -55,8 +61,9 @@ void WorkerThread::stop() {
// We've already set running=false, so processLoop will finish the
// next chance it gets and only then will set stopped=true.
//stopped = true;

#if !defined(_ZOS)
semaphore.inc();
#endif
IBMRAS_DEBUG_1(debug, "Worker thread for %s stopping", source->header.name);
}

Expand All @@ -74,9 +81,16 @@ void* WorkerThread::threadEntry(ibmras::common::port::ThreadData* data) {
void WorkerThread::process(bool immediate) {
IBMRAS_DEBUG_2(finest, "Worker thread process for %s, countdown is %d", source->header.name, countdown);
if ((immediate && countdown > 120) || (countdown == 0)) {
#if defined(_ZOS)
isDataPullAllowed = true;
#else
semaphore.inc();
#endif
countdown = source->pullInterval;
} else {
#if defined(_ZOS)
isDataPullAllowed = false;
#endif
countdown--;
}
}
Expand All @@ -89,7 +103,11 @@ void* WorkerThread::processLoop() {
IBMRAS_DEBUG_1(finest, "Worker thread started for %s", source->header.name);
Agent* agent = Agent::getInstance();
while (running) {
#if defined(_ZOS)
if (isDataPullAllowed && running) {
#else
if (semaphore.wait(1) && running) {
#endif
IBMRAS_DEBUG_1(fine, "Pulling data from source %s", source->header.name);
monitordata* data = source->callback();
if (data != NULL) {
Expand All @@ -100,6 +118,9 @@ void* WorkerThread::processLoop() {
source->complete(data);
}
}
#if defined(_ZOS)
ibmras::common::port::sleep(1);
#endif
}

source->complete(NULL);
Expand Down
4 changes: 4 additions & 0 deletions src/ibmras/monitoring/agent/threads/WorkerThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ class WorkerThread {
void* processLoop();
bool running;
bool stopped;
#if defined(_ZOS)
bool isDataPullAllowed;
#else
ibmras::common::port::Semaphore semaphore; /* sempahore to control data processing */
#endif
pullsource* source; /* source to pull data from */
ibmras::common::port::ThreadData data;
int countdown;
Expand Down