| Updated: October 28, 2024 |
Add an event to be triggered when a monitored value crosses a trigger point
#include <sys/procmgr.h>
int procmgr_value_notify_add( unsigned type,
int sub_id,
uint64_t value,
const struct sigevent *event );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
You can OR this with one of the following:
The procmgr_value_notify_add() function sets up an event to be triggered when the value being monitored crosses the trigger point up (PROCMGR_VALUE_TRIGGER_UP) or down (PROCMGR_VALUE_TRIGGER_DOWN).
For example, PROCMGR_VALUE_FREE_MEM | PROCMGR_VALUE_TRIGGER_DOWN causes the event to be delivered when the system free memory drops to the specified trigger value.
If you just want to read the value with procmgr_value_current(), don't specify either of the trigger bits.
To delete the notification, call procmgr_event_notify_delete(), passing it the ID that procmgr_value_notify_add() returns.
An event ID, or -1 if there was an error (errno is set).
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/neutrino.h>
#include <sys/procmgr.h>
#include <signal.h>
#define VALUE_CHANGED_CODE (_PULSE_CODE_MINAVAIL + 2)
int main(int argc, char **argv) {
int chid, coid, rc, handle;
struct sigevent event;
struct _pulse msg;
uint64_t trigger_value = 100;
chid = ChannelCreate(_NTO_CHF_PRIVATE);
if (chid == -1) {
perror("ChannelCreate() failed");
exit(EXIT_FAILURE);
}
coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, _NTO_COF_CLOEXEC);
if (coid == -1) {
perror("ConnectAttach() failed");
exit(EXIT_FAILURE);
}
SIGEV_PULSE_INIT(&event, coid, SIGEV_PULSE_PRIO_INHERIT, VALUE_CHANGED_CODE, 0);
SIGEV_MAKE_UPDATEABLE(&event);
if (MsgRegisterEvent(&event, chid) == -1) {
perror("MsgRegisterEvent() failed");
exit(EXIT_FAILURE);
}
/*
* Ask to be notified via a pulse whenever a specific value changes
*/
handle = procmgr_value_notify_add(PROCMGR_VALUE_FREE_MEM | PROCMGR_VALUE_TRIGGER_DOWN,
0, trigger_value, &event);
if (handle == -1) {
perror("procmgr_value_notify_add() failed");
exit(EXIT_FAILURE);
}
for (;;) {
rc = MsgReceivePulse(chid, &msg, sizeof(msg), NULL);
if (rc == -1) {
perror("MsgReceivePulse() failed");
exit(EXIT_FAILURE);
}
switch(msg.code) {
case VALUE_CHANGED_CODE:
printf("The specified value has changed\n");
break;
}
}
procmgr_event_notify_delete(handle);
return 0;
}
| Safety: | |
|---|---|
| Cancellation point | No |
| Interrupt handler | No |
| Signal handler | Yes |
| Thread | Yes |