yarv-diff:397
From: ko1 atdot.net
Date: 4 Oct 2006 23:05:55 +0900
Subject: [yarv-diff:397] r564 - branches/parallel
Author: ko1
Date: 2006-10-04 23:05:55 +0900 (Wed, 04 Oct 2006)
New Revision: 564
Modified:
branches/parallel/ChangeLog
branches/parallel/thread.c
branches/parallel/thread.h
branches/parallel/thread_pthread.h
branches/parallel/thread_win32.h
branches/parallel/yarv.h
branches/parallel/yarvcore.c
Log:
* thread.c : remove pthread depend code (and move to thread_pthread.c)
* thread.h : ditto
* thread_pthread.h : ditto
* yarv.h : ditto
* yarvcore.c : ditto
* thread_win32.h : add win32 support (now trying)
Modified: branches/parallel/ChangeLog
===================================================================
--- branches/parallel/ChangeLog 2006-10-03 11:12:07 UTC (rev 563)
+++ branches/parallel/ChangeLog 2006-10-04 14:05:55 UTC (rev 564)
@@ -4,6 +4,21 @@
# from Mon, 03 May 2004 01:24:19 +0900
#
+2006-10-04(Wed) 23:01:58 +0900 Koichi Sasada <ko1 atdot.net>
+
+ * thread.c : remove pthread depend code (and move to thread_pthread.c)
+
+ * thread.h : ditto
+
+ * thread_pthread.h : ditto
+
+ * yarv.h : ditto
+
+ * yarvcore.c : ditto
+
+ * thread_win32.h : add win32 support (now trying)
+
+
2006-10-03(Tue) 20:10:19 +0900 Koichi Sasada <ko1 atdot.net>
* thread.h : added
Modified: branches/parallel/thread.c
===================================================================
--- branches/parallel/thread.c 2006-10-03 11:12:07 UTC (rev 563)
+++ branches/parallel/thread.c 2006-10-04 14:05:55 UTC (rev 564)
@@ -78,6 +78,10 @@
static void yarv_set_interrupt_function(yarv_thread_t *th, yarv_interrupt_function_t *func);
static void yarv_clear_interrupt_function(yarv_thread_t *th);
+static int rb_thread_blocking_start(yarv_thread_t *th,
+ yarv_interrupt_function_t *func);
+static void rb_thread_blocking_end(yarv_thread_t *th);
+
#if THREAD_DEBUG
void thread_debug(const char *fmt, ...);
#else
@@ -146,8 +150,8 @@
} while (0)
-static void __attribute__((destructor))
- pr_show(void)
+static void
+pr_show(void)
{
if (getenv("RUBY_SHOW_PROFILE")) {
fprintf(stderr, "profile_conflict: %d, %d, %d\n",
@@ -432,7 +436,6 @@
rb_thread_global_lock_release(th);
}
-
VALUE th_eval_body(yarv_thread_t *th);
static void
@@ -1686,7 +1689,7 @@
FD_SET(fd, &set);
thread_debug("rb_thread_wait_fd (%d)\n", fd);
while (result <= 0) {
- BLOCKING_RANGE(th, interrupt_using_posix_signal, {
+ BLOCKING_RANGE(th, io_interrupt_function, {
result = select(fd + 1, &set, 0, 0, 0);
});
}
@@ -1705,7 +1708,7 @@
thread_debug("rb_thread_fd_writable (%d)\n", fd);
while (result <= 0) {
- BLOCKING_RANGE(th, interrupt_using_posix_signal, {
+ BLOCKING_RANGE(th, io_interrupt_function, {
result = select(fd + 1, 0, &set, 0, 0);
});
}
@@ -1765,7 +1768,7 @@
n = -1;
lerrno = EINTR;
- BLOCKING_RANGE(th, interrupt_using_posix_signal, {
+ BLOCKING_RANGE(th, io_interrupt_function, {
n = select(max, read, write, except, tvp);
lerrno = errno;
});
@@ -2385,7 +2388,8 @@
}
make_timer_thread();
- atexit(show_func);
+ //atexit(show_func);
+ //atexit(pr_show);
#if HAVE_SCHED_SETAFFINITY
if (getenv("RUBY_MAX_CPU")) {
Modified: branches/parallel/thread.h
===================================================================
--- branches/parallel/thread.h 2006-10-03 11:12:07 UTC (rev 563)
+++ branches/parallel/thread.h 2006-10-04 14:05:55 UTC (rev 564)
@@ -10,4 +10,30 @@
#error "unsupported thread type"
#endif
+#define FGLOCK(lock) native_fg_lock(lock)
+#define FGUNLOCK(lock) native_fg_unlock(lock)
+#define FGLOCK_RANGE(lock, body) \
+ { FGLOCK(lock); { body; } FGUNLOCK(lock); }
+
+#define GL_LOCK_RANGE(th_, body) do { \
+ int __locked = rb_thread_global_lock_acquire(th_); \
+ { body; } ; \
+ if (__locked) rb_thread_global_lock_release(th_); \
+} while (0)
+
+#define GL_UNLOCK_RANGE(th_, body) do { \
+ int __freeed = rb_thread_global_lock_release(th_); \
+ { body; } ;\
+ if (__freeed) rb_thread_global_lock_acquire(th_); \
+} while (0)
+
+#define BLOCKING_RANGE(th, func, body) do { \
+ yarv_thread_t *__th = th; \
+ if (rb_thread_blocking_start(__th, func) != 0) { \
+ body; \
+ rb_thread_blocking_end(__th); \
+ } \
+ YARV_CHECK_INTS_TH(__th); \
+} while (0)
+
#endif /* THREAD_H_INCLUDED */
Modified: branches/parallel/thread_pthread.h
===================================================================
--- branches/parallel/thread_pthread.h 2006-10-03 11:12:07 UTC (rev 563)
+++ branches/parallel/thread_pthread.h 2006-10-04 14:05:55 UTC (rev 564)
@@ -4,6 +4,8 @@
#include <pthread.h>
+#define TLS_SPECIFIER __thread
+
typedef pthread_t yarv_thread_id_t;
typedef pthread_mutex_t yarv_thread_lock_t;
typedef pthread_cond_t yarv_thread_cond_t;
@@ -12,6 +14,7 @@
void native_mutex_unlock(yarv_thread_lock_t *lock);
void native_mutex_destroy(yarv_thread_lock_t *lock);
int native_mutex_trylock(yarv_thread_lock_t *lock);
+void native_mutex_initialize(pthread_mutex_t *lock)
void native_cond_init(yarv_thread_cond_t *cond);
void native_cond_destroy(yarv_thread_cond_t *cond);
@@ -74,32 +77,6 @@
void native_fglock_init(yarv_thread_fglock_t *fglock);
void native_fglock_destroy(yarv_thread_fglock_t *fglock);
-#define FGLOCK(lock) native_fg_lock(lock)
-#define FGUNLOCK(lock) native_fg_unlock(lock)
-#define FGLOCK_RANGE(lock, body) \
- { FGLOCK(lock); { body; } FGUNLOCK(lock); }
-
-#define GL_LOCK_RANGE(th_, body) do { \
- int __locked = rb_thread_global_lock_acquire(th_); \
- { body; } ; \
- if (__locked) rb_thread_global_lock_release(th_); \
-} while (0)
-
-#define GL_UNLOCK_RANGE(th_, body) do { \
- int __freeed = rb_thread_global_lock_release(th_); \
- { body; } ;\
- if (__freeed) rb_thread_global_lock_acquire(th_); \
-} while (0)
-
-#define BLOCKING_RANGE(th, func, body) do { \
- yarv_thread_t *__th = th; \
- if (rb_thread_blocking_start(__th, func) != 0) { \
- body; \
- rb_thread_blocking_end(__th); \
- } \
- YARV_CHECK_INTS_TH(__th); \
-} while (0)
-
#endif /* THREAD_PTHREAD_H_INCLUDED */
@@ -171,7 +148,8 @@
thread_debug("native_fglock_destroy: %p\n", lock);
}
-void native_mutex_destroy(yarv_thread_lock_t *lock)
+void
+native_mutex_destroy(yarv_thread_lock_t *lock)
{
int r = pthread_mutex_destroy(lock);
if (r != 0) {
@@ -230,10 +208,6 @@
static void yarv_add_repeat_interrupt_func(yarv_thread_t *th,
yarv_interrupt_function_t *func);
static void yarv_remove_signal_thread_list(yarv_thread_t *th);
-static int rb_thread_blocking_start(yarv_thread_t *th,
- yarv_interrupt_function_t *func);
-static void rb_thread_blocking_end(yarv_thread_t *th);
-
static yarv_thread_fglock_t signal_thread_list_lock;
static void
@@ -459,6 +433,7 @@
yarv_add_repeat_interrupt_func(th, interrupt_using_posix_signal_i);
thread_debug("interrupt_using_posix_signal: register\n");
}
+#define io_interrupt_function interrupt_using_posix_signal
static void
native_sleep(yarv_thread_t *th, struct timeval *tv)
Modified: branches/parallel/thread_win32.h
===================================================================
--- branches/parallel/thread_win32.h 2006-10-03 11:12:07 UTC (rev 563)
+++ branches/parallel/thread_win32.h 2006-10-04 14:05:55 UTC (rev 564)
@@ -8,14 +8,31 @@
WINBASEAPI BOOL WINAPI
TryEnterCriticalSection(IN OUT LPCRITICAL_SECTION lpCriticalSection);
+#define TLS_SPECIFIER __declspec( thread )
+
typedef HANDLE yarv_thread_id_t;
typedef CRITICAL_SECTION yarv_thread_lock_t;
+typedef CRITICAL_SECTION yarv_thread_fglock_t;
+typedef HANDLE yarv_thread_cond_t;
int native_mutex_lock(yarv_thread_lock_t *);
int native_mutex_unlock(yarv_thread_lock_t *);
int native_mutex_trylock(yarv_thread_lock_t *);
void native_mutex_initialize(yarv_thread_lock_t *);
+void native_mutex_destroy(yarv_thread_lock_t *);
+void native_cond_init(yarv_thread_cond_t *cond);
+void native_cond_destroy(yarv_thread_cond_t *cond);
+void native_cond_signal(yarv_thread_cond_t *cond);
+void native_cond_broadcast(yarv_thread_cond_t *cond);
+void native_cond_wait(yarv_thread_cond_t *cond, yarv_thread_lock_t *lock);
+
+#define native_fg_lock native_mutex_lock
+#define native_fg_unlock native_mutex_unlock
+#define native_fg_trylock native_mutex_trylock
+#define native_fglock_init native_mutex_initialize
+#define native_fglock_destroy native_mutex_destroy
+
typedef struct native_thread_data_struct {
HANDLE interrupt_event;
} native_thread_data_t;
@@ -28,6 +45,8 @@
#ifdef THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION
+#define io_interrupt_function 0
+
#include <process.h>
#define WIN32_WAIT_TIMEOUT 10 /* 10 ms */
@@ -120,8 +139,7 @@
msec = INFINITE;
}
- GVL_UNLOCK_BEGIN();
- {
+ BLOCKING_RANGE(th, 0, {
DWORD ret;
int status = th->status;
th->status = THREAD_STOPPED;
@@ -131,8 +149,7 @@
thread_debug("native_sleep done (%d)\n", ret);
th->interrupt_function = 0;
th->status = status;
- }
- GVL_UNLOCK_END();
+ });
}
int
@@ -214,6 +231,60 @@
#endif
}
+void
+native_mutex_destroy(yarv_thread_lock_t *lock)
+{
+#if USE_WIN32MUTEX
+ CloseHandle(lock);
+#else
+ DeleteCriticalSection(lock);
+#endif
+}
+
+void
+native_cond_init(yarv_thread_cond_t *cond)
+{
+ *cond = CreateEvent(0, FALSE, FALSE, 0);
+ if (*cond == 0) {
+ rb_bug("native_cond_init: error");
+ }
+}
+
+void
+native_cond_destroy(yarv_thread_cond_t *cond)
+{
+ if (CloseHandle(*cond) == 0) {
+ rb_bug("native_cond_destroy: error");
+ }
+}
+
+void
+native_cond_signal(yarv_thread_cond_t *cond)
+{
+ if (SetEvent(cond) == 0) {
+ rb_bug("native_cond_signal: error");
+ }
+}
+
+void
+native_cond_broadcast(yarv_thread_cond_t *cond)
+{
+ if (SetEvent(cond) == 0) {
+ rb_bug("native_cond_broadcast: error");
+ }
+}
+
+void
+native_cond_wait(yarv_thread_cond_t *cond, yarv_thread_lock_t *lock)
+{
+ /* TODO: dangrous */
+ native_mutex_unlock(lock);
+ if (WaitForSingleObject(lock, INFINITE) != WAIT_OBJECT_0) {
+ rb_bug("native_cond_wait: error");
+ }
+ native_mutex_lock(lock);
+}
+
NOINLINE(static int
thread_start_func_2(yarv_thread_t *th, VALUE *stack_start));
void static thread_cleanup_func(void *th_ptr);
@@ -314,6 +385,14 @@
}
static void
+timer_thread_join(void)
+{
+ if (WaitForSingleObject(timer_thread_handle, INFINITE) != WAIT_OBJECT_0) {
+ rb_bug("timer_thread_join: error");
+ }
+}
+
+static void
make_timer_thread()
{
if (timer_thread_handle == 0) {
Modified: branches/parallel/yarv.h
===================================================================
--- branches/parallel/yarv.h 2006-10-03 11:12:07 UTC (rev 563)
+++ branches/parallel/yarv.h 2006-10-04 14:05:55 UTC (rev 564)
@@ -57,12 +57,24 @@
/**********************************************************/
#elif YARV_THREAD_MODEL == 3
-extern __thread yarv_thread_t *yarvCurrentThread;
+
+#if defined(__GNUC__)
+extern TLS_SPECIFIER yarv_thread_t *yarvCurrentThread;
extern yarv_vm_t *theYarvVM;
#define GET_VM() theYarvVM
#define GET_THREAD() yarvCurrentThread
+#elif defined(_WIN32)
+extern TLS_SPECIFIER yarv_thread_t *yarvCurrentThread;
+extern yarv_vm_t *theYarvVM;
+#define GET_VM() theYarvVM
+#define GET_THREAD() yarvCurrentThread
+
+#else
+#error "Does not support Parallel Ruby on this platform"
+#endif
+
static inline void
yarv_set_current_running_thread(yarv_thread_t *th)
{
Modified: branches/parallel/yarvcore.c
===================================================================
--- branches/parallel/yarvcore.c 2006-10-03 11:12:07 UTC (rev 563)
+++ branches/parallel/yarvcore.c 2006-10-04 14:05:55 UTC (rev 564)
@@ -77,7 +77,12 @@
/* YARVCore */
/************/
-__thread yarv_thread_t *yarvCurrentThread = 0;
+#if YARV_THREAD_MODEL == 3
+TLS_SPECIFIER yarv_thread_t *yarvCurrentThread = 0;
+#else
+yarv_thread_t *yarvCurrentThread = 0;
+#endif
+
yarv_vm_t *theYarvVM = 0;
static VALUE yarvVMArray = Qnil;
--
ML: yarv-diff quickml.atdot.net
Info: http://www.atdot.net/~ko1/quickml