use restrict everywhere it's required by c99 and/or posix 2008

to deal with the fact that the public headers may be used with pre-c99
compilers, __restrict is used in place of restrict, and defined
appropriately for any supported compiler. we also avoid the form
[restrict] since older versions of gcc rejected it due to a bug in the
original c99 standard, and instead use the form *restrict.
This commit is contained in:
Rich Felker 2012-09-06 22:44:55 -04:00
commit 400c5e5c83
192 changed files with 552 additions and 382 deletions

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_attr_getguardsize(const pthread_attr_t *a, size_t *size)
int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size)
{
*size = a->_a_guardsize + DEFAULT_GUARD_SIZE;
return 0;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_attr_getschedparam(const pthread_attr_t *a, struct sched_param *param)
int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param)
{
param->sched_priority = 0;
return 0;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_attr_getscope(const pthread_attr_t *a, int *scope)
int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope)
{
return 0;
}

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_attr_getstack(const pthread_attr_t *a, void **addr, size_t *size)
int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size)
{
if (!a->_a_stackaddr)
return EINVAL;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_attr_getstacksize(const pthread_attr_t *a, size_t *size)
int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size)
{
*size = a->_a_stacksize + DEFAULT_STACK_SIZE;
return 0;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_attr_setschedparam(pthread_attr_t *a, const struct sched_param *param)
int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param)
{
if (param->sched_priority) return ENOTSUP;
return 0;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_barrier_init(pthread_barrier_t *b, const pthread_barrierattr_t *a, unsigned count)
int pthread_barrier_init(pthread_barrier_t *restrict b, const pthread_barrierattr_t *restrict a, unsigned count)
{
if (count-1 > INT_MAX-1) return EINVAL;
*b = (pthread_barrier_t){ ._b_limit = count-1 | (a?*a:0) };

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *a, int *pshared)
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared)
{
*pshared = !!*a;
return 0;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_cond_init(pthread_cond_t *c, const pthread_condattr_t *a)
int pthread_cond_init(pthread_cond_t *restrict c, const pthread_condattr_t *restrict a)
{
memset(c, 0, sizeof *c);
if (a) {

View file

@ -36,7 +36,7 @@ static void cleanup(void *p)
pthread_mutex_lock(cm->m);
}
int pthread_cond_timedwait(pthread_cond_t *c, pthread_mutex_t *m, const struct timespec *ts)
int pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts)
{
struct cm cm = { .c=c, .m=m };
int r, e=0, seq;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m)
int pthread_cond_wait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m)
{
return pthread_cond_timedwait(c, m, 0);
}

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_condattr_getclock(const pthread_condattr_t *a, clockid_t *clk)
int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk)
{
*clk = *a & 0x7fffffff;
return 0;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_condattr_getpshared(const pthread_condattr_t *a, int *pshared)
int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared)
{
*pshared = *a>>31;
return 0;

View file

@ -84,7 +84,7 @@ static void init_file_lock(FILE *f)
if (f && f->lock<0) f->lock = 0;
}
int pthread_create(pthread_t *res, const pthread_attr_t *attr, void *(*entry)(void *), void *arg)
int pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attr, void *(*entry)(void *), void *restrict arg)
{
int ret;
size_t size = DEFAULT_STACK_SIZE + DEFAULT_GUARD_SIZE;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_mutex_init(pthread_mutex_t *m, const pthread_mutexattr_t *a)
int pthread_mutex_init(pthread_mutex_t *restrict m, const pthread_mutexattr_t *restrict a)
{
memset(m, 0, sizeof *m);
if (a) m->_m_type = *a & 7;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_mutex_timedlock(pthread_mutex_t *m, const struct timespec *at)
int pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at)
{
int r, t;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *a, int *pshared)
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared)
{
*pshared = *a>>31;
return 0;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_mutexattr_getrobust(const pthread_mutexattr_t *a, int *robust)
int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust)
{
*robust = *a / 4U % 2;
return 0;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_mutexattr_gettype(const pthread_mutexattr_t *a, int *type)
int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type)
{
*type = *a & 3;
return 0;

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_rwlock_init(pthread_rwlock_t *rw, const pthread_rwlockattr_t *a)
int pthread_rwlock_init(pthread_rwlock_t *restrict rw, const pthread_rwlockattr_t *restrict a)
{
memset(rw, 0, sizeof *rw);
if (a) {

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_rwlock_timedrdlock(pthread_rwlock_t *rw, const struct timespec *at)
int pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
{
int r, t;
while ((r=pthread_rwlock_tryrdlock(rw))==EBUSY) {

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_rwlock_timedwrlock(pthread_rwlock_t *rw, const struct timespec *at)
int pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at)
{
int r, t;
while ((r=pthread_rwlock_trywrlock(rw))==EBUSY) {

View file

@ -1,6 +1,6 @@
#include "pthread_impl.h"
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *a, int *pshared)
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared)
{
*pshared = *(int *)a;
return 0;

View file

@ -3,7 +3,7 @@
#include <pthread.h>
#include "syscall.h"
int pthread_sigmask(int how, const sigset_t *set, sigset_t *old)
int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old)
{
int ret;
if ((unsigned)how - SIG_BLOCK > 2U) return EINVAL;

View file

@ -1,6 +1,6 @@
#include <semaphore.h>
int sem_getvalue(sem_t *sem, int *valp)
int sem_getvalue(sem_t *restrict sem, int *restrict valp)
{
int val = sem->__val[0];
*valp = val < 0 ? 0 : val;

View file

@ -6,7 +6,7 @@ static void cleanup(void *p)
a_dec(p);
}
int sem_timedwait(sem_t *sem, const struct timespec *at)
int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at)
{
while (sem_trywait(sem)) {
int r;