static VALUE thgroup_add(VALUE group, SEL sel, VALUE thread) { rb_vm_thread_t *t = GetThreadPtr(thread); rb_thread_group_t *new_tg = GetThreadGroupPtr(group); if (new_tg->enclosed) { rb_raise(rb_eThreadError, "can't move from the enclosed thread group"); } if (t->group != Qnil) { rb_thread_group_t *old_tg = GetThreadGroupPtr(t->group); if (old_tg->enclosed) { rb_raise(rb_eThreadError, "can't move from the enclosed thread group"); } rb_ary_delete(old_tg->threads, thread); } rb_ary_push(new_tg->threads, thread); GC_WB(&t->group, group); return group; }
static VALUE thgroup_add_m(VALUE group, VALUE thread, bool check_enclose) { if (OBJ_FROZEN(group)) { rb_raise(rb_eThreadError, "can't move to the frozen thread group"); } rb_vm_thread_t *t = GetThreadPtr(thread); rb_thread_group_t *new_tg = GetThreadGroupPtr(group); if (new_tg->enclosed && check_enclose) { rb_raise(rb_eThreadError, "can't move from the enclosed thread group"); } if (t->group != Qnil) { if (OBJ_FROZEN(t->group)) { rb_raise(rb_eThreadError, "can't move from the frozen thread group"); } rb_thread_group_t *old_tg = GetThreadGroupPtr(t->group); if (old_tg->enclosed && check_enclose) { rb_raise(rb_eThreadError, "can't move from the enclosed thread group"); } thgroup_lock(old_tg); rb_ary_delete(old_tg->threads, thread); thgroup_unlock(old_tg); } thgroup_lock(new_tg); rb_ary_push(new_tg->threads, thread); thgroup_unlock(new_tg); GC_WB(&t->group, group); return group; }
void rb_thread_remove_from_group(VALUE thread) { rb_vm_thread_t *t = GetThreadPtr(thread); if (t->group != Qnil) { rb_thread_group_t *tg = GetThreadGroupPtr(t->group); thgroup_lock(tg); if (rb_ary_delete(tg->threads, thread) != thread) { printf("trying to remove a thread (%p) from a group that doesn't "\ "contain it\n", (void *)thread); abort(); } thgroup_unlock(tg); t->group = Qnil; } }
static VALUE thgroup_enclosed_p(VALUE group) { return GetThreadGroupPtr(group)->enclosed ? Qtrue : Qfalse; }
static VALUE thgroup_enclose(VALUE group, SEL sel) { GetThreadGroupPtr(group)->enclosed = true; return group; }
static VALUE thgroup_list(VALUE group, SEL sel) { return GetThreadGroupPtr(group)->threads; }