Summary
The cross-platform threading primitives — the mutex_* and cond_* wrapper functions (pthread on POSIX, CRITICAL_SECTION / CONDITION_VARIABLE on Windows) — currently live in valkey_glide_pubsub_common.{c,h}, because pub/sub introduced them first.
They are now also used by the MONITOR client (valkey_glide_monitor_common.*), which #includes valkey_glide_pubsub_common.h solely to obtain a mutex/condition variable. This is an awkward coupling: MONITOR has nothing to do with pub/sub, yet it depends on the pub/sub module for generic threading utilities.
Proposal
Extract the threading wrappers into a dedicated, neutral module, e.g. valkey_glide_threading.{c,h}:
- Move
mutex_init, mutex_lock, mutex_unlock, mutex_destroy
- Move
cond_init, cond_wait, cond_timedwait, cond_signal, cond_destroy
- Update
valkey_glide_pubsub_common.* and valkey_glide_monitor_common.* to include the new header
- Add the new source file to
config.m4, Makefile.frag, and package.xml
Context
Raised in review of #309 (MONITOR command). Deferred from that PR to keep its scope focused; the reviewer (@currantw) agreed to track it separately.
#309 (comment)
Summary
The cross-platform threading primitives — the
mutex_*andcond_*wrapper functions (pthread on POSIX, CRITICAL_SECTION / CONDITION_VARIABLE on Windows) — currently live invalkey_glide_pubsub_common.{c,h}, because pub/sub introduced them first.They are now also used by the MONITOR client (
valkey_glide_monitor_common.*), which#includesvalkey_glide_pubsub_common.hsolely to obtain a mutex/condition variable. This is an awkward coupling: MONITOR has nothing to do with pub/sub, yet it depends on the pub/sub module for generic threading utilities.Proposal
Extract the threading wrappers into a dedicated, neutral module, e.g.
valkey_glide_threading.{c,h}:mutex_init,mutex_lock,mutex_unlock,mutex_destroycond_init,cond_wait,cond_timedwait,cond_signal,cond_destroyvalkey_glide_pubsub_common.*andvalkey_glide_monitor_common.*to include the new headerconfig.m4,Makefile.frag, andpackage.xmlContext
Raised in review of #309 (MONITOR command). Deferred from that PR to keep its scope focused; the reviewer (@currantw) agreed to track it separately.
#309 (comment)