зеркало из https://github.com/github/ruby.git
* thread.c (rb_thread_debug): added runtime debugging flag.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
b0d8301744
Коммит
5374de14e3
|
@ -1,3 +1,7 @@
|
|||
Sat Feb 24 18:39:15 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* thread.c (rb_thread_debug): added runtime debugging flag.
|
||||
|
||||
Sat Feb 24 17:45:48 2007 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* parse.y (f_arg, opt_f_block_arg): ripper should export VALUE.
|
||||
|
|
36
thread.c
36
thread.c
|
@ -49,7 +49,9 @@
|
|||
#include "vm.h"
|
||||
#include "gc.h"
|
||||
|
||||
#ifndef THREAD_DEBUG
|
||||
#define THREAD_DEBUG 0
|
||||
#endif
|
||||
|
||||
static void sleep_for_polling();
|
||||
static void sleep_timeval(rb_thread_t *th, struct timeval time);
|
||||
|
@ -110,7 +112,27 @@ NOINLINE(void rb_gc_save_machine_context(rb_thread_t *));
|
|||
} while(0)
|
||||
|
||||
#if THREAD_DEBUG
|
||||
void thread_debug(const char *fmt, ...);
|
||||
void rb_thread_debug(const char *fmt, ...);
|
||||
|
||||
# if THREAD_DEBUG < 0
|
||||
static int rb_thread_debug_enabled;
|
||||
|
||||
static VALUE
|
||||
rb_thread_s_debug(void)
|
||||
{
|
||||
return INT2NUM(rb_thread_debug_enabled);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
rb_thread_s_debug_set(VALUE self, VALUE val)
|
||||
{
|
||||
rb_thread_debug_enabled = RTEST(val);
|
||||
return val;
|
||||
}
|
||||
# else
|
||||
# define rb_thread_debug_enabled THREAD_DEBUG
|
||||
# endif
|
||||
#define thread_debug rb_thread_debug
|
||||
#else
|
||||
#define thread_debug if(0)printf
|
||||
#endif
|
||||
|
@ -120,7 +142,8 @@ void thread_debug(const char *fmt, ...);
|
|||
|
||||
#define DEBUG_OUT() \
|
||||
WaitForSingleObject(&debug_mutex, INFINITE); \
|
||||
printf("%8p - %s", GetCurrentThreadId(), buf); \
|
||||
printf("%p - %s", GetCurrentThreadId(), buf); \
|
||||
fflush(stdout); \
|
||||
ReleaseMutex(&debug_mutex);
|
||||
|
||||
#elif defined(HAVE_PTHREAD_H)
|
||||
|
@ -129,6 +152,7 @@ void thread_debug(const char *fmt, ...);
|
|||
#define DEBUG_OUT() \
|
||||
pthread_mutex_lock(&debug_mutex); \
|
||||
printf("%8p - %s", pthread_self(), buf); \
|
||||
fflush(stdout); \
|
||||
pthread_mutex_unlock(&debug_mutex);
|
||||
|
||||
#else
|
||||
|
@ -140,11 +164,13 @@ static int debug_mutex_initialized = 1;
|
|||
static rb_thread_lock_t debug_mutex;
|
||||
|
||||
void
|
||||
thread_debug(const char *fmt, ...)
|
||||
rb_thread_debug(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
char buf[BUFSIZ];
|
||||
|
||||
if (!rb_thread_debug_enabled) return;
|
||||
|
||||
if (debug_mutex_initialized == 1) {
|
||||
debug_mutex_initialized = 0;
|
||||
native_mutex_initialize(&debug_mutex);
|
||||
|
@ -2383,6 +2409,10 @@ Init_Thread(void)
|
|||
rb_define_singleton_method(rb_cThread, "critical=", rb_thread_s_critical, 1);
|
||||
rb_define_singleton_method(rb_cThread, "abort_on_exception", rb_thread_s_abort_exc, 0);
|
||||
rb_define_singleton_method(rb_cThread, "abort_on_exception=", rb_thread_s_abort_exc_set, 1);
|
||||
#if THREAD_DEBUG < 0
|
||||
rb_define_singleton_method(rb_cThread, "DEBUG", rb_thread_s_debug, 0);
|
||||
rb_define_singleton_method(rb_cThread, "DEBUG=", rb_thread_s_debug_set, 1);
|
||||
#endif
|
||||
|
||||
rb_define_method(rb_cThread, "raise", thread_raise_m, -1);
|
||||
rb_define_method(rb_cThread, "join", thread_join_m, -1);
|
||||
|
|
Загрузка…
Ссылка в новой задаче