Basically, I have a function called "monitor" and basically, this function works by waiting until some expression is false, and then it returns.
Right now, for this specific instance, it compares two uint16_t's. If they are equal, it will "sleep" with a condition variable. When one of the uint16_t's is changed, the changing thread will signal on the condition variable, and the function will wake up, do the comparison, and finally return.
How can I generalize this "monitor function" so that it could accept a generic function that returns a bool value?
For example, right now, I have
Code:
void Monitor(uint16_t start_val, uint16_t &tail)
{
mutex.lock()
while (start_val == tail) {
condition.wait(mutex);
}
}
but I want to generalize the input parameters to accept a boolean function. The programmer can specify any number of parameters to this boolean function, so basically, the loop would be
Code:
void Monitor(bool function)
{
mutex.lock()
while (function(param p1, param p2, ..., param pn) {
condition.wait(mutex);
}
}
Is there any way to do this?