Add missing option for dispatch, which fills gap in combination of block/nonblock and one/all dispatch types. New type doesn't mask CS_ERR_TRY_AGAIN, and it means "no message was processed". Signed-off-by: Jan Friesse <jfriesse@xxxxxxxxxx> --- include/corosync/corotypes.h | 3 ++- lib/cfg.c | 13 ++++++++++--- lib/cmap.c | 14 ++++++++++---- lib/cpg.c | 14 ++++++++++---- lib/evs.c | 14 ++++++++++---- lib/quorum.c | 17 ++++++++++++----- lib/votequorum.c | 17 ++++++++++++----- man/cmap_dispatch.3 | 4 ++++ man/cpg_dispatch.3 | 4 ++++ man/evs_dispatch.3 | 4 ++++ man/quorum_dispatch.3 | 4 ++++ man/votequorum_dispatch.3 | 4 ++++ 12 files changed, 86 insertions(+), 26 deletions(-) diff --git a/include/corosync/corotypes.h b/include/corosync/corotypes.h index 98b54fb..906b4c7 100644 --- a/include/corosync/corotypes.h +++ b/include/corosync/corotypes.h @@ -66,7 +66,8 @@ typedef struct { typedef enum { CS_DISPATCH_ONE = 1, CS_DISPATCH_ALL = 2, - CS_DISPATCH_BLOCKING = 3 + CS_DISPATCH_BLOCKING = 3, + CS_DISPATCH_ONE_NONBLOCKING = 4 } cs_dispatch_flags_t; #define CS_TRACK_CURRENT 0x01 diff --git a/lib/cfg.c b/lib/cfg.c index 2a12cf4..7728b74 100644 --- a/lib/cfg.c +++ b/lib/cfg.c @@ -158,9 +158,10 @@ corosync_cfg_dispatch ( } /* - * Timeout instantly for CS_DISPATCH_ALL + * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and + * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING */ - if (dispatch_flags == CS_DISPATCH_ALL) { + if (dispatch_flags == CS_DISPATCH_ALL || dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) { timeout = 0; } @@ -176,6 +177,12 @@ corosync_cfg_dispatch ( goto error_put; } if (error == CS_ERR_TRY_AGAIN) { + if (dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) { + /* + * Don't mask error + */ + goto error_put; + } error = CS_OK; if (dispatch_flags == CS_DISPATCH_ALL) { break; /* exit do while cont is 1 loop */ @@ -215,7 +222,7 @@ corosync_cfg_dispatch ( /* * Determine if more messages should be processed */ - if (dispatch_flags == CS_DISPATCH_ONE) { + if (dispatch_flags == CS_DISPATCH_ONE || dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) { cont = 0; } } while (cont); diff --git a/lib/cmap.c b/lib/cmap.c index 252bf86..cfa7434 100644 --- a/lib/cmap.c +++ b/lib/cmap.c @@ -190,10 +190,10 @@ cs_error_t cmap_dispatch ( } /* - * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and - * wait indefinitely for CS_DISPATCH_BLOCKING + * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and + * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING */ - if (dispatch_types == CS_DISPATCH_ALL) { + if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { timeout = 0; } @@ -210,6 +210,12 @@ cs_error_t cmap_dispatch ( goto error_put; } if (error == CS_ERR_TRY_AGAIN) { + if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { + /* + * Don't mask error + */ + goto error_put; + } error = CS_OK; if (dispatch_types == CS_DISPATCH_ALL) { break; /* exit do while cont is 1 loop */ @@ -268,7 +274,7 @@ cs_error_t cmap_dispatch ( /* * Determine if more messages should be processed */ - if (dispatch_types == CS_DISPATCH_ONE) { + if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { cont = 0; } } while (cont); diff --git a/lib/cpg.c b/lib/cpg.c index 171d6b4..7e325e9 100644 --- a/lib/cpg.c +++ b/lib/cpg.c @@ -343,10 +343,10 @@ cs_error_t cpg_dispatch ( } /* - * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and - * wait indefinately for CS_DISPATCH_BLOCKING + * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and + * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING */ - if (dispatch_types == CS_DISPATCH_ALL) { + if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { timeout = 0; } @@ -363,6 +363,12 @@ cs_error_t cpg_dispatch ( goto error_put; } if (error == CS_ERR_TRY_AGAIN) { + if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { + /* + * Don't mask error + */ + goto error_put; + } error = CS_OK; if (dispatch_types == CS_DISPATCH_ALL) { break; /* exit do while cont is 1 loop */ @@ -471,7 +477,7 @@ cs_error_t cpg_dispatch ( /* * Determine if more messages should be processed */ - if (dispatch_types == CS_DISPATCH_ONE) { + if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { cont = 0; } } while (cont); diff --git a/lib/evs.c b/lib/evs.c index a5003ad..8592edd 100644 --- a/lib/evs.c +++ b/lib/evs.c @@ -230,10 +230,10 @@ cs_error_t evs_dispatch ( } /* - * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and - * wait indefinately for CS_DISPATCH_BLOCKING + * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and + * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING */ - if (dispatch_types == CS_DISPATCH_ALL) { + if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { timeout = 0; } @@ -249,6 +249,12 @@ cs_error_t evs_dispatch ( goto error_put; } if (error == CS_ERR_TRY_AGAIN) { + if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { + /* + * Don't mask error + */ + goto error_put; + } error = CS_OK; if (dispatch_types == CS_DISPATCH_ALL) { break; /* exit do while cont is 1 loop */ @@ -310,7 +316,7 @@ cs_error_t evs_dispatch ( /* * Determine if more messages should be processed */ - if (dispatch_types == CS_DISPATCH_ONE) { + if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { cont = 0; } } while (cont); diff --git a/lib/quorum.c b/lib/quorum.c index 7e42fd0..850711b 100644 --- a/lib/quorum.c +++ b/lib/quorum.c @@ -355,7 +355,8 @@ cs_error_t quorum_dispatch ( if (dispatch_types != CS_DISPATCH_ONE && dispatch_types != CS_DISPATCH_ALL && - dispatch_types != CS_DISPATCH_BLOCKING) { + dispatch_types != CS_DISPATCH_BLOCKING && + dispatch_types != CS_DISPATCH_ONE_NONBLOCKING) { return (CS_ERR_INVALID_PARAM); } @@ -367,10 +368,10 @@ cs_error_t quorum_dispatch ( } /* - * Timeout instantly for CS_DISPATCH_ONE or SA_DISPATCH_ALL and - * wait indefinately for CS_DISPATCH_BLOCKING + * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and + * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING */ - if (dispatch_types == CS_DISPATCH_ALL) { + if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { timeout = 0; } @@ -386,6 +387,12 @@ cs_error_t quorum_dispatch ( goto error_put; } if (error == CS_ERR_TRY_AGAIN) { + if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { + /* + * Don't mask error + */ + goto error_put; + } error = CS_OK; if (dispatch_types == CS_DISPATCH_ALL) { break; /* exit do while cont is 1 loop */ @@ -430,7 +437,7 @@ cs_error_t quorum_dispatch ( /* * Determine if more messages should be processed */ - if (dispatch_types == CS_DISPATCH_ONE) { + if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { cont = 0; } } while (cont); diff --git a/lib/votequorum.c b/lib/votequorum.c index 159d697..4488c12 100644 --- a/lib/votequorum.c +++ b/lib/votequorum.c @@ -429,7 +429,8 @@ cs_error_t votequorum_dispatch ( if (dispatch_types != CS_DISPATCH_ONE && dispatch_types != CS_DISPATCH_ALL && - dispatch_types != CS_DISPATCH_BLOCKING) { + dispatch_types != CS_DISPATCH_BLOCKING && + dispatch_types != CS_DISPATCH_ONE_NONBLOCKING) { return (CS_ERR_INVALID_PARAM); } @@ -441,10 +442,10 @@ cs_error_t votequorum_dispatch ( } /* - * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and - * wait indefinitely for CS_DISPATCH_BLOCKING + * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and + * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING */ - if (dispatch_types == CS_DISPATCH_ALL) { + if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { timeout = 0; } @@ -460,6 +461,12 @@ cs_error_t votequorum_dispatch ( goto error_put; } if (error == CS_ERR_TRY_AGAIN) { + if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { + /* + * Don't mask error + */ + goto error_put; + } error = CS_OK; if (dispatch_types == CS_DISPATCH_ALL) { break; /* exit do while cont is 1 loop */ @@ -517,7 +524,7 @@ cs_error_t votequorum_dispatch ( /* * Determine if more messages should be processed */ - if (dispatch_types == CS_DISPATCH_ONE) { + if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) { cont = 0; } } while (cont); diff --git a/man/cmap_dispatch.3 b/man/cmap_dispatch.3 index 19970e4..b791a5e 100644 --- a/man/cmap_dispatch.3 +++ b/man/cmap_dispatch.3 @@ -72,6 +72,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks. Dispatch all callbacks blocking indefinitely. This is used in a threaded program where a thread is created, and then cs_dispatch() is called immediately from the created thread to execute callbacks. +.TP +.B CS_DISPATCH_ONE_NONBLOCKING +Dispatch at most one callback. If there is no pending callback, +CS_ERR_TRY_AGAIN is returned. .PP It's needed to call .B cmap_track_add(3) diff --git a/man/cpg_dispatch.3 b/man/cpg_dispatch.3 index bac516c..f824a3f 100644 --- a/man/cpg_dispatch.3 +++ b/man/cpg_dispatch.3 @@ -82,6 +82,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks. Dispatch all callbacks, blocking indefinitely. This is used in a threaded program where a thread is created, and then cpg_dispatch() is called immediately from the created thread to execute callbacks. +.TP +.B CS_DISPATCH_ONE_NONBLOCKING +Dispatch at most one callback. If there is no pending callback, +CS_ERR_TRY_AGAIN is returned. .SH RETURN VALUE This call returns the CS_OK value if successful, otherwise an error is returned. diff --git a/man/evs_dispatch.3 b/man/evs_dispatch.3 index e6e7af0..2624a42 100644 --- a/man/evs_dispatch.3 +++ b/man/evs_dispatch.3 @@ -82,6 +82,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks. Dispatch all callbacks blocking indefinately. This is used in a threaded program where a thread is created, and then evs_dispatch() is called immediately from the created thread to execute callbacks. +.TP +.B CS_DISPATCH_ONE_NONBLOCKING +Dispatch at most one callback. If there is no pending callback, +CS_ERR_TRY_AGAIN is returned. .SH RETURN VALUE This call returns the CS_OK value if successful, otherwise an error is returned. diff --git a/man/quorum_dispatch.3 b/man/quorum_dispatch.3 index cb26050..8f7c3a0 100644 --- a/man/quorum_dispatch.3 +++ b/man/quorum_dispatch.3 @@ -81,6 +81,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks. Dispatch all callbacks blocking indefinitely. This is used in a threaded program where a thread is created, and then quorum_dispatch() is called immediately from the created thread to execute callbacks. +.TP +.B CS_DISPATCH_ONE_NONBLOCKING +Dispatch at most one callback. If there is no pending callback, +CS_ERR_TRY_AGAIN is returned. .SH RETURN VALUE This call returns the CS_OK value if successful, otherwise an error is returned. diff --git a/man/votequorum_dispatch.3 b/man/votequorum_dispatch.3 index c9e91f5..8d5f8d1 100644 --- a/man/votequorum_dispatch.3 +++ b/man/votequorum_dispatch.3 @@ -81,6 +81,10 @@ Dispatch all waiting callbacks without blocking to wait for any callbacks. Dispatch all callbacks blocking indefinitely. This is used in a threaded program where a thread is created, and then votequorum_dispatch() is called immediately from the created thread to execute callbacks. +.TP +.B CS_DISPATCH_ONE_NONBLOCKING +Dispatch at most one callback. If there is no pending callback, +CS_ERR_TRY_AGAIN is returned. .SH RETURN VALUE This call returns the CS_OK value if successful, otherwise an error is returned. -- 1.7.1 _______________________________________________ discuss mailing list discuss@xxxxxxxxxxxx http://lists.corosync.org/mailman/listinfo/discuss