Add pthread_condattr_getclock(3) and pthread_condattr_setclock(3).

This commit is contained in:
Jonas 'Sortie' Termansen 2014-07-07 15:13:17 +02:00
parent dffcc700d1
commit 993a5736f9
8 changed files with 76 additions and 4 deletions

View File

@ -12,7 +12,9 @@ CXXFLAGS:=$(CXXFLAGS) -Wall -Wextra -fno-exceptions -fno-rtti
OBJS=\
pthread_condattr_destroy.o \
pthread_condattr_getclock.o \
pthread_condattr_init.o \
pthread_condattr_setclock.o \
pthread_cond_broadcast.o \
pthread_cond_destroy.o \
pthread_cond_init.o \

View File

@ -44,22 +44,26 @@ typedef struct
{
struct pthread_cond_elem* first;
struct pthread_cond_elem* last;
__clock_t clock;
} __pthread_cond_t;
#else
typedef struct
{
void* __pthread_first;
void* __pthread_last;
__clock_t __pthread_clock;
} __pthread_cond_t;
#endif
#if defined(__is_sortix_libpthread)
typedef struct
{
__clock_t clock;
} __pthread_condattr_t;
#else
typedef struct
{
__clock_t __pthread_clock;
} __pthread_condattr_t;
#endif

View File

@ -150,7 +150,7 @@ struct pthread_cond_elem
};
#endif
#define PTHREAD_COND_INITIALIZER { NULL, NULL }
#define PTHREAD_COND_INITIALIZER { NULL, NULL, CLOCK_REALTIME }
#define PTHREAD_MUTEX_INITIALIZER { 0, PTHREAD_MUTEX_DEFAULT, 0, 0 }
#define PTHREAD_RWLOCK_INITIALIZER 0
@ -198,10 +198,11 @@ int pthread_cond_timedwait(pthread_cond_t* __restrict,
const struct timespec* __restrict);
int pthread_cond_wait(pthread_cond_t* __restrict, pthread_mutex_t* __restrict);
int pthread_condattr_destroy(pthread_condattr_t*);
/* TODO: pthread_condattr_getclock */
int pthread_condattr_getclock(const pthread_condattr_t* __restrict,
clockid_t* __restrict);
/* TODO: pthread_condattr_getpshared */
int pthread_condattr_init(pthread_condattr_t*);
/* TODO: pthread_condattr_setclock */
int pthread_condattr_setclock(pthread_condattr_t*, clockid_t);
/* TODO: pthread_condattr_setpshared */
/* TODO: pthread_create */
/* TODO: pthread_detach */

View File

@ -37,6 +37,7 @@ int pthread_cond_init(pthread_cond_t* restrict cond,
cond->first = NULL;
cond->last = NULL;
cond->clock = attr->clock;
return 0;
}

View File

@ -45,7 +45,7 @@ int pthread_cond_timedwait(pthread_cond_t* restrict cond,
while ( !elem.woken )
{
struct timespec now;
if ( clock_gettime(CLOCK_REALTIME, &now) < 0 )
if ( clock_gettime(cond->clock, &now) < 0 )
return errno;
if ( timespec_le(*abstime, now) )
return errno = ETIMEDOUT;

View File

@ -0,0 +1,32 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2014.
This file is part of Sortix libpthread.
Sortix libpthread is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
Sortix libpthread is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Sortix libpthread. If not, see <http://www.gnu.org/licenses/>.
pthread_condattr_getclock.c++
Gets the requested clock in a cond attribute object.
*******************************************************************************/
#include <pthread.h>
extern "C"
int pthread_condattr_getclock(const pthread_condattr_t* restrict attr,
clockid_t* restrict clock)
{
return *clock = attr->clock, 0;
}

View File

@ -28,5 +28,6 @@
extern "C" int pthread_condattr_init(pthread_condattr_t* attr)
{
memset(attr, 0, sizeof(*attr));
attr->clock = CLOCK_REALTIME;
return 0;
}

View File

@ -0,0 +1,31 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2014.
This file is part of Sortix libpthread.
Sortix libpthread is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
Sortix libpthread is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Sortix libpthread. If not, see <http://www.gnu.org/licenses/>.
pthread_condattr_setclock.c++
Sets the requested clock in a cond attribute object.
*******************************************************************************/
#include <pthread.h>
extern "C"
int pthread_condattr_setclock(pthread_condattr_t* attr, clockid_t clock)
{
return attr->clock = clock, 0;
}