NewMadeleine

Documentation

nm_lock.h
Go to the documentation of this file.
1/*
2 * NewMadeleine
3 * Copyright (C) 2009-2022 (see AUTHORS file)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 */
15
22#include <pthread.h>
23
24#ifndef NM_LOCK_H
25#define NM_LOCK_H
26
27#ifndef NM_PRIVATE_H
28# error "Cannot include this file directly. Please include <nm_private.h>"
29#endif
30
32static inline void nm_core_lock(struct nm_core*p_core);
33
37static inline int nm_core_trylock(struct nm_core*p_core);
38
40static inline void nm_core_unlock(struct nm_core*p_core);
41
43static inline void nm_core_lock_init(struct nm_core*p_core);
44
46static inline void nm_core_lock_destroy(struct nm_core*p_core);
47
49static inline void nm_core_nolock_assert(struct nm_core*p_core);
50
52static inline void nm_core_lock_assert(struct nm_core*p_core);
53
54
55/* ********************************************************* */
56/* inline definition */
57
58static inline void nm_core_lock(struct nm_core*p_core __attribute__((unused)))
59{
60 nm_spin_lock(&p_core->lock);
61 nm_profile_inc(p_core->profiling.n_locks);
62}
63
64static inline int nm_core_trylock(struct nm_core*p_core __attribute__((unused)))
65{
66 int rc = nm_spin_trylock(&p_core->lock);
67 if(rc)
68 nm_profile_inc(p_core->profiling.n_locks);
69 return rc;
70}
71
72static inline void nm_core_unlock(struct nm_core*p_core __attribute__((unused)))
73{
74 nm_spin_unlock(&p_core->lock);
75}
76
77static inline void nm_core_lock_init(struct nm_core*p_core __attribute__((unused)))
78{
79 nm_spin_init(&p_core->lock);
80}
81
82static inline void nm_core_lock_destroy(struct nm_core*p_core __attribute__((unused)))
83{
84 nm_spin_destroy(&p_core->lock);
85}
86
87static inline void nm_core_lock_assert(struct nm_core*p_core __attribute__((unused)))
88{
89 nm_spin_assert_locked(&p_core->lock);
90}
91
92static inline void nm_core_nolock_assert(struct nm_core*p_core __attribute__((unused)))
93{
94 nm_spin_assert_notlocked(&p_core->lock);
95}
96
97#endif /* NM_LOCK_H */
static void nm_spin_init(nm_spinlock_t *p_spin)
init the spin lock
static void nm_spin_assert_notlocked(nm_spinlock_t *p_spin)
assert that current thread doesn't hold the lock
struct nm_core_event_s __attribute__
static int nm_spin_trylock(nm_spinlock_t *p_spin)
try to lock the spin lock return 1 if lock is successfully acquired, 0 otherwise
static void nm_spin_destroy(nm_spinlock_t *p_spin)
destroy the spin lock
static void nm_spin_lock(nm_spinlock_t *p_spin)
acquire the spin lock
static void nm_spin_assert_locked(nm_spinlock_t *p_spin)
assert that current thread holds the lock
static void nm_spin_unlock(nm_spinlock_t *p_spin)
release the spin lock
#define nm_profile_inc(COUNTER)
static void nm_core_unlock(struct nm_core *p_core)
unlock the nm core lock
static void nm_core_lock_init(struct nm_core *p_core)
init the core lock
static void nm_core_nolock_assert(struct nm_core *p_core)
assert that current thread doesn't hold the lock
static int nm_core_trylock(struct nm_core *p_core)
try to lock the nm core core return 1 is lock is successfully acquired, 0 otherwise
static void nm_core_lock_destroy(struct nm_core *p_core)
destroy the core lock
static void nm_core_lock(struct nm_core *p_core)
acquire the nm core lock
static void nm_core_lock_assert(struct nm_core *p_core)
assert that current thread holds the lock
Core NewMadeleine structure.
Definition: nm_core.h:39