171b3fa15SDavid Xu /* 271b3fa15SDavid Xu * Copyright (c) 1997 John Birrell <jb@cimlogic.com.au>. 371b3fa15SDavid Xu * All rights reserved. 471b3fa15SDavid Xu * 571b3fa15SDavid Xu * Redistribution and use in source and binary forms, with or without 671b3fa15SDavid Xu * modification, are permitted provided that the following conditions 771b3fa15SDavid Xu * are met: 871b3fa15SDavid Xu * 1. Redistributions of source code must retain the above copyright 971b3fa15SDavid Xu * notice, this list of conditions and the following disclaimer. 1071b3fa15SDavid Xu * 2. Redistributions in binary form must reproduce the above copyright 1171b3fa15SDavid Xu * notice, this list of conditions and the following disclaimer in the 1271b3fa15SDavid Xu * documentation and/or other materials provided with the distribution. 1371b3fa15SDavid Xu * 3. All advertising materials mentioning features or use of this software 1471b3fa15SDavid Xu * must display the following acknowledgement: 1571b3fa15SDavid Xu * This product includes software developed by John Birrell. 1671b3fa15SDavid Xu * 4. Neither the name of the author nor the names of any co-contributors 1771b3fa15SDavid Xu * may be used to endorse or promote products derived from this software 1871b3fa15SDavid Xu * without specific prior written permission. 1971b3fa15SDavid Xu * 2071b3fa15SDavid Xu * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND 2171b3fa15SDavid Xu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2271b3fa15SDavid Xu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2371b3fa15SDavid Xu * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2471b3fa15SDavid Xu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2571b3fa15SDavid Xu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2671b3fa15SDavid Xu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2771b3fa15SDavid Xu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2871b3fa15SDavid Xu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2971b3fa15SDavid Xu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3071b3fa15SDavid Xu * SUCH DAMAGE. 3171b3fa15SDavid Xu * 32*9219c44cSDavid Xu * $DragonFly: src/lib/libthread_xu/thread/thr_condattr.c,v 1.2 2005/03/15 11:24:23 davidxu Exp $ 3371b3fa15SDavid Xu */ 3471b3fa15SDavid Xu #include <stdlib.h> 3571b3fa15SDavid Xu #include <string.h> 3671b3fa15SDavid Xu #include <errno.h> 3771b3fa15SDavid Xu #include <pthread.h> 3871b3fa15SDavid Xu #include "thr_private.h" 3971b3fa15SDavid Xu 4071b3fa15SDavid Xu __weak_reference(_pthread_condattr_init, pthread_condattr_init); 4171b3fa15SDavid Xu __weak_reference(_pthread_condattr_destroy, pthread_condattr_destroy); 4271b3fa15SDavid Xu __weak_reference(_pthread_condattr_getclock, pthread_condattr_getclock); 4371b3fa15SDavid Xu __weak_reference(_pthread_condattr_setclock, pthread_condattr_setclock); 4471b3fa15SDavid Xu __weak_reference(_pthread_condattr_getpshared, pthread_condattr_getpshared); 4571b3fa15SDavid Xu __weak_reference(_pthread_condattr_setpshared, pthread_condattr_setpshared); 4671b3fa15SDavid Xu 4771b3fa15SDavid Xu int 4871b3fa15SDavid Xu _pthread_condattr_init(pthread_condattr_t *attr) 4971b3fa15SDavid Xu { 5071b3fa15SDavid Xu pthread_condattr_t pattr; 5171b3fa15SDavid Xu int ret; 5271b3fa15SDavid Xu 5371b3fa15SDavid Xu if ((pattr = (pthread_condattr_t) 5471b3fa15SDavid Xu malloc(sizeof(struct pthread_cond_attr))) == NULL) { 5571b3fa15SDavid Xu ret = ENOMEM; 5671b3fa15SDavid Xu } else { 5771b3fa15SDavid Xu memcpy(pattr, &_pthread_condattr_default, 5871b3fa15SDavid Xu sizeof(struct pthread_cond_attr)); 5971b3fa15SDavid Xu *attr = pattr; 6071b3fa15SDavid Xu ret = 0; 6171b3fa15SDavid Xu } 6271b3fa15SDavid Xu return (ret); 6371b3fa15SDavid Xu } 6471b3fa15SDavid Xu 6571b3fa15SDavid Xu int 6671b3fa15SDavid Xu _pthread_condattr_destroy(pthread_condattr_t *attr) 6771b3fa15SDavid Xu { 6871b3fa15SDavid Xu int ret; 6971b3fa15SDavid Xu 7071b3fa15SDavid Xu if (attr == NULL || *attr == NULL) { 7171b3fa15SDavid Xu ret = EINVAL; 7271b3fa15SDavid Xu } else { 7371b3fa15SDavid Xu free(*attr); 7471b3fa15SDavid Xu *attr = NULL; 7571b3fa15SDavid Xu ret = 0; 7671b3fa15SDavid Xu } 7771b3fa15SDavid Xu return(ret); 7871b3fa15SDavid Xu } 7971b3fa15SDavid Xu 8071b3fa15SDavid Xu int 8171b3fa15SDavid Xu _pthread_condattr_getclock(const pthread_condattr_t *attr, 8271b3fa15SDavid Xu clockid_t *clock_id) 8371b3fa15SDavid Xu { 8471b3fa15SDavid Xu if (attr == NULL || *attr == NULL) 8571b3fa15SDavid Xu return (EINVAL); 8671b3fa15SDavid Xu *clock_id = (*attr)->c_clockid; 8771b3fa15SDavid Xu return (0); 8871b3fa15SDavid Xu } 8971b3fa15SDavid Xu 9071b3fa15SDavid Xu int 9171b3fa15SDavid Xu _pthread_condattr_setclock(const pthread_condattr_t *attr, 9271b3fa15SDavid Xu clockid_t clock_id) 9371b3fa15SDavid Xu { 9471b3fa15SDavid Xu if (attr == NULL || *attr == NULL) 9571b3fa15SDavid Xu return (EINVAL); 96*9219c44cSDavid Xu if (clock_id != CLOCK_REALTIME || 97*9219c44cSDavid Xu clock_id != CLOCK_MONOTONIC) 9871b3fa15SDavid Xu return (EINVAL); 9971b3fa15SDavid Xu (*attr)->c_clockid = clock_id; 10071b3fa15SDavid Xu return (0); 10171b3fa15SDavid Xu } 10271b3fa15SDavid Xu 10371b3fa15SDavid Xu int 10471b3fa15SDavid Xu _pthread_condattr_getpshared(const pthread_condattr_t *attr, 10571b3fa15SDavid Xu int *pshared) 10671b3fa15SDavid Xu { 10771b3fa15SDavid Xu if (attr == NULL || *attr == NULL) 10871b3fa15SDavid Xu return (EINVAL); 10971b3fa15SDavid Xu 11071b3fa15SDavid Xu pshared = PTHREAD_PROCESS_PRIVATE; 11171b3fa15SDavid Xu return (0); 11271b3fa15SDavid Xu } 11371b3fa15SDavid Xu 11471b3fa15SDavid Xu int 11571b3fa15SDavid Xu _pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared) 11671b3fa15SDavid Xu { 11771b3fa15SDavid Xu if (attr == NULL || *attr == NULL) 11871b3fa15SDavid Xu return (EINVAL); 11971b3fa15SDavid Xu 12071b3fa15SDavid Xu if (pshared != PTHREAD_PROCESS_PRIVATE) 12171b3fa15SDavid Xu return (EINVAL); 12271b3fa15SDavid Xu return (0); 12371b3fa15SDavid Xu } 124