1/* Copyright (C) 2002-2022 Free Software Foundation, Inc.
2
3This file is part of GCC.
4
5GCC is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free
7Software Foundation; either version 3, or (at your option) any later
8version.
9
10GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11WARRANTY; without even the implied warranty of MERCHANTABILITY or
12FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13for more details.
14
15Under Section 7 of GPL version 3, you are granted additional
16permissions described in the GCC Runtime Library Exception, version
173.1, as published by the Free Software Foundation.
18
19You should have received a copy of the GNU General Public License and
20a copy of the GCC Runtime Library Exception along with this program;
21see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
22<http://www.gnu.org/licenses/>.  */
23
24/* Threads compatibility routines for libgcc2 for VxWorks.
25
26   This file implements the GTHREAD_HAS_COND part of the interface
27   exposed by gthr-vxworks.h.  */
28
29#include "gthr.h"
30
31#if __GTHREAD_HAS_COND
32
33#include <taskLib.h>
34
35/* --------------------------- Condition Variables ------------------------ */
36
37void
38__gthread_cond_init (__gthread_cond_t *cond)
39{
40  if (!cond)
41    return;
42  *cond = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
43}
44
45int
46__gthread_cond_destroy (__gthread_cond_t *cond)
47{
48  if (!cond)
49    return ERROR;
50  return __CHECK_RESULT (semDelete (*cond));
51}
52
53int
54__gthread_cond_broadcast (__gthread_cond_t *cond)
55{
56  if (!cond)
57    return ERROR;
58
59  return __CHECK_RESULT (semFlush (*cond));
60}
61
62int
63__gthread_cond_wait (__gthread_cond_t *cond,
64		     __gthread_mutex_t *mutex)
65{
66  if (!cond)
67    return ERROR;
68
69  if (!mutex)
70    return ERROR;
71
72  int ret = __CHECK_RESULT (semExchange (*mutex, *cond, WAIT_FOREVER));
73
74  __RETURN_ERRNO_IF_NOT_OK (semTake (*mutex, WAIT_FOREVER));
75
76  return ret;
77}
78
79int
80__gthread_cond_wait_recursive (__gthread_cond_t *cond,
81			       __gthread_recursive_mutex_t *mutex)
82{
83  return __gthread_cond_wait (cond, mutex);
84}
85
86#endif
87