22 #include <sys/types.h> 33 #pragma warning(disable : 271 310) 40 kmp_bootstrap_lock_t __kmp_stdio_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER(
42 kmp_bootstrap_lock_t __kmp_console_lock = KMP_BOOTSTRAP_LOCK_INITIALIZER(
49 static HANDLE __kmp_stdout = NULL;
51 static HANDLE __kmp_stderr = NULL;
52 static int __kmp_console_exists = FALSE;
53 static kmp_str_buf_t __kmp_console_buf;
55 static int is_console(
void) {
63 rc = GetConsoleTitle(buffer,
sizeof(buffer));
70 return rc > 0 || err == 0;
73 void __kmp_close_console(
void) {
76 if (__kmp_console_exists) {
82 __kmp_str_buf_free(&__kmp_console_buf);
83 __kmp_console_exists = FALSE;
89 static void __kmp_redirect_output(
void) {
90 __kmp_acquire_bootstrap_lock(&__kmp_console_lock);
92 if (!__kmp_console_exists) {
99 __kmp_str_buf_init(&__kmp_console_buf);
108 ho = GetStdHandle(STD_OUTPUT_HANDLE);
109 if (ho == INVALID_HANDLE_VALUE || ho == NULL) {
111 DWORD err = GetLastError();
120 he = GetStdHandle(STD_ERROR_HANDLE);
121 if (he == INVALID_HANDLE_VALUE || he == NULL) {
123 DWORD err = GetLastError();
131 __kmp_console_exists = TRUE;
133 __kmp_release_bootstrap_lock(&__kmp_console_lock);
137 #define __kmp_stderr (stderr) 140 void __kmp_vprintf(
enum kmp_io __kmp_io,
char const *format, va_list ap) {
142 if (!__kmp_console_exists) {
143 __kmp_redirect_output();
145 if (!__kmp_stderr && __kmp_io == kmp_err) {
149 if (!__kmp_stdout && __kmp_io == kmp_out) {
155 if (__kmp_debug_buf && __kmp_debug_buffer != NULL) {
157 int dc = (__kmp_debug_buf_atomic ? KMP_TEST_THEN_INC32(&__kmp_debug_count)
158 : __kmp_debug_count++) %
159 __kmp_debug_buf_lines;
160 char *db = &__kmp_debug_buffer[dc * __kmp_debug_buf_chars];
163 #ifdef KMP_DEBUG_PIDS 164 chars = KMP_SNPRINTF(db, __kmp_debug_buf_chars,
"pid=%d: ",
165 (kmp_int32)getpid());
167 chars += KMP_VSNPRINTF(db, __kmp_debug_buf_chars, format, ap);
169 if (chars + 1 > __kmp_debug_buf_chars) {
170 if (chars + 1 > __kmp_debug_buf_warn_chars) {
173 __kmp_str_buf_print(&__kmp_console_buf,
"OMP warning: Debugging buffer " 174 "overflow; increase " 175 "KMP_DEBUG_BUF_CHARS to %d\n",
177 WriteFile(__kmp_stderr, __kmp_console_buf.str, __kmp_console_buf.used,
179 __kmp_str_buf_clear(&__kmp_console_buf);
181 fprintf(__kmp_stderr,
"OMP warning: Debugging buffer overflow; " 182 "increase KMP_DEBUG_BUF_CHARS to %d\n",
184 fflush(__kmp_stderr);
186 __kmp_debug_buf_warn_chars = chars + 1;
189 db[__kmp_debug_buf_chars - 2] =
'\n';
190 db[__kmp_debug_buf_chars - 1] =
'\0';
195 #ifdef KMP_DEBUG_PIDS 196 __kmp_str_buf_print(&__kmp_console_buf,
"pid=%d: ", (kmp_int32)getpid());
198 __kmp_str_buf_vprint(&__kmp_console_buf, format, ap);
199 WriteFile(__kmp_stderr, __kmp_console_buf.str, __kmp_console_buf.used,
201 __kmp_str_buf_clear(&__kmp_console_buf);
203 #ifdef KMP_DEBUG_PIDS 204 fprintf(__kmp_stderr,
"pid=%d: ", (kmp_int32)getpid());
206 vfprintf(__kmp_stderr, format, ap);
207 fflush(__kmp_stderr);
212 void __kmp_printf(
char const *format, ...) {
214 va_start(ap, format);
216 __kmp_acquire_bootstrap_lock(&__kmp_stdio_lock);
217 __kmp_vprintf(kmp_err, format, ap);
218 __kmp_release_bootstrap_lock(&__kmp_stdio_lock);
223 void __kmp_printf_no_lock(
char const *format, ...) {
225 va_start(ap, format);
227 __kmp_vprintf(kmp_err, format, ap);