From fda1c01f0ddadcca93edf414bdb8b630c8a402b2 Mon Sep 17 00:00:00 2001
From: Daniel Salzman <daniel.salzman@nic.cz>
Date: Fri, 30 Aug 2024 16:44:33 +0200
Subject: [PATCH] ctl: add a workaround for macOS

The functions pthread_rwlock_timedwrlock() and pthread_rwlock_timedrdlock()
are not available on macOS. Use not non-timed variants pthread_rwlock_wrlock()
and pthread_rwlock_rdlock() instead.
---
 src/knot/ctl/commands.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/knot/ctl/commands.c b/src/knot/ctl/commands.c
index e3b8d70d3a..99533a78cc 100644
--- a/src/knot/ctl/commands.c
+++ b/src/knot/ctl/commands.c
@@ -2425,10 +2425,18 @@ static int ctl_lock(server_t *server, ctl_lock_flag_t flags, uint64_t timeout_ms
 
 	if ((flags & CTL_LOCK_SRV_W)) {
 		assert(!(flags & CTL_LOCK_SRV_R));
+#if !defined(__APPLE__)
 		ret = pthread_rwlock_timedwrlock(&server->ctl_lock, &ts);
+#else
+		ret = pthread_rwlock_wrlock(&server->ctl_lock);
+#endif
 	}
 	if ((flags & CTL_LOCK_SRV_R)) {
+#if !defined(__APPLE__)
 		ret = pthread_rwlock_timedrdlock(&server->ctl_lock, &ts);
+#else
+		ret = pthread_rwlock_rdlock(&server->ctl_lock);
+#endif
 	}
 	return (ret != 0 ? KNOT_EBUSY : KNOT_EOK);
 }
-- 
GitLab