FreeBASIC  0.91.0
hinit.c
Go to the documentation of this file.
1 /* libfb initialization for Windows */
2 
3 #include "../fb.h"
4 #include "fb_private_console.h"
5 #include <float.h>
6 
7 #ifdef ENABLE_MT
8 static CRITICAL_SECTION __fb_global_mutex;
9 static CRITICAL_SECTION __fb_string_mutex;
10 static CRITICAL_SECTION __fb_mtcore_mutex;
11 FBCALL void fb_Lock( void ) { EnterCriticalSection( &__fb_global_mutex ); }
12 FBCALL void fb_Unlock( void ) { LeaveCriticalSection( &__fb_global_mutex ); }
13 FBCALL void fb_StrLock( void ) { EnterCriticalSection( &__fb_string_mutex ); }
14 FBCALL void fb_StrUnlock( void ) { LeaveCriticalSection( &__fb_string_mutex ); }
15 FBCALL void fb_MtLock( void ) { EnterCriticalSection( &__fb_mtcore_mutex ); }
16 FBCALL void fb_MtUnlock( void ) { LeaveCriticalSection( &__fb_mtcore_mutex ); }
17 #endif
18 
19 FB_CONSOLE_CTX __fb_con /* not initialized */;
20 
21 void fb_hInit( void )
22 {
23 #ifdef HOST_MINGW
24 #ifndef _clear87
25 /* if __STRICT_ANSI__ is defined the _controlfp function is not defined in some versions of mingw-gcc */
26 #define _PC_64 0x00000000
27 #define _RC_NEAR 0x00000000
28 #define _MCW_RC 0x00000300 /* Rounding */
29 #define _MCW_PC 0x00030000 /* Precision */
30 _CRTIMP unsigned int __cdecl __MINGW_NOTHROW _controlfp (unsigned int unNew, unsigned int unMask);
31 #endif
32  /* set FPU precision to 64-bit and round to nearest (as in QB) */
33  _controlfp( _PC_64|_RC_NEAR, _MCW_PC|_MCW_RC );
34 #elif defined HOST_X86
35  {
36  unsigned int control_word;
37  /* Get FPU control word */
38  __asm__ __volatile__( "fstcw %0" : "=m" (control_word) : );
39  /* Set 64-bit and round to nearest */
40  control_word = (control_word & 0xF0FF) | 0x300;
41  /* Write back FPU control word */
42  __asm__ __volatile__( "fldcw %0" : : "m" (control_word) );
43  }
44 #endif
45 
46 #ifdef ENABLE_MT
47  InitializeCriticalSection(&__fb_global_mutex);
48  InitializeCriticalSection(&__fb_string_mutex);
49  InitializeCriticalSection(&__fb_mtcore_mutex);
50 #endif
51 
52  memset( &__fb_con, 0, sizeof( FB_CONSOLE_CTX ) );
53 }
54 
55 void fb_hEnd( int unused )
56 {
57 #ifdef ENABLE_MT
58  DeleteCriticalSection(&__fb_global_mutex);
59  DeleteCriticalSection(&__fb_string_mutex);
60  DeleteCriticalSection(&__fb_mtcore_mutex);
61 #endif
62 }