diff options
author | Mark Stapp <mjs@voltanet.io> | 2020-04-07 15:50:53 +0200 |
---|---|---|
committer | Mark Stapp <mjs@voltanet.io> | 2020-06-02 14:20:54 +0200 |
commit | aa9002a5f5ef55e4c99c99601b4aa5a164d08bbf (patch) | |
tree | 31cf9479538c3c3bdaca25a4bb8320391b812eb6 /zebra/zserv.h | |
parent | zebra: add zebra opaque module (diff) | |
download | frr-aa9002a5f5ef55e4c99c99601b4aa5a164d08bbf.tar.xz frr-aa9002a5f5ef55e4c99c99601b4aa5a164d08bbf.zip |
zebra: add lock and busy counter for zclients
Add a mutex used to manage the list of zclients. Add a busy
counter to the zapi client session, so that we can use a
client session from another pthread.
Signed-off-by: Mark Stapp <mjs@voltanet.io>
Diffstat (limited to 'zebra/zserv.h')
-rw-r--r-- | zebra/zserv.h | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/zebra/zserv.h b/zebra/zserv.h index 9d442899f..b943c246c 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -96,6 +96,14 @@ struct zserv { /* Client file descriptor. */ int sock; + /* Attributes used to permit access to zapi clients from + * other pthreads: the client has a busy counter, and a + * 'closed' flag. These attributes are managed using a + * lock, via the acquire_client() and release_client() apis. + */ + int busy_count; + bool is_closed; + /* Input/output buffer to the client. */ pthread_mutex_t ibuf_mtx; struct stream_fifo *ibuf_fifo; @@ -116,7 +124,7 @@ struct zserv { /* Event for message processing, for the main pthread */ struct thread *t_process; - /* Threads for the main pthread */ + /* Event for the main pthread */ struct thread *t_cleanup; /* This client's redistribute flag. */ @@ -306,6 +314,27 @@ struct zserv *zserv_find_client_session(uint8_t proto, unsigned short instance, uint32_t session_id); /* + * Retrieve a client object by the complete tuple of + * {protocol, instance, session}. This version supports use + * from a different pthread: the object will be returned marked + * in-use. The caller *must* release the client object with the + * release_client() api, to ensure that the in-use marker is cleared properly. + * + * Returns: + * The Zebra API client. + */ +extern struct zserv *zserv_acquire_client(uint8_t proto, + unsigned short instance, + uint32_t session_id); + +/* + * Release a client object that was acquired with the acquire_client() api. + * After this has been called, the pointer must not be used - it may be freed + * in another pthread if the client has closed. + */ +extern void zserv_release_client(struct zserv *client); + +/* * Close a client. * * Kills a client's thread, removes the client from the client list and cleans |