18#ifndef _BOILERPLATE_LIBC_H
19#define _BOILERPLATE_LIBC_H
30#include <xeno_config.h>
32#include <boilerplate/compiler.h>
34#if !HAVE_DECL_PTHREAD_PRIO_NONE
43static inline int fork(
void)
50#ifndef HAVE_PTHREAD_ATFORK
53int pthread_atfork(
void (*prepare)(
void),
void (*parent)(
void),
59#error "fork() without pthread_atfork()"
63#ifndef HAVE_PTHREAD_GETATTR_NP
65int pthread_getattr_np(pthread_t th, pthread_attr_t *attr)
71#ifndef HAVE_PTHREAD_CONDATTR_SETCLOCK
76 return clock_id == CLOCK_REALTIME ? 0 : ENOSYS;
80#ifndef HAVE_PTHREAD_CONDATTR_GETCLOCK
83 clockid_t *__restrict__ clock_id)
85 *clock_id = CLOCK_REALTIME;
91#ifndef HAVE_PTHREAD_MUTEXATTR_SETPROTOCOL
96 return protocol == PTHREAD_PRIO_NONE ? 0 : ENOSYS;
100#ifndef HAVE_PTHREAD_MUTEXATTR_GETPROTOCOL
103 __restrict__ attr,
int *__restrict__ protocol)
105 *protocol = PTHREAD_PRIO_NONE;
111#ifndef HAVE_PTHREAD_MUTEXATTR_SETPRIOCEILING
113int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *attr,
120#ifndef HAVE_PTHREAD_MUTEXATTR_GETPRIOCEILING
122int pthread_mutexattr_getprioceiling(
const pthread_mutexattr_t *
124 int *__restrict prioceiling)
130#ifndef HAVE_PTHREAD_MUTEX_SETPRIOCEILING
134 int *__restrict old_ceiling)
140#ifndef HAVE_PTHREAD_MUTEX_GETPRIOCEILING
143 int *__restrict prioceiling)
149#ifndef HAVE_PTHREAD_ATTR_SETAFFINITY_NP
152int pthread_attr_setaffinity_np(pthread_attr_t *attr,
153 size_t cpusetsize,
const cpu_set_t *cpuset)
155 if (CPU_ISSET(0, cpuset) && CPU_COUNT(cpuset) == 1)
161#ifndef HAVE_PTHREAD_SETAFFINITY_NP
163int pthread_setaffinity_np(pthread_t thread,
size_t cpusetsize,
164 const cpu_set_t *cpuset)
166 if (CPU_ISSET(0, cpuset) && CPU_COUNT(cpuset) == 1)
172#ifndef HAVE_PTHREAD_SETSCHEDPRIO
175int pthread_setschedprio(pthread_t thread,
int prio)
177 struct sched_param param;
180 ret = pthread_getschedparam(thread, &policy, ¶m);
184 param.sched_priority = prio;
191#if !defined(HAVE_CLOCK_NANOSLEEP) && defined(CONFIG_XENO_MERCURY)
198__weak
int clock_nanosleep(clockid_t clock_id,
int flags,
199 const struct timespec *request,
200 struct timespec *remain)
202 struct timespec now, tmp;
206 clock_gettime(CLOCK_REALTIME, &now);
207 tmp.tv_sec -= now.tv_sec;
208 tmp.tv_nsec -= now.tv_nsec;
209 if (tmp.tv_nsec < 0) {
211 tmp.tv_nsec += 1000000000;
215 return nanosleep(&tmp, remain);
219#ifndef HAVE_SCHED_GETCPU
224__weak
int sched_getcpu(
void)
231__weak
int shm_open(
const char *name,
int oflag, mode_t mode)
238#ifndef HAVE_SHM_UNLINK
239__weak
int shm_unlink(
const char *name)
246#ifndef HAVE_PTHREAD_MUTEXATTR_SETROBUST
247#ifdef HAVE_PTHREAD_MUTEXATTR_SETROBUST_NP
248#define pthread_mutexattr_setrobust pthread_mutexattr_setrobust_np
251int pthread_mutexattr_setrobust(pthread_mutexattr_t *attr,
259#if !defined(HAVE_PTHREAD_SETNAME_NP) && defined(CONFIG_XENO_MERCURY)
269#if defined(__COBALT_WRAP__) || defined(__IN_XENO__)
275#ifndef HAVE_CLOCK_NANOSLEEP
276int clock_nanosleep(clockid_t clock_id,
int flags,
277 const struct timespec *request,
278 struct timespec *remain);
281#ifndef HAVE_PTHREAD_SETNAME_NP
286#ifndef PTHREAD_STACK_DEFAULT
287#define PTHREAD_STACK_DEFAULT \
289 int __ret = PTHREAD_STACK_MIN; \
int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clk_id)
Set the clock selection attribute of a condition variable attributes object.
int pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clk_id)
Get the clock selection attribute from a condition variable attributes object.
int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict mutex, int prioceiling, int *__restrict old_ceiling))
Set a mutex's priority ceiling.
Definition mutex.c:741
int pthread_mutex_getprioceiling(pthread_mutex_t *__restrict mutex, int *__restrict old_ceiling))
Get a mutex's priority ceiling.
Definition mutex.c:792
int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *attr, int *proto)
Get the protocol attribute from a mutex attributes object.
int pthread_mutexattr_setprotocol(pthread_mutexattr_t *attr, int proto)
Set the protocol attribute of a mutex attributes object.
int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param))
Set the scheduling policy and parameters of the specified thread.
Definition thread.c:540
int pthread_setname_np(pthread_t thread, const char *name))
Set a thread name.
Definition thread.c:403