source: rtems/cpukit/libstdthreads/cnd.c @ 68e1ccc4

5
Last change on this file since 68e1ccc4 was cff773f, checked in by Sebastian Huber <sebastian.huber@…>, on 09/10/15 at 15:12:06

libstdthreads: Add C11 threads

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*-
2 * Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
3 * Copyright (c) 2015 embedded brains GmbH <info@embedded-brains.de>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD r228904 2011-12-26T21:51:53Z$
28 */
29
30#include <threads.h>
31#include <errno.h>
32
33int
34cnd_broadcast(cnd_t *cond)
35{
36
37        _Condition_Broadcast(cond);
38        return (thrd_success);
39}
40
41void
42cnd_destroy(cnd_t *cond)
43{
44
45        _Condition_Destroy(cond);
46}
47
48int
49cnd_init(cnd_t *cond)
50{
51
52        _Condition_Initialize(cond);
53        return (thrd_success);
54}
55
56int
57cnd_signal(cnd_t *cond)
58{
59
60        _Condition_Signal(cond);
61        return (thrd_success);
62}
63
64int
65cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx,
66    const struct timespec *restrict ts)
67{
68
69        switch (_Condition_Wait_recursive_timed(cond, mtx, ts)) {
70        case 0:
71                return (thrd_success);
72        case ETIMEDOUT:
73                return (thrd_timedout);
74        default:
75                return (thrd_error);
76        }
77}
78
79int
80cnd_wait(cnd_t *cond, mtx_t *mtx)
81{
82
83        _Condition_Wait_recursive(cond, mtx);
84        return (thrd_success);
85}
Note: See TracBrowser for help on using the repository browser.