FreeBASIC  0.91.0
thread_mutex.c
Go to the documentation of this file.
1 /* mutex handling routines */
2 
3 #include "../fb.h"
4 #include "../fb_private_thread.h"
5 
7 {
8  FBMUTEX *mutex = (FBMUTEX *)malloc( sizeof( FBMUTEX ) );
9  if( !mutex )
10  return NULL;
11 
12  mutex->id = CreateSemaphore( NULL, 1, 1, NULL );
13 
14  return mutex;
15 }
16 
18 {
19  if( mutex ) {
20  CloseHandle( mutex->id );
21  free( (void *)mutex );
22  }
23 }
24 
26 {
27  if( mutex ) {
28  WaitForSingleObject( mutex->id, INFINITE );
29  }
30 }
31 
33 {
34  if( mutex ) {
35  ReleaseSemaphore( mutex->id, 1, NULL );
36  }
37 }