rthread_condattr.c revision 1.2
1/*	$OpenBSD: rthread_condattr.c,v 1.2 2017/08/15 06:38:41 guenther Exp $ */
2/*
3 * Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
4 * Copyright (c) 2012 Philip Guenther <guenther@openbsd.org>
5 * All Rights Reserved.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19/*
20 * Condition Variable Attributes
21 */
22
23#include <assert.h>
24#include <errno.h>
25#include <pthread.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29
30#include "rthread.h"
31
32int
33pthread_condattr_init(pthread_condattr_t *attrp)
34{
35	pthread_condattr_t attr;
36
37	attr = calloc(1, sizeof(*attr));
38	if (!attr)
39		return (errno);
40	attr->ca_clock = CLOCK_REALTIME;
41	*attrp = attr;
42
43	return (0);
44}
45
46int
47pthread_condattr_destroy(pthread_condattr_t *attrp)
48{
49	free(*attrp);
50	*attrp = NULL;
51
52	return (0);
53}
54
55int
56pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id)
57{
58	*clock_id = (*attr)->ca_clock;
59	return (0);
60}
61
62int
63pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)
64{
65	if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC)
66		return (EINVAL);
67	(*attr)->ca_clock = clock_id;
68	return (0);
69}
70
71