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>
|
lib: introduce element visibility attribute
Since core ABI 21, users can decide whether a new element should be
made public or private depending on the value of clone flags added to
the new long form of all element creation calls, i.e. evl_create_*().
All evl_new_*() calls become a shorthand for their respective long
form with reasonable default arguments, including private visibility.
As a shorthand, libevl also interprets a slash character leading the
name argument passed to these services as an implicit request for
creating a public element. In other words, this is the same as passing
EVL_CLONE_PUBLIC in the clone flags.
A public element appears as a cdev in the /dev/evl hierarchy, which
means that it is visible to other processes, which may share it. On
the contrary, a private element is only known from the process
creating it, although it does appear in the /sysfs hierarchy
regardless.
e.g.:
efd = evl_attach_self("/visible-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
crw-rw---- 1 root root 246, 0 Apr 17 11:59 visible-thread
or,
efd = evl_attach_self("private-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-17 18:24:28 +08:00
|
|
|
#include <uapi/evl/factory.h>
|
2019-02-24 00:03:22 +08:00
|
|
|
|
lib: introduce element visibility attribute
Since core ABI 21, users can decide whether a new element should be
made public or private depending on the value of clone flags added to
the new long form of all element creation calls, i.e. evl_create_*().
All evl_new_*() calls become a shorthand for their respective long
form with reasonable default arguments, including private visibility.
As a shorthand, libevl also interprets a slash character leading the
name argument passed to these services as an implicit request for
creating a public element. In other words, this is the same as passing
EVL_CLONE_PUBLIC in the clone flags.
A public element appears as a cdev in the /dev/evl hierarchy, which
means that it is visible to other processes, which may share it. On
the contrary, a private element is only known from the process
creating it, although it does appear in the /sysfs hierarchy
regardless.
e.g.:
efd = evl_attach_self("/visible-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
crw-rw---- 1 root root 246, 0 Apr 17 11:59 visible-thread
or,
efd = evl_attach_self("private-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-17 18:24:28 +08:00
|
|
|
#define EVL_MUTEX_NORMAL (0 << 0)
|
|
|
|
#define EVL_MUTEX_RECURSIVE (1 << 0)
|
2019-08-18 22:30:47 +08:00
|
|
|
|
|
|
|
#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;
|
lib: introduce element visibility attribute
Since core ABI 21, users can decide whether a new element should be
made public or private depending on the value of clone flags added to
the new long form of all element creation calls, i.e. evl_create_*().
All evl_new_*() calls become a shorthand for their respective long
form with reasonable default arguments, including private visibility.
As a shorthand, libevl also interprets a slash character leading the
name argument passed to these services as an implicit request for
creating a public element. In other words, this is the same as passing
EVL_CLONE_PUBLIC in the clone flags.
A public element appears as a cdev in the /dev/evl hierarchy, which
means that it is visible to other processes, which may share it. On
the contrary, a private element is only known from the process
creating it, although it does appear in the /sysfs hierarchy
regardless.
e.g.:
efd = evl_attach_self("/visible-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
crw-rw---- 1 root root 246, 0 Apr 17 11:59 visible-thread
or,
efd = evl_attach_self("private-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-17 18:24:28 +08:00
|
|
|
int flags;
|
|
|
|
int monitor : 2;
|
2019-03-08 23:58:34 +08:00
|
|
|
} uninit;
|
2020-03-26 00:29:41 +08:00
|
|
|
} u;
|
2019-02-24 00:03:22 +08:00
|
|
|
};
|
|
|
|
|
lib: introduce element visibility attribute
Since core ABI 21, users can decide whether a new element should be
made public or private depending on the value of clone flags added to
the new long form of all element creation calls, i.e. evl_create_*().
All evl_new_*() calls become a shorthand for their respective long
form with reasonable default arguments, including private visibility.
As a shorthand, libevl also interprets a slash character leading the
name argument passed to these services as an implicit request for
creating a public element. In other words, this is the same as passing
EVL_CLONE_PUBLIC in the clone flags.
A public element appears as a cdev in the /dev/evl hierarchy, which
means that it is visible to other processes, which may share it. On
the contrary, a private element is only known from the process
creating it, although it does appear in the /sysfs hierarchy
regardless.
e.g.:
efd = evl_attach_self("/visible-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
crw-rw---- 1 root root 246, 0 Apr 17 11:59 visible-thread
or,
efd = evl_attach_self("private-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-17 18:24:28 +08:00
|
|
|
#define EVL_MUTEX_INITIALIZER(__name, __clockfd, __ceiling, __flags) { \
|
2019-03-08 23:58:34 +08:00
|
|
|
.magic = __MUTEX_UNINIT_MAGIC, \
|
2020-03-26 00:29:41 +08:00
|
|
|
.u = { \
|
|
|
|
.uninit = { \
|
|
|
|
.name = (__name), \
|
|
|
|
.clockfd = (__clockfd), \
|
|
|
|
.ceiling = (__ceiling), \
|
lib: introduce element visibility attribute
Since core ABI 21, users can decide whether a new element should be
made public or private depending on the value of clone flags added to
the new long form of all element creation calls, i.e. evl_create_*().
All evl_new_*() calls become a shorthand for their respective long
form with reasonable default arguments, including private visibility.
As a shorthand, libevl also interprets a slash character leading the
name argument passed to these services as an implicit request for
creating a public element. In other words, this is the same as passing
EVL_CLONE_PUBLIC in the clone flags.
A public element appears as a cdev in the /dev/evl hierarchy, which
means that it is visible to other processes, which may share it. On
the contrary, a private element is only known from the process
creating it, although it does appear in the /sysfs hierarchy
regardless.
e.g.:
efd = evl_attach_self("/visible-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
crw-rw---- 1 root root 246, 0 Apr 17 11:59 visible-thread
or,
efd = evl_attach_self("private-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-17 18:24:28 +08:00
|
|
|
.flags = (__flags), \
|
2020-03-26 00:29:41 +08:00
|
|
|
.monitor = EVL_MONITOR_GATE, \
|
|
|
|
} \
|
2019-02-24 00:03:22 +08:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
lib: introduce element visibility attribute
Since core ABI 21, users can decide whether a new element should be
made public or private depending on the value of clone flags added to
the new long form of all element creation calls, i.e. evl_create_*().
All evl_new_*() calls become a shorthand for their respective long
form with reasonable default arguments, including private visibility.
As a shorthand, libevl also interprets a slash character leading the
name argument passed to these services as an implicit request for
creating a public element. In other words, this is the same as passing
EVL_CLONE_PUBLIC in the clone flags.
A public element appears as a cdev in the /dev/evl hierarchy, which
means that it is visible to other processes, which may share it. On
the contrary, a private element is only known from the process
creating it, although it does appear in the /sysfs hierarchy
regardless.
e.g.:
efd = evl_attach_self("/visible-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
crw-rw---- 1 root root 246, 0 Apr 17 11:59 visible-thread
or,
efd = evl_attach_self("private-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-17 18:24:28 +08:00
|
|
|
#define evl_new_mutex(__mutex, __fmt, __args...) \
|
|
|
|
evl_create_mutex(__mutex, EVL_CLOCK_MONOTONIC, \
|
|
|
|
0, EVL_MUTEX_NORMAL|EVL_CLONE_PRIVATE, \
|
|
|
|
__fmt, ##__args)
|
2019-08-19 01:20:21 +08:00
|
|
|
|
2019-02-24 00:03:22 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
lib: introduce element visibility attribute
Since core ABI 21, users can decide whether a new element should be
made public or private depending on the value of clone flags added to
the new long form of all element creation calls, i.e. evl_create_*().
All evl_new_*() calls become a shorthand for their respective long
form with reasonable default arguments, including private visibility.
As a shorthand, libevl also interprets a slash character leading the
name argument passed to these services as an implicit request for
creating a public element. In other words, this is the same as passing
EVL_CLONE_PUBLIC in the clone flags.
A public element appears as a cdev in the /dev/evl hierarchy, which
means that it is visible to other processes, which may share it. On
the contrary, a private element is only known from the process
creating it, although it does appear in the /sysfs hierarchy
regardless.
e.g.:
efd = evl_attach_self("/visible-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
crw-rw---- 1 root root 246, 0 Apr 17 11:59 visible-thread
or,
efd = evl_attach_self("private-thread");
total 0
crw-rw---- 1 root root 248, 1 Apr 17 11:59 clone
Signed-off-by: Philippe Gerum <rpm@xenomai.org>
2020-04-17 18:24:28 +08:00
|
|
|
int evl_create_mutex(struct evl_mutex *mutex,
|
|
|
|
int clockfd, unsigned int ceiling, int flags,
|
2019-08-19 01:20:21 +08:00
|
|
|
const char *fmt, ...);
|
2019-02-24 00:03:22 +08:00
|
|
|
|
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 */
|