PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/core/10.4/fusefs/fuse_locking.h

http://macfuse.googlecode.com/
C++ Header | 82 lines | 57 code | 18 blank | 7 comment | 0 complexity | c06a7614d26d1cc66f43acd58a2f9e82 MD5 | raw file
 1/*
 2 * Copyright (C) 2006 Google. All Rights Reserved.
 3 * Amit Singh <singh@>
 4 */
 5
 6#ifndef _FUSE_LOCKING_H_
 7#define _FUSE_LOCKING_H_
 8
 9#include "fuse_node.h"
10#include <IOKit/IOLocks.h>
11
12enum fusefslocktype {
13    FUSEFS_SHARED_LOCK    = 1,
14    FUSEFS_EXCLUSIVE_LOCK = 2,
15    FUSEFS_FORCE_LOCK     = 3
16};
17
18#define FUSEFS_SHARED_OWNER (void *)0xffffffff
19
20/* Locking */
21extern int fusefs_lock(fusenode_t, enum fusefslocktype);
22extern int fusefs_lockpair(fusenode_t, fusenode_t, enum fusefslocktype);
23extern int fusefs_lockfour(fusenode_t, fusenode_t, fusenode_t, fusenode_t,
24                           enum fusefslocktype);
25extern void fusefs_lock_truncate(fusenode_t, lck_rw_type_t);
26
27/* Unlocking */
28extern void fusefs_unlock(fusenode_t);
29extern void fusefs_unlockpair(fusenode_t, fusenode_t);
30extern void fusefs_unlockfour(fusenode_t, fusenode_t, fusenode_t, fusenode_t);
31extern void fusefs_unlock_truncate(fusenode_t);
32
33/* Wish the kernel exported lck_rw_done()... */
34extern void fusefs_lck_rw_done(lck_rw_t *);
35
36extern lck_attr_t     *fuse_lock_attr;
37extern lck_grp_attr_t *fuse_group_attr;
38extern lck_grp_t      *fuse_lock_group;
39extern lck_mtx_t      *fuse_device_mutex;
40
41#ifdef FUSE_TRACE_LK
42
43#define fuse_lck_mtx_lock(m)                                                  \
44    {                                                                         \
45        proc_t __FUNCTION__ ## p = current_proc();                            \
46        IOLog("0: lck_mtx_lock(%p): %s@%d by %d\n", (m), __FUNCTION__,        \
47           __LINE__, (__FUNCTION__ ## p) ? proc_pid(__FUNCTION__ ## p) : 0);  \
48        lck_mtx_lock((m));                                                    \
49        IOLog("1: lck_mtx_lock(%p): %s@%d by %d\n", (m), __FUNCTION__,        \
50           __LINE__, (__FUNCTION__ ## p) ? proc_pid(__FUNCTION__ ## p) : 0);  \
51    }
52
53#define fuse_lck_mtx_unlock(m)                                                \
54    {                                                                         \
55        proc_t __FUNCTION__ ## p = current_proc();                            \
56        IOLog("1: lck_mtx_unlock(%p): %s@%d by %d\n", (m), __FUNCTION__,      \
57           __LINE__, (__FUNCTION__ ## p) ? proc_pid(__FUNCTION__ ## p) : 0);  \
58        lck_mtx_unlock((m));                                                  \
59        IOLog("0: lck_mtx_unlock(%p): %s@%d by %d\n", (m), __FUNCTION__,      \
60           __LINE__, (__FUNCTION__ ## p) ? proc_pid(__FUNCTION__ ## p) : 0);  \
61    }
62
63#define fuse_lck_rw_lock_shared(l)      lck_rw_lock_shared((l))
64#define fuse_lck_rw_lock_exclusive(l)   lck_rw_lock_exclusive((l))
65#define fuse_lck_rw_unlock_shared(l)    lck_rw_unlock_shared((l))
66#define fuse_lck_rw_unlock_exclusive(l) lck_rw_unlock_exclusive((l))
67
68#else /* !FUSE_TRACE_LK */
69
70#define fuse_lck_mtx_lock(m)            lck_mtx_lock((m))
71#define fuse_lck_mtx_unlock(m)          lck_mtx_unlock((m))
72
73#define fuse_lck_rw_lock_shared(l)      lck_rw_lock_shared((l))
74#define fuse_lck_rw_lock_exclusive(l)   lck_rw_lock_exclusive((l))
75#define fuse_lck_rw_unlock_shared(l)    lck_rw_unlock_shared((l))
76#define fuse_lck_rw_unlock_exclusive(l) lck_rw_unlock_exclusive((l))
77
78#define fuse_lck_mtx_try_lock(l)        IOLockTryLock((IOLock *)l)
79
80#endif /* FUSE_TRACE_LK */
81
82#endif /* _FUSE_LOCKING_H_ */