* Thread attributes
*************************/
+static inline int __fosa_check_thread(const fosa_thread_id_t *tid)
+{
+ if (tid->linux_pid == tid->linux_tid)
+ return 0;
+
+ return 1;
+}
+
/**
* fosa_thread_attr_init()
*
**/
int fosa_thread_attr_init(fosa_thread_attr_t *attr)
{
- fosa_thread_id_t self;
-
- /* only POSIX threads have attributes */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
- return EINVAL;
-
return pthread_attr_init(attr);
}
**/
int fosa_thread_attr_destroy(fosa_thread_attr_t *attr)
{
- fosa_thread_id_t self;
-
- /* only POSIX threads can have attributes */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
- return EINVAL;
-
return pthread_attr_destroy(attr);
}
int fosa_thread_attr_set_stacksize(fosa_thread_attr_t *attr,
size_t stacksize)
{
- fosa_thread_id_t self;
-
- /* only POSIX threads can set the size of the stack */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
- return EINVAL;
-
return pthread_attr_setstacksize(attr, stacksize);
}
int fosa_thread_attr_get_stacksize(const fosa_thread_attr_t *attr,
size_t *stacksize)
{
- fosa_thread_id_t self;
-
- /* only POSIX threads can set the size of the stack */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
- return EINVAL;
-
return pthread_attr_getstacksize(attr, stacksize);
}
{
int i, error = 0;
bool found = false;
- fosa_thread_id_t self;
-
- /* only POSIX threads can have specific data */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
- return EINVAL;
if ((error = pthread_mutex_lock(&key_lock)) != 0)
return error;
int fosa_key_destroy(int key)
{
int error;
- fosa_thread_id_t self;
-
- /* only POSIX threads can have specific data */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
- return EINVAL;
if ((error = pthread_mutex_lock(&key_lock)) != 0)
return error;
fosa_thread_id_t tid,
const void * value)
{
- fosa_thread_id_t self;
-
/* only POSIX threads can have specific data */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
+ if (!__fosa_check_thread(&tid))
return EINVAL;
return pthread_setspecific(key_list[key], value);
fosa_thread_id_t tid,
void ** value)
{
- fosa_thread_id_t self;
-
/* only POSIX threads can have specific data */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
+ if (!__fosa_check_thread(&tid))
return EINVAL;
if ((value = pthread_getspecific(key_list[key])) != NULL)
int fosa_thread_attr_set_prio(fosa_thread_attr_t *attr, int prio)
{
int error;
- fosa_thread_id_t self;
struct sched_param param;
- /* normal UNIX processes have no attributes */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
- return EINVAL;
-
param.sched_priority = prio;
if ((error = pthread_attr_setschedpolicy(attr, SCHED_RR)) == 0)
return error;
int fosa_thread_attr_get_prio(const fosa_thread_attr_t *attr, int *prio)
{
int error;
- fosa_thread_id_t self;
struct sched_param param;
- /* normal UNIX processes have no attributes */
- self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
- return EINVAL;
-
if ((error = pthread_attr_getschedparam(attr, ¶m)) == 0)
*prio = param.sched_priority;
{
struct sched_param param;
- param.sched_priority=prio;
-
+ param.sched_priority = prio;
return sched_setscheduler(0, SCHED_RR, ¶m);
}
int fosa_thread_get_prio(fosa_thread_id_t tid, int *prio)
{
struct sched_param param;
- int error;
+ int ret;
- error = sched_getparam(0, ¶m);
+ ret = sched_getparam(0, ¶m);
*prio = param.sched_priority;
- return error;
+ return ret;
}
/*******************************************************************
}
self = fosa_thread_self();
- if (self.linux_pid == self.linux_tid)
+ if (__fosa_check_thread(&self))
return pthread_sigmask(SIG_BLOCK, &sigset, NULL);
else
return sigprocmask(SIG_BLOCK, &sigset, NULL);