Skip to content
Snippets Groups Projects
Commit 29d05537 authored by Glauber Costa's avatar Glauber Costa
Browse files

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.
parent d2a5235e
No related branches found
No related tags found
No related merge requests found
...@@ -130,12 +130,6 @@ extern int tick; ...@@ -130,12 +130,6 @@ extern int tick;
#define ENOIOCTL (-3) /* ioctl not handled by this layer */ #define ENOIOCTL (-3) /* ioctl not handled by this layer */
#define EDIRIOCTL (-4) /* do direct ioctl in GEOM */ #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... */ /* FIXME: TODO - Implement... */
#ifndef time_uptime #ifndef time_uptime
#define time_uptime (1) #define time_uptime (1)
......
#include <osv/mutex.h> #include <osv/mutex.h>
#include <osv/rwlock.h>
#include <stdlib.h> #include <stdlib.h>
#include <bsd/porting/sync_stub.h> #include <bsd/porting/sync_stub.h>
...@@ -40,3 +41,28 @@ void mtx_assert(struct mtx *mp, int flag) ...@@ -40,3 +41,28 @@ void mtx_assert(struct mtx *mp, int flag)
abort(); 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);
}
...@@ -22,6 +22,21 @@ void mtx_destroy(struct mtx *m); ...@@ -22,6 +22,21 @@ void mtx_destroy(struct mtx *m);
void mtx_lock(struct mtx *mp); void mtx_lock(struct mtx *mp);
void mtx_unlock(struct mtx *mp); void mtx_unlock(struct mtx *mp);
void mtx_assert(struct mtx *mp, int flag); 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 __END_DECLS
#define mtx_sleep(chan, mtx, pri, wmesg, timo) (void)0; #define mtx_sleep(chan, mtx, pri, wmesg, timo) (void)0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment