summaryrefslogtreecommitdiff
path: root/lib/command.c
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2019-04-03 16:31:18 -0300
committerRenato Westphal <renato@opensourcerouting.org>2019-04-26 18:04:22 -0300
commit83981138fe8c1e0a40b8dede74eca65449dda5de (patch)
treecd22f38c39e38eb1fb9f0dd7354fe19480523fba /lib/command.c
parent364ad673c885d741d575e97dbae70bf6d7c8f36e (diff)
lib: introduce a read-write lock for northbound configurations
The upcoming gRPC-based northbound plugin will run on a separate pthread, and it will need to have access to the running configuration global variable. Introduce a rw-lock to control concurrent access to the running configuration. Add the lock inside the "nb_config" structure so that it can be used to protect candidate configurations as well (this might be necessary depending on the threading scheme of future northbound plugins). Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
Diffstat (limited to 'lib/command.c')
-rw-r--r--lib/command.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/command.c b/lib/command.c
index 559457c119..b3ef028004 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -1705,12 +1705,16 @@ static int vty_write_config(struct vty *vty)
vty_out(vty, "frr defaults %s\n", DFLT_NAME);
vty_out(vty, "!\n");
- for (i = 0; i < vector_active(cmdvec); i++)
- if ((node = vector_slot(cmdvec, i)) && node->func
- && (node->vtysh || vty->type != VTY_SHELL)) {
- if ((*node->func)(vty))
- vty_out(vty, "!\n");
- }
+ pthread_rwlock_rdlock(&running_config->lock);
+ {
+ for (i = 0; i < vector_active(cmdvec); i++)
+ if ((node = vector_slot(cmdvec, i)) && node->func
+ && (node->vtysh || vty->type != VTY_SHELL)) {
+ if ((*node->func)(vty))
+ vty_out(vty, "!\n");
+ }
+ }
+ pthread_rwlock_unlock(&running_config->lock);
if (vty->type == VTY_TERM) {
vty_out(vty, "end\n");