1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include <sys/param.h>
#include <support/mrlock.h>
void
_sx_xfs_destroy(struct sx *sx)
{
if (sx->sx_cnt == -1)
sx_xunlock(sx);
sx_destroy(sx);
}
void
_sx_xfs_lock(struct sx *sx, int type, const char *file, int line)
{
if (type == MR_ACCESS)
_sx_slock(sx, file, line);
else if (type == MR_UPDATE)
_sx_sunlock(sx, file, line);
else
panic("Invalid lock type passed");
}
void
_sx_xfs_unlock(struct sx *sx, const char *file, int line)
{
if (_sx_xfs_xowned(sx))
_sx_xunlock(sx, file, line);
else if (_sx_xfs_sowned(sx))
_sx_sunlock(sx, file, line);
else
panic("lock is not locked");
}
int
ismrlocked(mrlock_t *mrp, int type)
{
if (type == MR_ACCESS)
return _sx_xfs_sowned(mrp); /* Read lock */
else if (type == MR_UPDATE)
return _sx_xfs_xowned(mrp); /* Write lock */
else if (type == (MR_UPDATE | MR_ACCESS))
return _sx_xfs_sowned(mrp) ||
_sx_xfs_xowned(mrp); /* Any type of lock held */
return (mrp->sx_shrd_wcnt > 0 || mrp->sx_excl_wcnt > 0);
}
|