rsys

Basic data structures and low-level features
git clone git://git.meso-star.fr/rsys.git
Log | Files | Refs | README | LICENSE

pthread_condition.c (1593B)


      1 /* Copyright (C) 2013-2023, 2025 Vincent Forest (vaplv@free.fr)
      2  *
      3  * The RSys library is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published
      5  * by the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * The RSys library is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with the RSys library. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #include "../condition.h"
     17 #include "../mem_allocator.h"
     18 #include <pthread.h>
     19 
     20 #ifdef NDEBUG
     21   #define PTHREAD(Func) pthread_##Func
     22 #else
     23   #define PTHREAD(Func) ASSERT(pthread_##Func == 0)
     24 #endif
     25 
     26 struct cond*
     27 cond_create(void)
     28 {
     29   pthread_cond_t* cond = mem_alloc(sizeof(pthread_cond_t));
     30   if(cond)
     31     PTHREAD(cond_init(cond, NULL));
     32   return (struct cond*)cond;
     33 }
     34 
     35 void
     36 cond_destroy(struct cond* cond)
     37 {
     38   ASSERT(cond);
     39   PTHREAD(cond_destroy((pthread_cond_t*)cond));
     40   mem_rm(cond);
     41 }
     42 
     43 void
     44 cond_wait(struct cond* cond, struct mutex* mutex)
     45 {
     46   ASSERT(cond);
     47   PTHREAD(cond_wait((pthread_cond_t*)cond, (pthread_mutex_t*)mutex));
     48 }
     49 
     50 void
     51 cond_signal(struct cond* cond)
     52 {
     53   ASSERT(cond);
     54   PTHREAD(cond_signal((pthread_cond_t*)cond));
     55 }
     56 
     57 void
     58 cond_broadcast(struct cond* cond)
     59 {
     60   ASSERT(cond);
     61   PTHREAD(cond_broadcast((pthread_cond_t*)cond));
     62 }
     63 
     64 #undef PTHREAD