diff options
| author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2026-07-05 18:10:50 +0200 |
|---|---|---|
| committer | Sander Vrijders <sander@ouroboros.rocks> | 2026-07-08 11:02:24 +0200 |
| commit | 2e5391e78c3c145e402bff1efef0a4160002b418 (patch) | |
| tree | b7665f76498b383981ed94e24c9856beac3aeaa6 | |
| parent | 0562337b7aaee1c50fa840e220eba4f7478a9e82 (diff) | |
| download | ouroboros-2e5391e78c3c145e402bff1efef0a4160002b418.tar.gz ouroboros-2e5391e78c3c145e402bff1efef0a4160002b418.zip | |
lib: Prefer writers on the proc flow lock
FRCT readers hold proc.lock in a rdlock loop and could starve a
pending flow accept waiting for the wrlock. Initialise the lock with
the writer-nonrecursive kind on Linux with glibc, so writers are not
indefinitely delayed.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
| -rw-r--r-- | src/lib/dev.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c index c4c874cc..0586f012 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -850,9 +850,10 @@ static void init(int argc, char ** argv, char ** envp) { - struct proc_info info; - char * prog = argv[0]; - int i; + struct proc_info info; + char * prog = argv[0]; + int i; + pthread_rwlockattr_t attr; #ifdef PROC_FLOW_STATS char procstr[32]; #endif @@ -937,7 +938,16 @@ static void init(int argc, goto fail_cond; } - if (pthread_rwlock_init(&proc.lock, NULL) < 0) { + /* Writer-preferred: FRCT readers must not starve flow accept. */ + if (pthread_rwlockattr_init(&attr) != 0) { + fprintf(stderr, "FATAL: Could not init rwlock attributes.\n"); + goto fail_rwlock_attr; + } +#if defined(__GLIBC__) + pthread_rwlockattr_setkind_np( + &attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); +#endif + if (pthread_rwlock_init(&proc.lock, &attr) != 0) { fprintf(stderr, "FATAL: Could not initialize flow lock.\n"); goto fail_flow_lock; } @@ -967,6 +977,8 @@ static void init(int argc, } } #endif + pthread_rwlockattr_destroy(&attr); + return; #if defined PROC_FLOW_STATS @@ -980,6 +992,8 @@ static void init(int argc, fail_fqset: pthread_rwlock_destroy(&proc.lock); fail_flow_lock: + pthread_rwlockattr_destroy(&attr); + fail_rwlock_attr: pthread_cond_destroy(&proc.cond); fail_cond: pthread_mutex_destroy(&proc.mtx); |
