int pthread_attr_setschedpolicy ( pthread_attr_t *attr, int policy ) { ASSERT_ERRNO_AND_RETURN ( attr, EINVAL ); ASSERT_ERRNO_AND_RETURN ( policy >= 0 && policy < SCHED_NUM, EINVAL ); attr->sched_policy = policy; return EXIT_SUCCESS; }
int pthread_attr_setschedpolicy ( pthread_attr_t *attr, int policy ) { ASSERT_ERRNO_AND_RETURN ( attr, EINVAL ); ASSERT_ERRNO_AND_RETURN ( policy == SCHED_FIFO, ENOTSUP ); attr->sched_policy = policy; return EXIT_SUCCESS; }
int pthread_attr_setschedparam ( pthread_attr_t *attr, struct sched_param *param ) { ASSERT_ERRNO_AND_RETURN ( attr && param, EINVAL ); ASSERT_ERRNO_AND_RETURN ( param->sched_priority >= THREAD_MIN_PRIO && param->sched_priority <= THREAD_MAX_PRIO, EINVAL ); attr->sched_params = *param; return EXIT_SUCCESS; }
/*! Set thread scheduling parameters */ int pthread_setschedparam ( pthread_t thread, int policy, struct sched_param *param ) { ASSERT_ERRNO_AND_RETURN ( policy == SCHED_FIFO, ENOTSUP ); if ( param ) ASSERT_ERRNO_AND_RETURN ( param->sched_priority >= THREAD_MIN_PRIO && param->sched_priority <= THREAD_MAX_PRIO, EINVAL ); return sys__pthread_setschedparam ( &thread, policy, param ); }
/*! * Create new timer * \param clockid Clock used in timer * \param evp Timer expiration action * \param timerid Timer descriptor is returned in this variable * \return status 0 for success */ int timer_create ( clockid_t clockid, sigevent_t *evp, timer_t *timer ) { ASSERT_ERRNO_AND_RETURN ( evp && timer && ( clockid == CLOCK_REALTIME || clockid == CLOCK_MONOTONIC ), EINVAL ); return syscall ( TIMER_CREATE, clockid, evp, timer ); }
int debug () { int a, b, c; printf ( "Example program: [%s:%s]\n%s\n\n", __FILE__, __FUNCTION__, debug_PROG_HELP ); a = 1; b = a + 1; c = inc ( a ) + inc ( b ); a += b + c; b += a + c; c += a + b; printf ( "a=%d, b=%d, c=%d\n", a, b, c ); #if 1 /* compile with 'debug=yes' and without */ LOG ( WARN, "This is log entry with WARN relevance" ); LOG ( INFO, "Address of 'a' is %x", &a ); ASSERT_ERRNO_AND_RETURN ( TRUE, EINVAL ); ASSERT ( TRUE ); //ASSERT ( FALSE ); #endif return 0; }
/*! * Arm/disarm timer * \param timerid Timer descriptor (user descriptor) * \param flags Various flags (TIMER_ABSTIME) * \param value Set timer values (it_value+it_period) * \param ovalue Where to store time to next timer expiration (+period) * \return status 0 for success */ int timer_settime ( timer_t *timer, int flags, itimerspec_t *value, itimerspec_t *ovalue ) { ASSERT_ERRNO_AND_RETURN ( timer, EINVAL ); return syscall ( TIMER_SETTIME, timer, flags, value, ovalue ); }
/*! * Set current time * \param clockid Clock to use * \param time Time to set * \return status */ int clock_settime ( clockid_t clockid, timespec_t *time ) { ASSERT_ERRNO_AND_RETURN ( time && ( clockid == CLOCK_REALTIME || clockid == CLOCK_MONOTONIC ), EINVAL ); return syscall ( CLOCK_SETTIME, clockid, time ); }
int pthread_create ( pthread_t *thread, pthread_attr_t *attr, void *(*start_routine) (void *), void *arg ) { ASSERT_ERRNO_AND_RETURN ( start_routine, EINVAL ); return sys__pthread_create ( thread, attr, start_routine, arg ); }
/*! * Suspend thread until given time elapses * \param clockid Clock to use * \param flags Flags (TIMER_ABSTIME) * \param request Suspend duration * \param remain Remainder time if interrupted during suspension * \return status */ int clock_nanosleep ( clockid_t clockid, int flags, timespec_t *request, timespec_t *remain ) { ASSERT_ERRNO_AND_RETURN ( request && ( clockid == CLOCK_REALTIME || clockid == CLOCK_MONOTONIC ), EINVAL ); return syscall ( CLOCK_NANOSLEEP, clockid, flags, request, remain ); }
int send_message ( int dest_type, void *dest, msg_t *msg, uint flags ) { int retval; ASSERT_ERRNO_AND_RETURN ( dest, E_INVALID_ARGUMENT ); do { retval = syscall ( SEND_MESG, dest_type, dest, msg, flags ); } while ( retval == -E_RETRY && ( flags & IPC_WAIT ) ); return retval; }
/*! * Delay thread until given time is reached (passes) * Given time is compared by system time * \param t Expiration time * \return 0 */ int delay_until ( time_t *t ) { void *id; ASSERT_ERRNO_AND_RETURN ( t, E_INVALID_ARGUMENT ); id = alarm_set ( NULL, t, NULL, NULL, NULL, IPC_WAIT ); alarm_remove ( id ); return 0; }
int pthread_attr_init ( pthread_attr_t *attr ) { ASSERT_ERRNO_AND_RETURN ( attr, EINVAL ); attr->flags = PTHREAD_INHERIT_SCHED | PTHREAD_CREATE_JOINABLE | PTHREAD_SCOPE_SYSTEM; attr->sched_policy = SCHED_FIFO; attr->sched_params.sched_priority = THREAD_DEF_PRIO; attr->stackaddr = NULL; attr->stacksize = 0; return EXIT_SUCCESS; }
int receive_message ( int src_type, void *src, msg_t *msg, int type, size_t size, uint flags ) { int retval; ASSERT_ERRNO_AND_RETURN ( src, E_INVALID_ARGUMENT ); do { retval = syscall ( RECV_MESG, src_type, src, msg, type, size, flags ); } while ( retval == -E_RETRY && ( flags & IPC_WAIT ) ); return retval; }
/*! * Delay thread until given time period expires * \param t Expiration time * \return 0 */ int delay ( time_t *t ) { time_t aps; ASSERT_ERRNO_AND_RETURN ( t, E_INVALID_ARGUMENT ); time_get ( &aps ); aps.sec += t->sec; aps.nsec += t->nsec; if ( aps.nsec > 1000000000 ) { aps.nsec -= 1000000000; aps.sec++; } return delay_until ( &aps ); }
/*! * Modify thread signal mask * \param sig Signal number * \param act Signal handling behavior * \param oact Where to save old signal behavior * \return 0 if successful, -1 otherwise and appropriate error number is set */ int sigaction ( int sig, sigaction_t *act, sigaction_t *oact ) { ASSERT_ERRNO_AND_RETURN ( sig > 0 && sig <= SIGMAX, EINVAL ); return syscall ( SIGACTION, sig, act, oact ); }
int pthread_attr_destroy ( pthread_attr_t *attr ) { ASSERT_ERRNO_AND_RETURN ( attr, EINVAL ); return EXIT_SUCCESS; }
/*! * Wait for alarm to expire (activate) * \param alarm Alarm id (pointer) * \param wait Do thread really wait or not (just return status)? * \returns status (0 for success) */ int wait_for_alarm ( void *id, int wait ) { ASSERT_ERRNO_AND_RETURN ( id, E_INVALID_ARGUMENT ); return sys__wait_for_alarm ( id, wait ); }
int sem_init ( sem_t *sem, int initial_value ) { ASSERT_ERRNO_AND_RETURN ( sem, E_INVALID_ARGUMENT ); return syscall ( SEM_INIT, sem, initial_value ); }
int sem_wait ( sem_t *sem ) { ASSERT_ERRNO_AND_RETURN ( sem, E_INVALID_ARGUMENT ); return syscall ( SEM_WAIT, sem ); }
int sem_destroy ( sem_t *sem ) { ASSERT_ERRNO_AND_RETURN ( sem, E_INVALID_ARGUMENT ); return syscall ( SEM_DESTROY, sem ); }
/*! * Modify thread signal mask * \param how How to modify current mask * \param set Mask to use in modification * \param oset Where to store old mask * \return 0 if successful, -1 otherwise and appropriate error number is set */ int pthread_sigmask ( int how, sigset_t *set, sigset_t *oset ) { ASSERT_ERRNO_AND_RETURN ( set, EINVAL ); return syscall ( PTHREAD_SIGMASK, how, set, oset ); }
/*! * Wait for signal * \param set Signals thread is waiting for * \param info Where to save caught signal * \return signal number if signal is caught, * -1 otherwise and appropriate error number is set */ int sigwaitinfo ( sigset_t *set, siginfo_t *info ) { ASSERT_ERRNO_AND_RETURN ( set, EINVAL ); return syscall ( SIGWAITINFO, set, info ); }
/*! * Get current system time * \param t Pointer where to store time * \returns 0 if successful, -1 otherwise */ int time_get ( time_t *t ) { ASSERT_ERRNO_AND_RETURN ( t, E_INVALID_ARGUMENT ); return sys__get_time ( t ); }
/*! * Removes (deletes) alarm * \param id Pointer to alarm handle * \return 0 if successful, -1 otherwise */ int alarm_remove ( void *id ) { ASSERT_ERRNO_AND_RETURN ( id, E_INVALID_ARGUMENT ); return syscall ( ALARM_REMOVE, id ); }
/*! * Get alarm parameters * \param id Pointer to alarm handler * \param alarm Pointer where to store parameters * \return 0 if successful, -1 otherwise */ int alarm_get ( void *id, alarm_t *alarm ) { ASSERT_ERRNO_AND_RETURN ( id && alarm, E_INVALID_ARGUMENT ); return syscall ( ALARM_GET, id, alarm ); }
/*! * Wait for alarm to expire (activate) * \param alarm Alarm id (pointer) * \param wait Do thread really wait or not (just return status)? * \return status (0 for success) */ int wait_for_alarm ( void *id, int wait ) { ASSERT_ERRNO_AND_RETURN ( id, E_INVALID_ARGUMENT ); return syscall ( WAIT_FOR_ALARM, id, wait ); }
/*! * Get current system time * \param t Pointer where to store time * \return 0 if successful, -1 otherwise */ int time_get ( time_t *t ) { ASSERT_ERRNO_AND_RETURN ( t, E_INVALID_ARGUMENT ); return syscall ( GET_TIME, t ); }
/*! * Send signal to thread (from thread) * \param pid Thread descriptor (user level descriptor) * \param signo Signal number * \param sigval Parameter to send with signal * \return 0 if successful, -1 otherwise and appropriate error number is set */ int sigqueue ( pid_t pid, int signo, sigval_t sigval ) { ASSERT_ERRNO_AND_RETURN ( signo > 0 && signo <= SIGMAX, EINVAL ); return syscall ( SIGQUEUE, pid, signo, sigval ); }
/*! * Removes (deletes) alarm * \param id Pointer to alarm handle * \returns 0 if successful, -1 otherwise */ int alarm_remove ( void *id ) { ASSERT_ERRNO_AND_RETURN ( id, E_INVALID_ARGUMENT ); return sys__alarm_remove ( id ); }