SEF: add sef_cancel()

This function allows the caller to cancel receiving a message from a
SEF callback. The receive function will then return EINTR.
This commit is contained in:
David van Moolenbroek 2012-04-09 16:35:57 +02:00
parent 6aa61efd09
commit 060399d9dd
2 changed files with 23 additions and 0 deletions

View file

@ -8,6 +8,7 @@
/* SEF entry points for system processes. */
void sef_startup(void);
int sef_receive_status(endpoint_t src, message *m_ptr, int *status_ptr);
void sef_cancel(void);
void sef_exit(int status);
#define sef_receive(src, m_ptr) sef_receive_status(src, m_ptr, NULL)

View file

@ -12,6 +12,7 @@ char sef_self_name[SEF_SELF_NAME_MAXLEN];
endpoint_t sef_self_endpoint;
int sef_self_priv_flags;
int sef_self_first_receive_done;
int sef_self_receiving;
/* Debug. */
#if SEF_INIT_DEBUG || SEF_LU_DEBUG || SEF_PING_DEBUG || SEF_SIGNAL_DEBUG
@ -119,7 +120,14 @@ int sef_receive_status(endpoint_t src, message *m_ptr, int *status_ptr)
/* SEF receive() interface for system services. */
int r, status;
sef_self_receiving = TRUE;
while(TRUE) {
/* If the caller indicated that it no longer wants to receive a message,
* return now.
*/
if (!sef_self_receiving)
return EINTR;
#if INTERCEPT_SEF_LU_REQUESTS
/* Handle SEF Live update before receive events. */
@ -180,6 +188,20 @@ int sef_receive_status(endpoint_t src, message *m_ptr, int *status_ptr)
return r;
}
/*===========================================================================*
* sef_cancel *
*===========================================================================*/
void sef_cancel(void)
{
/* Cancel receiving a message. This function be called from a callback invoked
* from within sef_receive_status(), which will then return an EINTR error
* code. In particular, this function can be used to exit from the main receive
* loop when a signal handler causes the process to want to shut down.
*/
sef_self_receiving = FALSE;
}
/*===========================================================================*
* sef_exit *
*===========================================================================*/