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

lib/thread: add services to set/clear thread mode bits



Open-coding oob_ioctl() calls to set/clear mode bits in apps is
unhandy and fairly ugly. Let's provide sanctioned services for these
requests, namely evl_set_thread_mode() and evl_clear_thread_mode()
respectively.
Signed-off-by: default avatarPhilippe Gerum <rpm@xenomai.org>
parent 9922efa2
......@@ -20,7 +20,7 @@
#include <evl/poll.h>
#include <evl/proxy.h>
#define __EVL__ 14 /* API version */
#define __EVL__ 15 /* API version */
#define EVL_ABI_PREREQ 21
......
......@@ -70,6 +70,12 @@ int evl_unblock_thread(int efd);
int evl_demote_thread(int efd);
int evl_set_thread_mode(int efd, int mask,
int *oldmask);
int evl_clear_thread_mode(int efd, int mask,
int *oldmask);
#ifdef __cplusplus
}
#endif
......
......@@ -209,3 +209,28 @@ int evl_demote_thread(int efd)
{
return __evl_common_ioctl(efd, EVL_THRIOC_DEMOTE);
}
static int do_thread_mode(int efd, int op, int mask, int *oldmask)
{
__u32 val = mask;
int ret;
ret = __evl_common_ioctl(efd, op, &val);
if (ret)
return ret;
if (oldmask)
*oldmask = val;
return 0;
}
int evl_set_thread_mode(int efd, int mask, int *oldmask)
{
return do_thread_mode(efd, EVL_THRIOC_SET_MODE, mask, oldmask);
}
int evl_clear_thread_mode(int efd, int mask, int *oldmask)
{
return do_thread_mode(efd, EVL_THRIOC_CLEAR_MODE, mask, oldmask);
}
......@@ -13,10 +13,17 @@ int main(int argc, char *argv[])
int tfd;
tfd = evl_attach_self("test");
tfd = evl_attach_thread(EVL_CLONE_PUBLIC, "test");
evl_detach_self();
evl_detach_thread(0);
evl_get_self();
evl_switch_oob();
evl_switch_inband();
evl_get_state(tfd, &statebuf);
evl_unblock_thread(tfd);
evl_demote_thread(tfd);
evl_set_thread_mode(tfd, 0, NULL);
evl_clear_thread_mode(tfd, 0, NULL);
return 0;
}
/*
* SPDX-License-Identifier: MIT
*/
#include <sys/types.h>
#include <stdbool.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <evl/thread.h>
#include "helpers.h"
int main(int argc, char *argv[])
{
struct sched_param param;
int tfd, ret;
int oldmask;
param.sched_priority = 1;
__Texpr_assert(pthread_setschedparam(pthread_self(),
SCHED_FIFO, &param) == 0);
__Tcall_assert(tfd, evl_attach_self("thread-mode-bits:%d", getpid()));
/* Starts with no mode bit set. */
__Tcall_assert(ret, evl_set_thread_mode(tfd, T_WOSS|T_WOLI|T_WOSX, &oldmask));
__Texpr_assert(oldmask == 0);
__Tcall_assert(ret, evl_set_thread_mode(tfd, 0, &oldmask));
__Texpr_assert(oldmask == (T_WOSS|T_WOLI|T_WOSX));
__Tcall_assert(ret, evl_clear_thread_mode(tfd, T_WOSS, &oldmask));
__Texpr_assert(oldmask == (T_WOSS|T_WOLI|T_WOSX));
__Tcall_assert(ret, evl_clear_thread_mode(tfd, T_WOLI|T_WOSX, &oldmask));
__Texpr_assert(oldmask == (T_WOLI|T_WOSX));
__Tcall_assert(ret, evl_set_thread_mode(tfd, 0, &oldmask));
__Texpr_assert(oldmask == 0);
__Tcall_assert(ret, evl_set_thread_mode(tfd, 0, NULL));
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment