(root)/
gcc-13.2.0/
libgcc/
config/
gthr-vxworks-cond.c
       1  /* Copyright (C) 2002-2023 Free Software Foundation, Inc.
       2  
       3  This file is part of GCC.
       4  
       5  GCC is free software; you can redistribute it and/or modify it under
       6  the terms of the GNU General Public License as published by the Free
       7  Software Foundation; either version 3, or (at your option) any later
       8  version.
       9  
      10  GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11  WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13  for more details.
      14  
      15  Under Section 7 of GPL version 3, you are granted additional
      16  permissions described in the GCC Runtime Library Exception, version
      17  3.1, as published by the Free Software Foundation.
      18  
      19  You should have received a copy of the GNU General Public License and
      20  a copy of the GCC Runtime Library Exception along with this program;
      21  see 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  
      37  void
      38  __gthread_cond_init (__gthread_cond_t *cond)
      39  {
      40    if (!cond)
      41      return;
      42    *cond = semBCreate (SEM_Q_FIFO, SEM_EMPTY);
      43  }
      44  
      45  int
      46  __gthread_cond_destroy (__gthread_cond_t *cond)
      47  {
      48    if (!cond)
      49      return ERROR;
      50    return __CHECK_RESULT (semDelete (*cond));
      51  }
      52  
      53  int
      54  __gthread_cond_broadcast (__gthread_cond_t *cond)
      55  {
      56    if (!cond)
      57      return ERROR;
      58  
      59    return __CHECK_RESULT (semFlush (*cond));
      60  }
      61  
      62  int
      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  
      79  int
      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