From 29d05537a424309a1bf74e9800dc0ede3334851e Mon Sep 17 00:00:00 2001 From: Glauber Costa <glommer@cloudius-systems.com> Date: Wed, 26 Jun 2013 16:09:46 +0400 Subject: [PATCH] bsd: stubs for sx_xlock Aside from mutex, BSD always implements sx locks. They are a form of rwlock, and according to BSD's sx.h, the differences from their own rwlock are an implementation detail. Let's just use them as rwlocks for now. The declarations are uglier than I wanted. But this file ends up being included from c and cc code, and rwlock.h calls condvar.h inside - which is full of sync_stub.h - and as a result condvar.h itself - are usually included in extern "C" blocks. Because we are not expected to use sxlocks from C, it should be fine. --- bsd/porting/netport.h | 6 ------ bsd/porting/sync_stub.c | 26 ++++++++++++++++++++++++++ bsd/porting/sync_stub.h | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/bsd/porting/netport.h b/bsd/porting/netport.h index 57d9a04c9..53d24482e 100644 --- a/bsd/porting/netport.h +++ b/bsd/porting/netport.h @@ -130,12 +130,6 @@ extern int tick; #define ENOIOCTL (-3) /* ioctl not handled by this layer */ #define EDIRIOCTL (-4) /* do direct ioctl in GEOM */ -/* FIXME: TODO - Implement... */ -#define sx_slock(...) do{}while(0) -#define sx_sunlock(...) do{}while(0) -#define sx_xlock(...) do{}while(0) -#define sx_xunlock(...) do{}while(0) - /* FIXME: TODO - Implement... */ #ifndef time_uptime #define time_uptime (1) diff --git a/bsd/porting/sync_stub.c b/bsd/porting/sync_stub.c index 1ec73af3c..9f34a02f9 100644 --- a/bsd/porting/sync_stub.c +++ b/bsd/porting/sync_stub.c @@ -1,4 +1,5 @@ #include <osv/mutex.h> +#include <osv/rwlock.h> #include <stdlib.h> #include <bsd/porting/sync_stub.h> @@ -40,3 +41,28 @@ void mtx_assert(struct mtx *mp, int flag) abort(); } } + +void sx_init(struct sx *s, const char *name) +{ + rwlock_init(&s->_rw); +} + +void sx_xlock(struct sx *s) +{ + rw_wlock(&s->_rw); +} + +void sx_xunlock(struct sx *s) +{ + rw_wunlock(&s->_rw); +} + +void sx_slock(struct sx *s) +{ + rw_wlock(&s->_rw); +} + +void sx_sunlock(struct sx *s) +{ + rw_runlock(&s->_rw); +} diff --git a/bsd/porting/sync_stub.h b/bsd/porting/sync_stub.h index 48c571337..629be0139 100644 --- a/bsd/porting/sync_stub.h +++ b/bsd/porting/sync_stub.h @@ -22,6 +22,21 @@ void mtx_destroy(struct mtx *m); void mtx_lock(struct mtx *mp); void mtx_unlock(struct mtx *mp); void mtx_assert(struct mtx *mp, int flag); + +#ifndef __cplusplus +#include <osv/rwlock.h> +struct sx { + rwlock_t _rw; +}; + +void sx_init(struct sx *m, const char *name); +void sx_xlock(struct sx *mp); +void sx_xunlock(struct sx *mp); +void sx_slock(struct sx *mp); +void sx_sunlock(struct sx *mp); +#endif +#define sx_assert(...) do { } while (0) + __END_DECLS #define mtx_sleep(chan, mtx, pri, wmesg, timo) (void)0; -- GitLab