43 # include <sys/types.h>
53 # pragma warning( push )
54 # pragma warning( disable: 271 310 )
56 # pragma warning( pop )
62 kmp_bootstrap_lock_t __kmp_stdio_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( __kmp_stdio_lock );
63 kmp_bootstrap_lock_t __kmp_console_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( __kmp_console_lock );
69 static HANDLE __kmp_stdout = NULL;
71 static HANDLE __kmp_stderr = NULL;
72 static int __kmp_console_exists = FALSE;
73 static kmp_str_buf_t __kmp_console_buf;
85 rc = GetConsoleTitle( buffer,
sizeof( buffer ) );
92 return rc > 0 || err == 0;
96 __kmp_close_console(
void )
100 if( __kmp_console_exists ) {
106 __kmp_str_buf_free( &__kmp_console_buf );
107 __kmp_console_exists = FALSE;
114 __kmp_redirect_output(
void )
116 __kmp_acquire_bootstrap_lock( &__kmp_console_lock );
118 if( ! __kmp_console_exists ) {
125 __kmp_str_buf_init( &__kmp_console_buf );
134 ho = GetStdHandle( STD_OUTPUT_HANDLE );
135 if ( ho == INVALID_HANDLE_VALUE || ho == NULL ) {
137 DWORD err = GetLastError();
147 he = GetStdHandle( STD_ERROR_HANDLE );
148 if ( he == INVALID_HANDLE_VALUE || he == NULL ) {
150 DWORD err = GetLastError();
158 __kmp_console_exists = TRUE;
160 __kmp_release_bootstrap_lock( &__kmp_console_lock );
164 #define __kmp_stderr (stderr)
168 __kmp_vprintf(
enum kmp_io __kmp_io,
char const * format, va_list ap )
171 if( !__kmp_console_exists ) {
172 __kmp_redirect_output();
174 if( ! __kmp_stderr && __kmp_io == kmp_err ) {
178 if( ! __kmp_stdout && __kmp_io == kmp_out ) {
184 if ( __kmp_debug_buf && __kmp_debug_buffer != NULL ) {
186 int dc = ( __kmp_debug_buf_atomic ?
187 KMP_TEST_THEN_INC32( & __kmp_debug_count) : __kmp_debug_count++ )
188 % __kmp_debug_buf_lines;
189 char *db = & __kmp_debug_buffer[ dc * __kmp_debug_buf_chars ];
192 #ifdef KMP_DEBUG_PIDS
193 chars = sprintf( db,
"pid=%d: ", (kmp_int32)getpid() );
195 chars += vsprintf( db, format, ap );
197 if ( chars + 1 > __kmp_debug_buf_chars ) {
198 if ( chars + 1 > __kmp_debug_buf_warn_chars ) {
201 __kmp_str_buf_print( &__kmp_console_buf,
202 "OMP warning: Debugging buffer overflow; increase KMP_DEBUG_BUF_CHARS to %d\n",
204 WriteFile( __kmp_stderr, __kmp_console_buf.str, __kmp_console_buf.used, &count, NULL );
205 __kmp_str_buf_clear( &__kmp_console_buf );
207 fprintf( __kmp_stderr,
208 "OMP warning: Debugging buffer overflow; increase KMP_DEBUG_BUF_CHARS to %d\n",
210 fflush( __kmp_stderr );
212 __kmp_debug_buf_warn_chars = chars + 1;
215 db[ __kmp_debug_buf_chars - 2 ] =
'\n';
216 db[ __kmp_debug_buf_chars - 1 ] =
'\0';
221 #ifdef KMP_DEBUG_PIDS
222 __kmp_str_buf_print( &__kmp_console_buf,
"pid=%d: ",
223 (kmp_int32)getpid() );
225 __kmp_str_buf_vprint( &__kmp_console_buf, format, ap );
228 __kmp_console_buf.str,
229 __kmp_console_buf.used,
233 __kmp_str_buf_clear( &__kmp_console_buf );
235 #ifdef KMP_DEBUG_PIDS
236 fprintf( __kmp_stderr,
"pid=%d: ", (kmp_int32)getpid() );
238 vfprintf( __kmp_stderr, format, ap );
239 fflush( __kmp_stderr );
245 __kmp_printf(
char const * format, ... )
248 va_start( ap, format );
250 __kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
251 __kmp_vprintf( kmp_err, format, ap );
252 __kmp_release_bootstrap_lock( & __kmp_stdio_lock );
258 __kmp_printf_no_lock(
char const * format, ... )
261 va_start( ap, format );
263 __kmp_vprintf( kmp_err, format, ap );