root/maint/gnulib/lib/glthread/cond.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. glthread_cond_init
  2. glthread_cond_wait
  3. glthread_cond_timedwait
  4. glthread_cond_signal
  5. glthread_cond_broadcast
  6. glthread_cond_destroy

   1 /* Condition variables for multithreading.
   2    Copyright (C) 2008-2021 Free Software Foundation, Inc.
   3 
   4    This file is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU Lesser General Public License as
   6    published by the Free Software Foundation; either version 2.1 of the
   7    License, or (at your option) any later version.
   8 
   9    This file is distributed in the hope that it will be useful,
  10    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12    GNU Lesser General Public License for more details.
  13 
  14    You should have received a copy of the GNU Lesser General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 /* Written by Yoann Vandoorselaere <yoann@prelude-ids.org>, 2008,
  18    and Bruno Haible <bruno@clisp.org>, 2008.  */
  19 
  20 #include <config.h>
  21 
  22 #define _GLTHREAD_COND_INLINE _GL_EXTERN_INLINE
  23 #include "glthread/cond.h"
  24 
  25 /* ========================================================================= */
  26 
  27 #if USE_ISOC_THREADS || USE_ISOC_AND_POSIX_THREADS
  28 
  29 int
  30 glthread_cond_init (gl_cond_t *condition)
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32   if (cnd_init (&condition->condition) != thrd_success)
  33     return ENOMEM;
  34   condition->init_needed = 0;
  35   return 0;
  36 }
  37 
  38 int
  39 glthread_cond_wait (gl_cond_t *condition, gl_lock_t *lock)
     /* [previous][next][first][last][top][bottom][index][help] */
  40 {
  41   if (condition->init_needed)
  42     call_once (&condition->init_once, condition->init_func);
  43   if (lock->init_needed)
  44     call_once (&lock->init_once, lock->init_func);
  45   if (cnd_wait (&condition->condition, &lock->mutex) != thrd_success)
  46     return EINVAL;
  47   return 0;
  48 }
  49 
  50 int
  51 glthread_cond_timedwait (gl_cond_t *condition, gl_lock_t *lock,
     /* [previous][next][first][last][top][bottom][index][help] */
  52                          const struct timespec *abstime)
  53 {
  54   if (condition->init_needed)
  55     call_once (&condition->init_once, condition->init_func);
  56   if (lock->init_needed)
  57     call_once (&lock->init_once, lock->init_func);
  58   switch (cnd_timedwait (&condition->condition, &lock->mutex, abstime))
  59     {
  60     case thrd_success:
  61       break;
  62     case thrd_timedout:
  63       return ETIMEDOUT;
  64     default:
  65       return EINVAL;
  66     }
  67   return 0;
  68 }
  69 
  70 int
  71 glthread_cond_signal (gl_cond_t *condition)
     /* [previous][next][first][last][top][bottom][index][help] */
  72 {
  73   if (condition->init_needed)
  74     call_once (&condition->init_once, condition->init_func);
  75   if (cnd_signal (&condition->condition) != thrd_success)
  76     return EINVAL;
  77   return 0;
  78 }
  79 
  80 int
  81 glthread_cond_broadcast (gl_cond_t *condition)
     /* [previous][next][first][last][top][bottom][index][help] */
  82 {
  83   if (condition->init_needed)
  84     call_once (&condition->init_once, condition->init_func);
  85   if (cnd_broadcast (&condition->condition) != thrd_success)
  86     return EINVAL;
  87   return 0;
  88 }
  89 
  90 int
  91 glthread_cond_destroy (gl_cond_t *condition)
     /* [previous][next][first][last][top][bottom][index][help] */
  92 {
  93   if (condition->init_needed)
  94     call_once (&condition->init_once, condition->init_func);
  95   cnd_destroy (&condition->condition);
  96   return 0;
  97 }
  98 
  99 #endif
 100 
 101 /* ========================================================================= */
 102 
 103 #if USE_POSIX_THREADS
 104 
 105 #endif
 106 
 107 /* ========================================================================= */
 108 
 109 #if USE_WINDOWS_THREADS
 110 
 111 #endif
 112 
 113 /* ========================================================================= */

/* [previous][next][first][last][top][bottom][index][help] */