1194845Sraj/* Copyright (C) 2002-2022 Free Software Foundation, Inc.
2194845Sraj
3194845SrajThis file is part of GCC.
4194845Sraj
5194845SrajGCC is free software; you can redistribute it and/or modify it under
6194845Srajthe terms of the GNU General Public License as published by the Free
7194845SrajSoftware Foundation; either version 3, or (at your option) any later
8194845Srajversion.
9194845Sraj
10194845SrajGCC is distributed in the hope that it will be useful, but WITHOUT ANY
11194845SrajWARRANTY; without even the implied warranty of MERCHANTABILITY or
12194845SrajFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13194845Srajfor more details.
14194845Sraj
15194845SrajUnder Section 7 of GPL version 3, you are granted additional
16194845Srajpermissions described in the GCC Runtime Library Exception, version
17194845Sraj3.1, as published by the Free Software Foundation.
18194845Sraj
19194845SrajYou should have received a copy of the GNU General Public License and
20194845Sraja copy of the GCC Runtime Library Exception along with this program;
21194845Srajsee the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
22194845Sraj<http://www.gnu.org/licenses/>.  */
23194845Sraj
24194845Sraj/* Threads compatibility routines for libgcc2 for VxWorks.
25194845Sraj
26194845Sraj   This file implements the GTHREAD_HAS_COND part of the interface
27194845Sraj   exposed by gthr-vxworks.h.  */
28194845Sraj
29194845Sraj#include "gthr.h"
30194845Sraj
31194845Sraj#if __GTHREAD_HAS_COND
32194845Sraj
33194845Sraj#include <taskLib.h>
34194845Sraj
35194845Sraj/* --------------------------- Condition Variables ------------------------ */
36194845Sraj
37194845Srajvoid
38194845Sraj__gthread_cond_init (__gthread_cond_t *cond)
39194845Sraj{
40194845Sraj  if (!cond)
41194845Sraj    return;
42194845Sraj  *cond = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
43194845Sraj}
44194845Sraj
45194845Srajint
46194845Sraj__gthread_cond_destroy (__gthread_cond_t *cond)
47194845Sraj{
48194845Sraj  if (!cond)
49194845Sraj    return ERROR;
50194845Sraj  return __CHECK_RESULT (semDelete (*cond));
51209131Sraj}
52209131Sraj
53194845Srajint
54194845Sraj__gthread_cond_broadcast (__gthread_cond_t *cond)
55194845Sraj{
56194845Sraj  if (!cond)
57194845Sraj    return ERROR;
58194845Sraj
59194845Sraj  return __CHECK_RESULT (semFlush (*cond));
60194845Sraj}
61194845Sraj
62194845Srajint
63194845Sraj__gthread_cond_wait (__gthread_cond_t *cond,
64194845Sraj		     __gthread_mutex_t *mutex)
65194845Sraj{
66194845Sraj  if (!cond)
67194845Sraj    return ERROR;
68194845Sraj
69194845Sraj  if (!mutex)
70194845Sraj    return ERROR;
71194845Sraj
72194845Sraj  int ret = __CHECK_RESULT (semExchange (*mutex, *cond, WAIT_FOREVER));
73194845Sraj
74194845Sraj  __RETURN_ERRNO_IF_NOT_OK (semTake (*mutex, WAIT_FOREVER));
75194845Sraj
76194845Sraj  return ret;
77194845Sraj}
78194845Sraj
79194845Srajint
80194845Sraj__gthread_cond_wait_recursive (__gthread_cond_t *cond,
81194845Sraj			       __gthread_recursive_mutex_t *mutex)
82194845Sraj{
83194845Sraj  return __gthread_cond_wait (cond, mutex);
84194845Sraj}
85194845Sraj
86194845Sraj#endif
87194845Sraj