]>
git.proxmox.com Git - ceph.git/blob - ceph/src/include/Spinlock.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 Inktank
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
13 * @author Sage Weil <sage@inktank.com>
16 #ifndef CEPH_SPINLOCK_H
17 #define CEPH_SPINLOCK_H
24 #ifdef HAVE_PTHREAD_SPINLOCK
25 pthread_spinlock_t lock
;
31 #ifdef HAVE_PTHREAD_SPINLOCK
33 static inline int ceph_spin_init(ceph_spinlock_t
*l
)
35 return pthread_spin_init(&l
->lock
, PTHREAD_PROCESS_PRIVATE
);
38 static inline int ceph_spin_destroy(ceph_spinlock_t
*l
)
40 return pthread_spin_destroy(&l
->lock
);
43 static inline int ceph_spin_lock(ceph_spinlock_t
*l
)
45 return pthread_spin_lock(&l
->lock
);
48 static inline int ceph_spin_unlock(ceph_spinlock_t
*l
)
50 return pthread_spin_unlock(&l
->lock
);
53 #else /* !HAVE_PTHREAD_SPINLOCK */
55 static inline int ceph_spin_init(ceph_spinlock_t
*l
)
57 return pthread_mutex_init(&l
->lock
, NULL
);
60 static inline int ceph_spin_destroy(ceph_spinlock_t
*l
)
62 return pthread_mutex_destroy(&l
->lock
);
65 static inline int ceph_spin_lock(ceph_spinlock_t
*l
)
67 return pthread_mutex_lock(&l
->lock
);
70 static inline int ceph_spin_unlock(ceph_spinlock_t
*l
)
72 return pthread_mutex_unlock(&l
->lock
);
78 mutable ceph_spinlock_t _lock
;
82 ceph_spin_init(&_lock
);
85 ceph_spin_destroy(&_lock
);
88 // don't allow copying.
89 void operator=(Spinlock
& s
);
90 Spinlock(const Spinlock
& s
);
94 ceph_spin_lock(&_lock
);
98 ceph_spin_unlock(&_lock
);
102 const Spinlock
& spinlock
;
104 Locker(const Spinlock
& s
) : spinlock(s
) {