summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri@ouroboros.rocks>2026-05-01 14:43:33 +0200
committerSander Vrijders <sander@ouroboros.rocks>2026-05-20 08:17:04 +0200
commit81ea9a137b87fb8264d439a944cc077aced71602 (patch)
tree6dd1507ccdcc49a4abd5b8ac96b7a8c59684a99a
parent5f0e3f8bf1710f23eaa223357e41a8595487094b (diff)
downloadouroboros-81ea9a137b87fb8264d439a944cc077aced71602.tar.gz
ouroboros-81ea9a137b87fb8264d439a944cc077aced71602.zip
lib: Drop RIB lock before component callback
The RIB lock only needs to protect operations on the components list. This avoids holding the lock on longer RIB reads. Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks> Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
-rw-r--r--src/lib/rib.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/lib/rib.c b/src/lib/rib.c
index a8d535c9..6e421397 100644
--- a/src/lib/rib.c
+++ b/src/lib/rib.c
@@ -112,14 +112,14 @@ static int rib_read(const char * path,
(void) info;
(void) offset;
- pthread_rwlock_wrlock(&rib.lock);
+ pthread_rwlock_rdlock(&rib.lock);
list_for_each(p, &rib.reg_comps) {
struct reg_comp * r = list_entry(p, struct reg_comp, next);
if (strcmp(comp, r->path) == 0) {
- int ret = r->ops->read(path + 1, buf, size);
+ struct rib_ops * ops = r->ops;
pthread_rwlock_unlock(&rib.lock);
- return ret;
+ return ops->read(path + 1, buf, size);
}
}
@@ -160,19 +160,25 @@ static int rib_readdir(const char * path,
ssize_t len;
ssize_t i;
struct reg_comp * c;
+ struct rib_ops * ops;
c = list_entry(p, struct reg_comp, next);
if (strcmp(path + 1, c->path) != 0)
continue;
- assert(c->ops->readdir != NULL);
+ ops = c->ops;
+
+ assert(ops->readdir != NULL);
+
+ pthread_rwlock_unlock(&rib.lock);
- len = c->ops->readdir(&dir_entries);
+ len = ops->readdir(&dir_entries);
if (len < 0)
- break;
+ return 0;
for (i = 0; i < len; ++i)
filler(buf, dir_entries[i], NULL, 0);
freepp(char, dir_entries, len);
+ return 0;
}
}