FreeBASIC  0.91.0
thread_cond.c
Go to the documentation of this file.
1 /* condition variable functions */
2 
3 #include "../fb.h"
4 #include "../fb_private_thread.h"
5 
6 struct _FBCOND {
7  pthread_cond_t id;
8 };
9 
11 {
12  FBCOND *cond;
13 
14  cond = (FBCOND *)malloc( sizeof( FBCOND ) );
15  if( cond ) {
16  pthread_cond_init( &cond->id, NULL );
17  }
18 
19  return cond;
20 }
21 
23 {
24  if( cond ) {
25  pthread_cond_destroy( &cond->id );
26  free( (void *)cond );
27  }
28 }
29 
31 {
32  if( cond ) {
33  pthread_cond_signal( &cond->id );
34  }
35 }
36 
38 {
39  if( cond ) {
40  pthread_cond_broadcast( &cond->id );
41  }
42 }
43 
45 {
46  if( cond && mutex ) {
47  pthread_cond_wait( &cond->id, &mutex->id );
48  }
49 }