1/*
2 * cf_mutex.h
3 *
4 * Copyright (C) 2017 Aerospike, Inc.
5 *
6 * Portions may be licensed to Aerospike, Inc. under one or more contributor
7 * license agreements.
8 *
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU Affero General Public License as published by the Free
11 * Software Foundation, either version 3 of the License, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/
21 */
22
23#pragma once
24
25
26//==========================================================
27// Includes.
28//
29
30#include <stdbool.h>
31#include <stdint.h>
32
33
34//==========================================================
35// Typedefs & constants.
36//
37
38typedef struct cf_mutex_s {
39 uint32_t u32;
40} cf_mutex __attribute__ ((aligned(4)));
41
42typedef struct cf_condition_s {
43 uint32_t seq;
44} cf_condition __attribute__ ((aligned(4)));
45
46#define CF_MUTEX_INIT { 0 }
47#define cf_mutex_init(__m) (__m)->u32 = 0
48#define cf_mutex_destroy(__m) // no-op
49
50#define CF_CONDITION_INIT { 0 }
51#define cf_condition_init(__m) (__m)->seq = 0
52#define cf_condition_destroy(__m) // no-op
53
54
55//==========================================================
56// Public API.
57//
58
59void cf_mutex_lock(cf_mutex *m);
60void cf_mutex_unlock(cf_mutex *m);
61bool cf_mutex_trylock(cf_mutex *m);
62
63void cf_mutex_lock_spin(cf_mutex *m);
64void cf_mutex_unlock_spin(cf_mutex *m);
65
66void cf_condition_wait(cf_condition *c, cf_mutex *m);
67void cf_condition_signal(cf_condition *c);
68