2019-02-24 00:03:22 +08:00
|
|
|
/*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Philippe Gerum <rpm@xenomai.org>
|
|
|
|
*/
|
|
|
|
|
2019-03-10 23:25:02 +08:00
|
|
|
#ifndef _EVL_MUTEX_H
|
|
|
|
#define _EVL_MUTEX_H
|
2019-02-24 00:03:22 +08:00
|
|
|
|
2019-03-08 23:58:34 +08:00
|
|
|
#include <time.h>
|
|
|
|
#include <linux/types.h>
|
2019-03-10 23:25:02 +08:00
|
|
|
#include <evl/atomic.h>
|
|
|
|
#include <uapi/evl/types.h>
|
|
|
|
#include <uapi/evl/monitor.h>
|
2019-02-24 00:03:22 +08:00
|
|
|
|
2019-08-18 22:30:47 +08:00
|
|
|
#define EVL_MUTEX_NORMAL 0
|
|
|
|
#define EVL_MUTEX_RECURSIVE 1
|
|
|
|
|
|
|
|
#define __MUTEX_UNINIT_MAGIC 0xfe11fe11
|
|
|
|
#define __MUTEX_ACTIVE_MAGIC 0xab12ab12
|
|
|
|
|
2019-03-04 00:03:22 +08:00
|
|
|
struct evl_mutex {
|
2019-03-08 23:58:34 +08:00
|
|
|
unsigned int magic;
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
fundle_t fundle;
|
|
|
|
struct evl_monitor_state *state;
|
|
|
|
int efd;
|
2019-08-18 22:30:47 +08:00
|
|
|
int monitor : 2,
|
2019-06-11 23:17:48 +08:00
|
|
|
protocol : 4;
|
2019-03-08 23:58:34 +08:00
|
|
|
} active;
|
|
|
|
struct {
|
|
|
|
const char *name;
|
|
|
|
int clockfd;
|
|
|
|
unsigned int ceiling;
|
2019-08-18 22:30:47 +08:00
|
|
|
int monitor : 2,
|
|
|
|
protocol : 4,
|
|
|
|
type : 1;
|
2019-03-08 23:58:34 +08:00
|
|
|
} uninit;
|
|
|
|
};
|
2019-02-24 00:03:22 +08:00
|
|
|
};
|
|
|
|
|
2019-08-18 22:30:47 +08:00
|
|
|
#define EVL_MUTEX_INITIALIZER(__type, __name, __clockfd) { \
|
|
|
|
.magic = __MUTEX_UNINIT_MAGIC, \
|
|
|
|
.uninit = { \
|
|
|
|
.monitor = EVL_MONITOR_GATE, \
|
|
|
|
.protocol = EVL_GATE_PI, \
|
|
|
|
.type = (__type), \
|
|
|
|
.name = (__name), \
|
|
|
|
.clockfd = (__clockfd), \
|
|
|
|
.ceiling = 0, \
|
|
|
|
} \
|
2019-02-24 00:03:22 +08:00
|
|
|
}
|
|
|
|
|
2019-08-18 22:30:47 +08:00
|
|
|
#define EVL_MUTEX_CEILING_INITIALIZER(__type, __name, __clockfd, __ceiling) { \
|
2019-03-08 23:58:34 +08:00
|
|
|
.magic = __MUTEX_UNINIT_MAGIC, \
|
2019-08-18 22:30:47 +08:00
|
|
|
.uninit = { \
|
|
|
|
.monitor = EVL_MONITOR_GATE, \
|
2019-06-11 23:17:48 +08:00
|
|
|
.protocol = EVL_GATE_PP, \
|
2019-08-18 22:30:47 +08:00
|
|
|
.type = (__type), \
|
2019-03-08 23:58:34 +08:00
|
|
|
.name = (__name), \
|
2019-08-08 19:10:25 +08:00
|
|
|
.clockfd = (__clockfd), \
|
2019-03-08 23:58:34 +08:00
|
|
|
.ceiling = (__ceiling), \
|
2019-02-24 00:03:22 +08:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-08-18 22:30:47 +08:00
|
|
|
int evl_new_mutex(struct evl_mutex *mutex, int type,
|
2019-02-24 00:03:22 +08:00
|
|
|
int clockfd, const char *fmt, ...);
|
|
|
|
|
2019-08-18 22:30:47 +08:00
|
|
|
int evl_new_mutex_ceiling(struct evl_mutex *mutex, int type,
|
2019-02-24 00:03:22 +08:00
|
|
|
int clockfd, unsigned int ceiling,
|
|
|
|
const char *fmt, ...);
|
|
|
|
|
2019-03-04 00:03:22 +08:00
|
|
|
int evl_open_mutex(struct evl_mutex *mutex,
|
2019-02-24 00:03:22 +08:00
|
|
|
const char *fmt, ...);
|
|
|
|
|
2019-06-13 02:59:49 +08:00
|
|
|
int evl_lock_mutex(struct evl_mutex *mutex);
|
2019-02-24 00:03:22 +08:00
|
|
|
|
2019-06-13 02:59:49 +08:00
|
|
|
int evl_timedlock_mutex(struct evl_mutex *mutex,
|
|
|
|
const struct timespec *timeout);
|
2019-02-24 00:03:22 +08:00
|
|
|
|
2019-06-13 02:59:49 +08:00
|
|
|
int evl_trylock_mutex(struct evl_mutex *mutex);
|
2019-02-24 00:03:22 +08:00
|
|
|
|
2019-06-13 02:59:49 +08:00
|
|
|
int evl_unlock_mutex(struct evl_mutex *mutex);
|
2019-02-24 00:03:22 +08:00
|
|
|
|
2019-03-04 00:03:22 +08:00
|
|
|
int evl_set_mutex_ceiling(struct evl_mutex *mutex,
|
2019-02-24 00:03:22 +08:00
|
|
|
unsigned int ceiling);
|
|
|
|
|
2019-03-04 00:03:22 +08:00
|
|
|
int evl_get_mutex_ceiling(struct evl_mutex *mutex);
|
2019-02-24 00:03:22 +08:00
|
|
|
|
2019-03-04 00:03:22 +08:00
|
|
|
int evl_close_mutex(struct evl_mutex *mutex);
|
2019-02-24 00:03:22 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-03-10 23:25:02 +08:00
|
|
|
#endif /* _EVL_MUTEX_H */
|