41 # include <sys/types.h>
51 # pragma warning( push )
52 # pragma warning( disable: 271 310 )
54 # pragma warning( pop )
60 kmp_bootstrap_lock_t __kmp_stdio_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( __kmp_stdio_lock );
61 kmp_bootstrap_lock_t __kmp_console_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER( __kmp_console_lock );
67 static HANDLE __kmp_stdout = NULL;
69 static HANDLE __kmp_stderr = NULL;
70 static int __kmp_console_exists = FALSE;
71 static kmp_str_buf_t __kmp_console_buf;
83 rc = GetConsoleTitle( buffer,
sizeof( buffer ) );
90 return rc > 0 || err == 0;
94 __kmp_close_console(
void )
98 if( __kmp_console_exists ) {
104 __kmp_str_buf_free( &__kmp_console_buf );
105 __kmp_console_exists = FALSE;
112 __kmp_redirect_output(
void )
114 __kmp_acquire_bootstrap_lock( &__kmp_console_lock );
116 if( ! __kmp_console_exists ) {
123 __kmp_str_buf_init( &__kmp_console_buf );
132 ho = GetStdHandle( STD_OUTPUT_HANDLE );
133 if ( ho == INVALID_HANDLE_VALUE || ho == NULL ) {
135 DWORD err = GetLastError();
145 he = GetStdHandle( STD_ERROR_HANDLE );
146 if ( he == INVALID_HANDLE_VALUE || he == NULL ) {
148 DWORD err = GetLastError();
156 __kmp_console_exists = TRUE;
158 __kmp_release_bootstrap_lock( &__kmp_console_lock );
162 #define __kmp_stderr (stderr)
166 __kmp_vprintf(
enum kmp_io __kmp_io,
char const * format, va_list ap )
169 if( !__kmp_console_exists ) {
170 __kmp_redirect_output();
172 if( ! __kmp_stderr && __kmp_io == kmp_err ) {
176 if( ! __kmp_stdout && __kmp_io == kmp_out ) {
182 if ( __kmp_debug_buf && __kmp_debug_buffer != NULL ) {
184 int dc = ( __kmp_debug_buf_atomic ?
185 KMP_TEST_THEN_INC32( & __kmp_debug_count) : __kmp_debug_count++ )
186 % __kmp_debug_buf_lines;
187 char *db = & __kmp_debug_buffer[ dc * __kmp_debug_buf_chars ];
190 #ifdef KMP_DEBUG_PIDS
191 chars = KMP_SNPRINTF( db, __kmp_debug_buf_chars,
"pid=%d: ", (kmp_int32)getpid() );
193 chars += KMP_VSNPRINTF( db, __kmp_debug_buf_chars, format, ap );
195 if ( chars + 1 > __kmp_debug_buf_chars ) {
196 if ( chars + 1 > __kmp_debug_buf_warn_chars ) {
199 __kmp_str_buf_print( &__kmp_console_buf,
200 "OMP warning: Debugging buffer overflow; increase KMP_DEBUG_BUF_CHARS to %d\n",
202 WriteFile( __kmp_stderr, __kmp_console_buf.str, __kmp_console_buf.used, &count, NULL );
203 __kmp_str_buf_clear( &__kmp_console_buf );
205 fprintf( __kmp_stderr,
206 "OMP warning: Debugging buffer overflow; increase KMP_DEBUG_BUF_CHARS to %d\n",
208 fflush( __kmp_stderr );
210 __kmp_debug_buf_warn_chars = chars + 1;
213 db[ __kmp_debug_buf_chars - 2 ] =
'\n';
214 db[ __kmp_debug_buf_chars - 1 ] =
'\0';
219 #ifdef KMP_DEBUG_PIDS
220 __kmp_str_buf_print( &__kmp_console_buf,
"pid=%d: ",
221 (kmp_int32)getpid() );
223 __kmp_str_buf_vprint( &__kmp_console_buf, format, ap );
226 __kmp_console_buf.str,
227 __kmp_console_buf.used,
231 __kmp_str_buf_clear( &__kmp_console_buf );
233 #ifdef KMP_DEBUG_PIDS
234 fprintf( __kmp_stderr,
"pid=%d: ", (kmp_int32)getpid() );
236 vfprintf( __kmp_stderr, format, ap );
237 fflush( __kmp_stderr );
243 __kmp_printf(
char const * format, ... )
246 va_start( ap, format );
248 __kmp_acquire_bootstrap_lock( & __kmp_stdio_lock );
249 __kmp_vprintf( kmp_err, format, ap );
250 __kmp_release_bootstrap_lock( & __kmp_stdio_lock );
256 __kmp_printf_no_lock(
char const * format, ... )
259 va_start( ap, format );
261 __kmp_vprintf( kmp_err, format, ap );