rthread_condattr.c revision 1.1
1/*	$OpenBSD: rthread_condattr.c,v 1.1 2017/08/15 06:13:24 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 <stdlib.h>
25#include <string.h>
26#include <unistd.h>
27#include <errno.h>
28
29#include <pthread.h>
30
31#include "rthread.h"
32
33int
34pthread_condattr_init(pthread_condattr_t *attrp)
35{
36	pthread_condattr_t attr;
37
38	attr = calloc(1, sizeof(*attr));
39	if (!attr)
40		return (errno);
41	attr->ca_clock = CLOCK_REALTIME;
42	*attrp = attr;
43
44	return (0);
45}
46
47int
48pthread_condattr_destroy(pthread_condattr_t *attrp)
49{
50	free(*attrp);
51	*attrp = NULL;
52
53	return (0);
54}
55
56int
57pthread_condattr_getclock(const pthread_condattr_t *attr, clockid_t *clock_id)
58{
59	*clock_id = (*attr)->ca_clock;
60	return (0);
61}
62
63int
64pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id)
65{
66	if (clock_id != CLOCK_REALTIME && clock_id != CLOCK_MONOTONIC)
67		return (EINVAL);
68	(*attr)->ca_clock = clock_id;
69	return (0);
70}
71
72