summaryrefslogtreecommitdiff
path: root/thread.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-05 05:04:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-07-05 05:04:41 +0000
commitb35d1e714c1df44b5346e35a6dc519da5e8de4d5 (patch)
treea810917b0517707971dc9f4f9bb5392f02fb2b52 /thread.c
parentfd4d1dde2f88547afadb8270143911adfd50d916 (diff)
* thread.c (rb_threadptr_exec_event_hooks): new function to
execute event hooks, with preserving errinfo. [ruby-core:24118] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23959 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'thread.c')
-rw-r--r--thread.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/thread.c b/thread.c
index 63706c9800..c6f9cea24f 100644
--- a/thread.c
+++ b/thread.c
@@ -3528,6 +3528,32 @@ set_threads_event_flags(int flag)
st_foreach(GET_VM()->living_threads, set_threads_event_flags_i, (st_data_t) flag);
}
+static inline void
+exec_event_hooks(const rb_event_hook_t *hook, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
+{
+ for (; hook; hook = hook->next) {
+ if (flag & hook->flag) {
+ (*hook->func)(flag, hook->data, self, id, klass);
+ }
+ }
+}
+
+void
+rb_threadptr_exec_event_hooks(rb_thread_t *th, rb_event_flag_t flag, VALUE self, ID id, VALUE klass)
+{
+ const VALUE errinfo = th->errinfo;
+ const rb_event_flag_t wait_event = th->event_flags;
+
+ if (self == rb_mRubyVMFrozenCore) return;
+ if (wait_event & flag) {
+ exec_event_hooks(th->event_hooks, flag, self, id, klass);
+ }
+ if (wait_event & RUBY_EVENT_VM) {
+ exec_event_hooks(th->vm->event_hooks, flag, self, id, klass);
+ }
+ th->errinfo = errinfo;
+}
+
void
rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
{