~ubuntu-branches/ubuntu/trusty/drbd8/trusty

« back to all changes in this revision

Viewing changes to drbd/linux/mutex.h

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2011-07-05 15:40:13 UTC
  • mfrom: (1.4.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110705154013-f9l32owj6mi9e1p0
Tags: 2:8.3.11-0ubuntu1
* New upstream release
* debian/patches/01_ubuntu_cn_idx.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* "Backport" of the mutex to older Linux-2.6.x kernels.
2
 
 */
3
 
#ifndef __LINUX_MUTEX_H
4
 
#define __LINUX_MUTEX_H
5
 
 
6
 
#include <asm/semaphore.h>
7
 
 
8
 
struct mutex {
9
 
        struct semaphore sem;
10
 
};
11
 
 
12
 
static inline void mutex_init(struct mutex *m)
13
 
{
14
 
        sema_init(&m->sem, 1);
15
 
}
16
 
 
17
 
static inline void mutex_lock(struct mutex *m)
18
 
{
19
 
        down(&m->sem);
20
 
}
21
 
 
22
 
static inline int mutex_lock_interruptible(struct mutex *m)
23
 
{
24
 
        return down_interruptible(&m->sem);
25
 
}
26
 
 
27
 
static inline void mutex_unlock(struct mutex *m)
28
 
{
29
 
        up(&m->sem);
30
 
}
31
 
 
32
 
static inline int mutex_is_locked(struct mutex *lock)
33
 
{
34
 
        return atomic_read(&lock->sem.count) != 1;
35
 
}
36
 
 
37
 
static inline int mutex_trylock(struct mutex *lock)
38
 
{
39
 
        return !down_trylock(&lock->sem);
40
 
}
41
 
#endif