当前位置: 首页>>代码示例>>C++>>正文


C++ GC_WB函数代码示例

本文整理汇总了C++中GC_WB函数的典型用法代码示例。如果您正苦于以下问题:C++ GC_WB函数的具体用法?C++ GC_WB怎么用?C++ GC_WB使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GC_WB函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: enumerator_init_copy

/* :nodoc: */
static VALUE
enumerator_init_copy(VALUE obj, SEL sel, VALUE orig)
{
    struct enumerator *ptr0, *ptr1;

    ptr0 = enumerator_ptr(orig);
    if (ptr0->fib) {
	/* Fibers cannot be copied */
	rb_raise(rb_eTypeError, "can't copy execution context");
    }

    Data_Get_Struct(obj, struct enumerator, ptr1);

    if (!ptr1) {
	rb_raise(rb_eArgError, "unallocated enumerator");
    }

    GC_WB(&ptr1->obj, ptr0->obj);
    ptr1->sel = ptr0->sel;
    if (ptr0->args != 0) {
	GC_WB(&ptr1->args, ptr0->args);
    }
    ptr1->fib  = 0;

    return obj;
}
开发者ID:Sophrinix,项目名称:MacRuby,代码行数:27,代码来源:enumerator.c

示例2: rb_source_init

static VALUE
rb_source_init(VALUE self, SEL sel,
    VALUE type, VALUE handle, VALUE mask, VALUE queue)
{
    Check_Queue(queue);
    rb_source_t *src = RSource(self);
    src->source_enum = (source_enum_t) NUM2LONG(type);
    dispatch_source_type_t c_type = rb_source_enum2type(src->source_enum);
    assert(c_type != NULL);
    uintptr_t c_handle = NUM2UINT(rb_Integer(handle));
    unsigned long c_mask = NUM2LONG(mask);
    dispatch_queue_t c_queue = RQueue(queue)->queue;
    src->source = dispatch_source_create(c_type, c_handle, c_mask, c_queue);
    assert(src->source != NULL);

    rb_vm_block_t *block = get_prepared_block();
    GC_WB(&src->event_handler, block);
    GC_RETAIN(self); // apparently needed to ensure consistent counting
    dispatch_set_context(src->source, (void *)self);
    dispatch_source_set_event_handler_f(src->source, rb_source_event_handler);

    GC_WB(&src->handle, handle);
    if (rb_source_is_file(src) && rb_obj_is_kind_of(handle, rb_cIO)) {
        dispatch_source_set_cancel_handler_f(src->source,
          rb_source_close_handler);
    }
    rb_dispatch_resume(self, 0);
    return self;
}
开发者ID:JosephKu,项目名称:MacRuby,代码行数:29,代码来源:gcd.c

示例3: dup_block

static rb_vm_block_t *
dup_block(rb_vm_block_t *src_b)
{
    const size_t block_size = sizeof(rb_vm_block_t)
	    + (sizeof(VALUE *) * src_b->dvars_size);

    rb_vm_block_t *new_b = (rb_vm_block_t *)xmalloc(block_size);

    memcpy(new_b, src_b, block_size);
    new_b->proc = src_b->proc; // weak
    GC_WB(&new_b->parent_block, src_b->parent_block);
    GC_WB(&new_b->self, src_b->self);
    new_b->flags = src_b->flags & ~VM_BLOCK_ACTIVE;

    rb_vm_local_t *src_l = src_b->locals;
    rb_vm_local_t **new_l = &new_b->locals;
    while (src_l != NULL) {
	GC_WB(new_l, xmalloc(sizeof(rb_vm_local_t)));
	(*new_l)->name = src_l->name;
	(*new_l)->value = src_l->value;

	new_l = &(*new_l)->next;
	src_l = src_l->next;
    }
    *new_l = NULL;

    return new_b;
}
开发者ID:Hunter-Dolan,项目名称:MacRuby,代码行数:28,代码来源:dispatcher.cpp

示例4: rb_vm_get_method

rb_vm_method_t *
rb_vm_get_method(VALUE klass, VALUE obj, ID mid, int scope)
{
    SEL sel = 0;
    IMP imp = NULL;
    rb_vm_method_node_t *node = NULL;

    // TODO honor scope

    if (!rb_vm_lookup_method2((Class)klass, mid, &sel, &imp, &node)) {
	rb_print_undef(klass, mid, 0);
    }

    Class k, oklass = (Class)klass;
    while ((k = class_getSuperclass(oklass)) != NULL) {
	if (!rb_vm_lookup_method(k, sel, NULL, NULL)) {
	    break;
	}
	oklass = k;
    }

    Method method = class_getInstanceMethod((Class)klass, sel);
    assert(method != NULL);

    int arity;
    rb_vm_method_node_t *new_node;
    if (node == NULL) {
	arity = rb_method_getNumberOfArguments(method) - 2;
	new_node = NULL;
    }
    else {
	arity = rb_vm_arity_n(node->arity);
	new_node = (rb_vm_method_node_t *)xmalloc(sizeof(rb_vm_method_node_t));
	memcpy(new_node, node, sizeof(rb_vm_method_node_t));
    }

    rb_vm_method_t *m = (rb_vm_method_t *)xmalloc(sizeof(rb_vm_method_t));

    m->oclass = (VALUE)oklass;
    m->rclass = klass;
    GC_WB(&m->recv, obj);
    m->sel = sel;
    m->arity = arity;
    GC_WB(&m->node, new_node);

    // Let's allocate a static cache here, since a rb_vm_method_t must always
    // point to the method it was created from.
    struct mcache *c = (struct mcache *)xmalloc(sizeof(struct mcache));
    if (new_node == NULL) {
	fill_ocache(c, obj, oklass, imp, sel, method, arity);
    }
    else {
	fill_rcache(c, oklass, sel, new_node);
    }
    GC_WB(&m->cache, c);

    return m;
}
开发者ID:Hunter-Dolan,项目名称:MacRuby,代码行数:58,代码来源:dispatcher.cpp

示例5: name_err_mesg_new

/* :nodoc: */
static VALUE
name_err_mesg_new(VALUE obj, SEL sel, VALUE mesg, VALUE recv, VALUE method)
{
    VALUE *ptr = ALLOC_N(VALUE, 3);

    GC_WB(&ptr[0], mesg);
    GC_WB(&ptr[1], recv);
    GC_WB(&ptr[2], method);

    return Data_Wrap_Struct(rb_cNameErrorMesg, NULL, NULL, ptr);
}
开发者ID:1nueve,项目名称:MacRuby,代码行数:12,代码来源:error.c

示例6: imp_rhash_keyEnumerator

static void *
imp_rhash_keyEnumerator(void *rcv, SEL sel)
{
    NEWOBJ(keyenum, rb_hash_keyenum_t);
    keyenum->klass = rb_cRubyHashKeyEnumerator;
    GC_WB(&keyenum->hash, rcv);
    VALUE ary = rb_ary_new();
    st_foreach_safe(RHASH(rcv)->tbl, keys_i, (st_data_t)ary);
    GC_WB(&keyenum->keys, ary); 
    keyenum->pos = 0;
    return keyenum;
}
开发者ID:Jaharmi,项目名称:MacRuby,代码行数:12,代码来源:hash.c

示例7: binding_dup

static VALUE
binding_dup(VALUE self, SEL sel)
{
    VALUE bindval = binding_alloc(rb_cBinding);
    rb_vm_binding_t *src, *dst;
    GetBindingPtr(self, src);
    GetBindingPtr(bindval, dst);
    GC_WB(&dst->self, src->self);
    GC_WB(&dst->next, src->next);
    GC_WB(&dst->locals, src->locals);
    GC_WB(&dst->outer_stack, src->outer_stack);
    GC_WB(&dst->block, src->block);
    return bindval;
}
开发者ID:MSch,项目名称:MacRuby,代码行数:14,代码来源:proc.c

示例8: thgroup_s_alloc

static VALUE
thgroup_s_alloc(VALUE self, SEL sel)
{
    rb_thread_group_t *t = (rb_thread_group_t *)xmalloc(
	    sizeof(rb_thread_group_t));
    t->enclosed = false;
    GC_WB(&t->threads, rb_ary_new());
    OBJ_UNTRUST(t->threads);

    VALUE mutex = mutex_s_alloc(rb_cMutex, 0);
    mutex_initialize(mutex, 0);
    GC_WB(&t->mutex, mutex);

    return Data_Wrap_Struct(self, NULL, NULL, t);
}
开发者ID:1nueve,项目名称:MacRuby,代码行数:15,代码来源:thread.c

示例9: define_final

static VALUE
define_final(VALUE os, SEL sel, int argc, VALUE *argv)
{
    VALUE obj, block;

    rb_scan_args(argc, argv, "11", &obj, &block);
    if (argc == 1) {
	block = rb_block_proc();
    }
    else if (!rb_respond_to(block, rb_intern("call"))) {
	rb_raise(rb_eArgError, "wrong type argument %s (should be callable)",
		rb_obj_classname(block));
    }

    if (SPECIAL_CONST_P(obj)) {
	rb_raise(rb_eArgError, "immediate types are not finalizable");
    }

    rb_vm_finalizer_t *finalizer = rb_objc_get_associative_ref((void *)obj,
	    &finalizer_key);
    if (finalizer == NULL) {
	finalizer = (rb_vm_finalizer_t *)
	    rb_objc_newobj(sizeof(rb_vm_finalizer_t *));
	finalizer->klass = rb_cFinalizer;
	finalizer->objid = rb_obj_id(obj, 0);
	GC_WB(&finalizer->finalizers, rb_ary_new());
	rb_objc_set_associative_ref((void *)obj, &finalizer_key, finalizer);
	rb_vm_register_finalizer(finalizer); 
    }

    rb_ary_push(finalizer->finalizers, block);
    
    // For RubySpec conformance.
    return rb_ary_new3(2, INT2FIX(rb_safe_level()), block);
}
开发者ID:1nueve,项目名称:MacRuby,代码行数:35,代码来源:gc.c

示例10: rb_mutex_lock

static VALUE
rb_mutex_lock(VALUE self, SEL sel)
{
    rb_vm_thread_t *current = GetThreadPtr(rb_vm_current_thread());
    rb_vm_mutex_t *m = GetMutexPtr(self);
    rb_vm_thread_status_t prev_status;
    if (m->thread == current) {
	rb_raise(rb_eThreadError, "deadlock; recursive locking");
    }

    prev_status = current->status;
    if (current->status == THREAD_ALIVE) {
	current->status = THREAD_SLEEP;
    }
    current->wait_for_mutex_lock = true;
    pthread_assert(pthread_mutex_lock(&m->mutex));
    current->wait_for_mutex_lock = false;
    current->status = prev_status;
    m->thread = current;
    if (current->mutexes == Qnil) {
	GC_WB(&current->mutexes, rb_ary_new());
	OBJ_UNTRUST(current->mutexes);
    }
    rb_ary_push(current->mutexes, self);

    return self;
}
开发者ID:1nueve,项目名称:MacRuby,代码行数:27,代码来源:thread.c

示例11: proc_dup

static VALUE
proc_dup(VALUE self)
{
    VALUE procval = rb_proc_alloc(rb_cProc);
    rb_proc_t *src, *dst;
    GetProcPtr(self, src);
    GetProcPtr(procval, dst);

    dst->block = src->block;
    GC_WB(&dst->block.proc, procval);
    GC_WB(&dst->envval, src->envval);
    dst->safe_level = src->safe_level;
    dst->is_lambda = src->is_lambda;

    return procval;
}
开发者ID:Sophrinix,项目名称:iphone-macruby,代码行数:16,代码来源:proc.c

示例12: rb_yaml_parser_set_input

static VALUE
rb_yaml_parser_set_input(VALUE self, SEL sel, VALUE input)
{
    rb_yaml_parser_t *rbparser = RYAMLParser(self);
    yaml_parser_t *parser = &rbparser->parser;

    if (!NIL_P(input)) {
	assert(parser != NULL);
	if (TYPE(input) == T_STRING) {
	    const char * instring = RSTRING_PTR(input);
	    yaml_parser_set_input_string(parser,
		    (const unsigned char *)(instring),
		    strlen(instring));			
	}
	else if (TYPE(input) == T_FILE) {
	    yaml_parser_set_input(parser, rb_yaml_io_read_handler,
		    (void *)input);
	}
	else {
	    rb_raise(rb_eArgError, "invalid input for YAML parser: %s",
		    rb_obj_classname(input));
	}
    }

    GC_WB(&rbparser->input, input);
    return input;
}
开发者ID:alloy,项目名称:MacRuby,代码行数:27,代码来源:rubyext.c

示例13: rb_yaml_emitter_set_output

static VALUE
rb_yaml_emitter_set_output(VALUE self, SEL sel, VALUE output)
{
    rb_yaml_emitter_t *remitter = RYAMLEmitter(self);
    GC_WB(&remitter->output, output);
    yaml_emitter_t *emitter = &remitter->emitter;
    if (!NIL_P(output)) {
	switch (TYPE(output)) {
	    case T_FILE:
		yaml_emitter_set_output(emitter, rb_yaml_io_output_handler,
			(void *)output);
		break;

	    case T_STRING:
		yaml_emitter_set_output(emitter, rb_yaml_str_output_handler,
			(void *)output);
		break;

	    default:
		rb_raise(rb_eArgError, "unsupported YAML output type %s",
			rb_obj_classname(output));
	}	
    }
    return output;
}
开发者ID:alloy,项目名称:MacRuby,代码行数:25,代码来源:rubyext.c

示例14: proc_binding

/*
 *  call-seq:
 *     prc.binding    => binding
 *  
 *  Returns the binding associated with <i>prc</i>. Note that
 *  <code>Kernel#eval</code> accepts either a <code>Proc</code> or a
 *  <code>Binding</code> object as its second parameter.
 *     
 *     def fred(param)
 *       proc {}
 *     end
 *     
 *     b = fred(99)
 *     eval("param", b.binding)   #=> 99
 */
static VALUE
proc_binding(VALUE self, SEL sel)
{
    rb_vm_block_t *block;
    GetProcPtr(self, block);

    rb_vm_binding_t *binding = (rb_vm_binding_t *)xmalloc(
	    sizeof(rb_vm_binding_t));

    binding->block = NULL;
    GC_WB(&binding->self, block->self);
    GC_WB(&binding->locals, block->locals);
    binding->outer_stack = NULL;

    return Data_Wrap_Struct(rb_cBinding, NULL, NULL, binding);
}
开发者ID:MSch,项目名称:MacRuby,代码行数:31,代码来源:proc.c

示例15: rb_fd_init

void
rb_fd_init(volatile rb_fdset_t *fds)
{
    fds->maxfd = 0;
    GC_WB(&fds->fdset, ALLOC(fd_set));
    FD_ZERO(fds->fdset);
}
开发者ID:alloy,项目名称:mr-experimental,代码行数:7,代码来源:thread.c


注:本文中的GC_WB函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。