gthr-vxworks-cond.c 2.1 KB

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