Commit f0d37f47 authored by Philippe Gerum's avatar Philippe Gerum
Browse files

treewide: API update

Improve consistency in naming and disambiguate some calls.
parent 90cacf8f
......@@ -4,8 +4,8 @@
* Copyright (C) 2019 Philippe Gerum <rpm@xenomai.org>
*/
#ifndef _EVL_CONDVAR_H
#define _EVL_CONDVAR_H
#ifndef _EVL_EVENT_H
#define _EVL_EVENT_H
#include <time.h>
#include <linux/types.h>
......@@ -13,7 +13,7 @@
#include <uapi/evl/types.h>
#include <uapi/evl/monitor.h>
struct evl_condvar {
struct evl_event {
unsigned int magic;
union {
struct {
......@@ -28,10 +28,10 @@ struct evl_condvar {
};
};
#define __CONDVAR_UNINIT_MAGIC 0x01770177
#define __EVENT_UNINIT_MAGIC 0x01770177
#define EVL_CONDVAR_INITIALIZER(__name, __clock) { \
.magic = __CONDVAR_UNINIT_MAGIC, \
#define EVL_EVENT_INITIALIZER(__name, __clock) { \
.magic = __EVENT_UNINIT_MAGIC, \
.uninit = { \
.name = (__name), \
.clockfd = (__clock), \
......@@ -42,31 +42,31 @@ struct evl_condvar {
extern "C" {
#endif
int evl_new_condvar(struct evl_condvar *cv,
int evl_new_event(struct evl_event *evt,
int clockfd,
const char *fmt, ...);
int evl_open_condvar(struct evl_condvar *cv,
int evl_open_event(struct evl_event *evt,
const char *fmt, ...);
int evl_wait(struct evl_condvar *cv,
struct evl_mutex *mutex);
int evl_wait_event(struct evl_event *evt,
struct evl_mutex *mutex);
int evl_timedwait(struct evl_condvar *cv,
struct evl_mutex *mutex,
const struct timespec *timeout);
int evl_timedwait_event(struct evl_event *evt,
struct evl_mutex *mutex,
const struct timespec *timeout);
int evl_signal(struct evl_condvar *cv);
int evl_signal_event(struct evl_event *evt);
int evl_signal_thread(struct evl_condvar *cv,
int evl_signal_thread(struct evl_event *evt,
int thrfd);
int evl_broadcast(struct evl_condvar *cv);
int evl_broadcast_event(struct evl_event *evt);
int evl_close_condvar(struct evl_condvar *cv);
int evl_close_event(struct evl_event *evt);
#ifdef __cplusplus
}
#endif
#endif /* _EVL_CONDVAR_H */
#endif /* _EVL_EVENT_H */
......@@ -10,7 +10,7 @@
#include <signal.h>
#include <evl/clock.h>
#include <evl/mutex.h>
#include <evl/condvar.h>
#include <evl/event.h>
#include <evl/sem.h>
#include <evl/syscall.h>
#include <evl/thread.h>
......@@ -19,7 +19,7 @@
#include <evl/proxy.h>
#include <evl/utils.h>
#define __EVL__ 0 /* API revision */
#define __EVL__ 1 /* API revision */
#ifdef __cplusplus
extern "C" {
......
......@@ -51,7 +51,7 @@ int evl_new_flags(struct evl_flags *flg,
const char *fmt, ...);
int evl_open_flags(struct evl_flags *flg,
const char *fmt, ...);
const char *fmt, ...);
int evl_close_flags(struct evl_flags *flg);
......
......@@ -71,14 +71,14 @@ int evl_new_mutex_ceiling(struct evl_mutex *mutex,
int evl_open_mutex(struct evl_mutex *mutex,
const char *fmt, ...);
int evl_lock(struct evl_mutex *mutex);
int evl_lock_mutex(struct evl_mutex *mutex);
int evl_timedlock(struct evl_mutex *mutex,
const struct timespec *timeout);
int evl_timedlock_mutex(struct evl_mutex *mutex,
const struct timespec *timeout);
int evl_trylock(struct evl_mutex *mutex);
int evl_trylock_mutex(struct evl_mutex *mutex);
int evl_unlock(struct evl_mutex *mutex);
int evl_unlock_mutex(struct evl_mutex *mutex);
int evl_set_mutex_ceiling(struct evl_mutex *mutex,
unsigned int ceiling);
......
......@@ -55,16 +55,16 @@ int evl_open_sem(struct evl_sem *sem,
int evl_close_sem(struct evl_sem *sem);
int evl_get(struct evl_sem *sem);
int evl_get_sem(struct evl_sem *sem);
int evl_timedget(struct evl_sem *sem,
int evl_timedget_sem(struct evl_sem *sem,
const struct timespec *timeout);
int evl_put(struct evl_sem *sem);
int evl_put_sem(struct evl_sem *sem);
int evl_tryget(struct evl_sem *sem);
int evl_tryget_sem(struct evl_sem *sem);
int evl_getval(struct evl_sem *sem);
int evl_peek_sem(struct evl_sem *sem);
#ifdef __cplusplus
}
......
......@@ -18,7 +18,7 @@
#include <sched.h>
#include <evl/evl.h>
#include <evl/mutex.h>
#include <evl/condvar.h>
#include <evl/event.h>
#include <evl/thread.h>
#include <evl/syscall.h>
#include <linux/types.h>
......@@ -26,10 +26,10 @@
#include <uapi/evl/mutex.h>
#include "internal.h"
#define __CONDVAR_ACTIVE_MAGIC 0xef55ef55
#define __CONDVAR_DEAD_MAGIC 0
#define __EVENT_ACTIVE_MAGIC 0xef55ef55
#define __EVENT_DEAD_MAGIC 0
static int init_condvar_vargs(struct evl_condvar *cv,
static int init_event_vargs(struct evl_event *evt,
int clockfd, const char *fmt, va_list ap)
{
struct evl_monitor_attrs attrs;
......@@ -53,28 +53,28 @@ static int init_condvar_vargs(struct evl_condvar *cv,
if (efd < 0)
return efd;
cv->active.state = evl_shared_memory + eids.state_offset;
cv->active.fundle = eids.fundle;
cv->active.efd = efd;
cv->magic = __CONDVAR_ACTIVE_MAGIC;
evt->active.state = evl_shared_memory + eids.state_offset;
evt->active.fundle = eids.fundle;
evt->active.efd = efd;
evt->magic = __EVENT_ACTIVE_MAGIC;
return 0;
}
static int init_condvar(struct evl_condvar *cv,
int clockfd, const char *fmt, ...)
static int init_event(struct evl_event *evt,
int clockfd, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = init_condvar_vargs(cv, clockfd, fmt, ap);
ret = init_event_vargs(evt, clockfd, fmt, ap);
va_end(ap);
return ret;
}
static int open_condvar_vargs(struct evl_condvar *cv,
static int open_event_vargs(struct evl_event *evt,
const char *fmt, va_list ap)
{
struct evl_monitor_binding bind;
......@@ -96,10 +96,10 @@ static int open_condvar_vargs(struct evl_condvar *cv,
goto fail;
}
cv->active.state = evl_shared_memory + bind.eids.state_offset;
cv->active.fundle = bind.eids.fundle;
cv->active.efd = efd;
cv->magic = __CONDVAR_ACTIVE_MAGIC;
evt->active.state = evl_shared_memory + bind.eids.state_offset;
evt->active.fundle = bind.eids.fundle;
evt->active.efd = efd;
evt->magic = __EVENT_ACTIVE_MAGIC;
return 0;
fail:
......@@ -108,73 +108,73 @@ fail:
return ret;
}
int evl_new_condvar(struct evl_condvar *cv,
int evl_new_event(struct evl_event *evt,
int clockfd, const char *fmt, ...)
{
va_list ap;
int ret;
va_start(ap, fmt);
ret = init_condvar_vargs(cv, clockfd, fmt, ap);
ret = init_event_vargs(evt, clockfd, fmt, ap);
va_end(ap);
return ret;
}
int evl_open_condvar(struct evl_condvar *cv, const char *fmt, ...)
int evl_open_event(struct evl_event *evt, const char *fmt, ...)
{
va_list ap;
int efd;
va_start(ap, fmt);
efd = open_condvar_vargs(cv, fmt, ap);
efd = open_event_vargs(evt, fmt, ap);
va_end(ap);
return efd;
}
int evl_close_condvar(struct evl_condvar *cv)
int evl_close_event(struct evl_event *evt)
{
int efd;
if (cv->magic == __CONDVAR_UNINIT_MAGIC)
if (evt->magic == __EVENT_UNINIT_MAGIC)
return 0;
if (cv->magic != __CONDVAR_ACTIVE_MAGIC)
if (evt->magic != __EVENT_ACTIVE_MAGIC)
return -EINVAL;
efd = cv->active.efd;
cv->active.efd = -1;
efd = evt->active.efd;
evt->active.efd = -1;
compiler_barrier();
close(efd);
cv->active.fundle = EVL_NO_HANDLE;
cv->active.state = NULL;
cv->magic = __CONDVAR_DEAD_MAGIC;
evt->active.fundle = EVL_NO_HANDLE;
evt->active.state = NULL;
evt->magic = __EVENT_DEAD_MAGIC;
return 0;
}
static int check_condvar_sanity(struct evl_condvar *cv)
static int check_event_sanity(struct evl_event *evt)
{
int ret;
if (cv->magic == __CONDVAR_UNINIT_MAGIC) {
ret = init_condvar(cv, cv->uninit.clockfd, cv->uninit.name);
if (evt->magic == __EVENT_UNINIT_MAGIC) {
ret = init_event(evt, evt->uninit.clockfd, evt->uninit.name);
if (ret)
return ret;
} else if (cv->magic != __CONDVAR_ACTIVE_MAGIC)
} else if (evt->magic != __EVENT_ACTIVE_MAGIC)
return -EINVAL;
return 0;
}
static struct evl_monitor_state *get_lock_state(struct evl_condvar *cv)
static struct evl_monitor_state *get_lock_state(struct evl_event *evt)
{
struct evl_monitor_state *est = cv->active.state;
struct evl_monitor_state *est = evt->active.state;
if (est->u.event.gate_offset == EVL_MONITOR_NOGATE)
return NULL; /* Nobody waits on @cv */
return NULL; /* Nobody waits on @evt */
return evl_shared_memory + est->u.event.gate_offset;
}
......@@ -184,7 +184,7 @@ struct unwait_data {
int efd;
};
static void unwait_condvar(void *data)
static void unwait_event(void *data)
{
struct unwait_data *unwait = data;
int ret;
......@@ -195,15 +195,15 @@ static void unwait_condvar(void *data)
while (ret && errno == EINTR);
}
int evl_timedwait(struct evl_condvar *cv,
struct evl_mutex *mutex,
const struct timespec *timeout)
int evl_timedwait_event(struct evl_event *evt,
struct evl_mutex *mutex,
const struct timespec *timeout)
{
struct evl_monitor_waitreq req;
struct unwait_data unwait;
int ret, old_type;
ret = check_condvar_sanity(cv);
ret = check_event_sanity(evt);
if (ret)
return ret;
......@@ -212,89 +212,89 @@ int evl_timedwait(struct evl_condvar *cv,
req.status = -EINVAL;
req.value = 0; /* dummy */
unwait.ureq.gatefd = req.gatefd;
unwait.efd = cv->active.efd;
unwait.efd = evt->active.efd;
pthread_cleanup_push(unwait_condvar, &unwait);
pthread_cleanup_push(unwait_event, &unwait);
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &old_type);
ret = oob_ioctl(cv->active.efd, EVL_MONIOC_WAIT, &req);
ret = oob_ioctl(evt->active.efd, EVL_MONIOC_WAIT, &req);
pthread_setcanceltype(old_type, NULL);
pthread_cleanup_pop(0);
/*
* If oob_ioctl() failed with EINTR, we got forcibly unblocked
* while waiting for the condvar or trying to reacquire the lock
* while waiting for the event or trying to reacquire the lock
* afterwards, in which case the mutex was left
* unlocked. Issue UNWAIT to recover from that situation.
*/
if (ret && errno == EINTR) {
unwait_condvar(&unwait);
unwait_event(&unwait);
pthread_testcancel();
}
return ret ? -errno : req.status;
}
int evl_wait(struct evl_condvar *cv, struct evl_mutex *mutex)
int evl_wait_event(struct evl_event *evt, struct evl_mutex *mutex)
{
struct timespec timeout = { .tv_sec = 0, .tv_nsec = 0 };
return evl_timedwait(cv, mutex, &timeout);
return evl_timedwait_event(evt, mutex, &timeout);
}
int evl_signal(struct evl_condvar *cv)
int evl_signal_event(struct evl_event *evt)
{
struct evl_monitor_state *est, *gst;
int ret;
ret = check_condvar_sanity(cv);
ret = check_event_sanity(evt);
if (ret)
return ret;
gst = get_lock_state(cv);
gst = get_lock_state(evt);
if (gst) {
gst->flags |= EVL_MONITOR_SIGNALED;
est = cv->active.state;
est = evt->active.state;
est->flags |= EVL_MONITOR_SIGNALED;
}
return 0;
}
int evl_signal_thread(struct evl_condvar *cv, int thrfd)
int evl_signal_thread(struct evl_event *evt, int thrfd)
{
struct evl_monitor_state *gst;
__u32 efd;
int ret;
ret = check_condvar_sanity(cv);
ret = check_event_sanity(evt);
if (ret)
return ret;
gst = get_lock_state(cv);
gst = get_lock_state(evt);
if (gst) {
gst->flags |= EVL_MONITOR_SIGNALED;
efd = cv->active.efd;
efd = evt->active.efd;
return oob_ioctl(thrfd, EVL_THRIOC_SIGNAL, &efd) ? -errno : 0;
}
/* No thread waits on @cv, so @thrfd neither => nop. */
/* No thread waits on @evt, so @thrfd neither => nop. */
return 0;
}
int evl_broadcast(struct evl_condvar *cv)
int evl_broadcast_event(struct evl_event *evt)
{
struct evl_monitor_state *est, *gst;
int ret;
ret = check_condvar_sanity(cv);
ret = check_event_sanity(evt);
if (ret)
return ret;
gst = get_lock_state(cv);
gst = get_lock_state(evt);
if (gst) {
gst->flags |= EVL_MONITOR_SIGNALED;
est = cv->active.state;
est = evt->active.state;
est->flags |= EVL_MONITOR_SIGNALED|EVL_MONITOR_BROADCAST;
}
......
......@@ -122,9 +122,9 @@ static int check_sanity(struct evl_flags *flg)
{
if (flg->magic == __FLAGS_UNINIT_MAGIC)
return evl_new_flags(flg,
flg->uninit.clockfd,
flg->uninit.initval,
flg->uninit.name);
flg->uninit.clockfd,
flg->uninit.initval,
flg->uninit.name);
return flg->magic != __FLAGS_ACTIVE_MAGIC ? -EINVAL : 0;
}
......
......@@ -96,7 +96,7 @@ static inline int generic_init(void)
goto fail;
shmem = mmap(NULL, core_info.shm_size, PROT_READ|PROT_WRITE,
MAP_SHARED, ctlfd, 0);
MAP_SHARED, ctlfd, 0);
if (shmem == MAP_FAILED) {
ret = -errno;
goto fail;
......@@ -115,7 +115,7 @@ fail:
int evl_sigevl_handler(int sig, siginfo_t *si, void *ctxt)
{
if (si->si_code == SI_QUEUE &&
sigevl_action(si->si_int) == SIGEVL_ACTION_HOME) {
sigevl_action(si->si_int) == SIGEVL_ACTION_HOME) {
oob_ioctl(evl_efd, EVL_THRIOC_SWITCH_OOB);
return 1;
}
......@@ -170,7 +170,7 @@ static void sigevl_handler(int sig, siginfo_t *si, void *ctxt)
return;
if ((!(sa->sa_flags & SA_SIGINFO) && sa->sa_handler == NULL) ||
((sa->sa_flags & SA_SIGINFO) && sa->sa_sigaction == NULL))
((sa->sa_flags & SA_SIGINFO) && sa->sa_sigaction == NULL))
return; /* Not sent by the EVL core */
pthread_sigmask(SIG_SETMASK, &sa->sa_mask, &omask);
......
......@@ -30,7 +30,7 @@
* an element causes its automatic deletion.
*/
int create_evl_element(const char *type, const char *name,
void *attrs, struct evl_element_ids *eids)
void *attrs, struct evl_element_ids *eids)
{
struct evl_clone_req clone;
char *fdevname, *edevname;
......
......@@ -79,8 +79,8 @@ static int init_mutex_vargs(struct evl_mutex *mutex,
}
static int init_mutex(struct evl_mutex *mutex,
int protocol, int clockfd, unsigned int ceiling,
const char *fmt, ...)
int protocol, int clockfd, unsigned int ceiling,
const char *fmt, ...)
{
va_list ap;
int ret;
......@@ -253,8 +253,8 @@ static int try_lock(struct evl_mutex *mutex)
return -ENODATA;
}
int evl_timedlock(struct evl_mutex *mutex,
const struct timespec *timeout)
int evl_timedlock_mutex(struct evl_mutex *mutex,
const struct timespec *timeout)
{
struct evl_monitor_lockreq lreq;
int ret, cancel_type;
......@@ -276,14 +276,14 @@ int evl_timedlock(struct evl_mutex *mutex,
return ret ? -errno : 0;
}
int evl_lock(struct evl_mutex *mutex)
int evl_lock_mutex(struct evl_mutex *mutex)
{
struct timespec timeout = { .tv_sec = 0, .tv_nsec = 0 };
return evl_timedlock(mutex, &timeout);
return evl_timedlock_mutex(mutex, &timeout);
}
int evl_trylock(struct evl_mutex *mutex)
int evl_trylock_mutex(struct evl_mutex *mutex)
{
int ret;
......@@ -298,7 +298,7 @@ int evl_trylock(struct evl_mutex *mutex)
return ret ? -errno : 0;
}
int evl_unlock(struct evl_mutex *mutex)
int evl_unlock_mutex(struct evl_mutex *mutex)
{
struct evl_user_window *u_window;
struct evl_monitor_state *gst;
......@@ -313,7 +313,7 @@ int evl_unlock(struct evl_mutex *mutex)
if (!evl_is_mutex_owner(&gst->u.gate.owner, current))
return -EPERM;
/* Do we have waiters on a signaled condvar we are gating? */
/* Do we have waiters on a signaled event we are gating? */
if (gst->flags & EVL_MONITOR_SIGNALED)
goto slow_path;
......
......@@ -122,9 +122,9 @@ static int check_sanity(struct evl_sem *sem)
{
if (sem->magic == __SEM_UNINIT_MAGIC)
return evl_new_sem(sem,
sem->uninit.clockfd,
sem->uninit.initval,
sem->uninit.name);
sem->uninit.clockfd,
sem->uninit.initval,
sem->uninit.name);
return sem->magic != __SEM_ACTIVE_MAGIC ? -EINVAL : 0;
}
......@@ -160,7 +160,7 @@ static int try_get(struct evl_monitor_state *state)
return 0;
}
int evl_timedget(struct evl_sem *sem, const struct timespec *timeout)
int evl_timedget_sem(struct evl_sem *sem, const struct timespec *timeout)
{
struct evl_monitor_state *state;
struct evl_monitor_waitreq req;
......@@ -199,14 +199,14 @@ int evl_timedget(struct evl_sem *sem, const struct timespec *timeout)
return ret ? -errno : req.status;
}
int evl_get(struct evl_sem *sem)
int evl_get_sem(struct evl_sem *sem)
{
struct timespec timeout = { .tv_sec = 0, .tv_nsec = 0 };
return evl_timedget(sem, &timeout);
return evl_timedget_sem(sem, &timeout);
}
int evl_tryget(struct evl_sem *sem)
int evl_tryget_sem(struct evl_sem *sem)
{
int ret;
......@@ -217,7 +217,7 @@ int evl_tryget(struct evl_sem *sem)
return try_get(sem->active.state);
}
int evl_put(struct evl_sem *sem)
int evl_put_sem(struct evl_sem *sem)
{
struct evl_monitor_state *state;
int val, prev, next, ret;
......@@ -250,7 +250,7 @@ int evl_put(struct evl_sem *sem)
return 0;
}
int evl_getval(struct evl_sem *sem)
int evl_peek_sem(struct evl_sem *sem)
{
if (sem->magic != __SEM_ACTIVE_MAGIC)
return -EINVAL;
......
......@@ -12,7 +12,7 @@
#include "internal.h"
int evl_new_xbuf(size_t i_bufsz, size_t o_bufsz,
const char *fmt, ...)
const char *fmt, ...)
{