22 # include <sys/types.h> 32 # pragma warning( push ) 33 # pragma warning( disable: 271 310 ) 35 # pragma warning( pop ) 41 kmp_bootstrap_lock_t __kmp_stdio_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( __kmp_stdio_lock );
42 kmp_bootstrap_lock_t __kmp_console_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( __kmp_console_lock );
48 static HANDLE __kmp_stdout = NULL;
50 static HANDLE __kmp_stderr = NULL;
51 static int __kmp_console_exists = FALSE;
52 static kmp_str_buf_t __kmp_console_buf;
64 rc = GetConsoleTitle( buffer,
sizeof( buffer ) );
71 return rc > 0 || err == 0;
75 __kmp_close_console(
void )
79 if( __kmp_console_exists ) {
85 __kmp_str_buf_free( &__kmp_console_buf );
86 __kmp_console_exists = FALSE;
93 __kmp_redirect_output(
void )
95 __kmp_acquire_bootstrap_lock( &__kmp_console_lock );
97 if( ! __kmp_console_exists ) {
104 __kmp_str_buf_init( &__kmp_console_buf );
113 ho = GetStdHandle( STD_OUTPUT_HANDLE );
114 if ( ho == INVALID_HANDLE_VALUE || ho == NULL ) {
116 DWORD err = GetLastError();
126 he = GetStdHandle( STD_ERROR_HANDLE );
127 if ( he == INVALID_HANDLE_VALUE || he == NULL ) {
129 DWORD err = GetLastError();
137 __kmp_console_exists = TRUE;
139 __kmp_release_bootstrap_lock( &__kmp_console_lock );
143 #define __kmp_stderr (stderr) 147 __kmp_vprintf(
enum kmp_io __kmp_io,
char const * format, va_list ap )
150 if( !__kmp_console_exists ) {
151 __kmp_redirect_output();
153 if( ! __kmp_stderr && __kmp_io == kmp_err ) {
157 if( ! __kmp_stdout && __kmp_io == kmp_out ) {
163 if ( __kmp_debug_buf && __kmp_debug_buffer != NULL ) {
165 int dc = ( __kmp_debug_buf_atomic ?
166 KMP_TEST_THEN_INC32( & __kmp_debug_count) : __kmp_debug_count++ )
167 % __kmp_debug_buf_lines;
168 char *db = & __kmp_debug_buffer[ dc * __kmp_debug_buf_chars ];
171 #ifdef KMP_DEBUG_PIDS 172 chars = KMP_SNPRINTF( db, __kmp_debug_buf_chars,
"pid=%d: ", (kmp_int32)getpid() );
174 chars += KMP_VSNPRINTF( db, __kmp_debug_buf_chars, format, ap );
176 if ( chars + 1 > __kmp_debug_buf_chars ) {
177 if ( chars + 1 > __kmp_debug_buf_warn_chars ) {
180 __kmp_str_buf_print( &__kmp_console_buf,
181 "OMP warning: Debugging buffer overflow; increase KMP_DEBUG_BUF_CHARS to %d\n",
183 WriteFile( __kmp_stderr, __kmp_console_buf.str, __kmp_console_buf.used, &count, NULL );
184 __kmp_str_buf_clear( &__kmp_console_buf );
186 fprintf( __kmp_stderr,
187 "OMP warning: Debugging buffer overflow; increase KMP_DEBUG_BUF_CHARS to %d\n",
189 fflush( __kmp_stderr );
191 __kmp_debug_buf_warn_chars = chars + 1;
194 db[ __kmp_debug_buf_chars - 2 ] =
'\n';
195 db[ __kmp_debug_buf_chars - 1 ] =
'\0';
200 #ifdef KMP_DEBUG_PIDS 201 __kmp_str_buf_print( &__kmp_console_buf,
"pid=%d: ",
202 (kmp_int32)getpid() );
204 __kmp_str_buf_vprint( &__kmp_console_buf, format, ap );
207 __kmp_console_buf.str,
208 __kmp_console_buf.used,
212 __kmp_str_buf_clear( &__kmp_console_buf );
214 #ifdef KMP_DEBUG_PIDS 215 fprintf( __kmp_stderr,
"pid=%d: ", (kmp_int32)getpid() );
217 vfprintf( __kmp_stderr, format, ap );
218 fflush( __kmp_stderr );
224 __kmp_printf(
char const * format, ... )
227 va_start( ap, format );
229 __kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
230 __kmp_vprintf( kmp_err, format, ap );
231 __kmp_release_bootstrap_lock( & __kmp_stdio_lock );
237 __kmp_printf_no_lock(
char const * format, ... )
240 va_start( ap, format );
242 __kmp_vprintf( kmp_err, format, ap );