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


C++ rb_thread_current函数代码示例

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


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

示例1: acquire_lock

/*
 * Holds thread execution while another thread is active.
 *
 * Thanks to this, all threads are "frozen" while the user is typing commands.
 */
void
acquire_lock(debug_context_t * dc)
{
  while ((!NIL_P(locker) && locker != rb_thread_current())
         || CTX_FL_TEST(dc, CTX_FL_SUSPEND))
  {
    add_to_locked(rb_thread_current());
    rb_thread_stop();

    if (CTX_FL_TEST(dc, CTX_FL_SUSPEND))
      CTX_FL_SET(dc, CTX_FL_WAS_RUNNING);
  }

  locker = rb_thread_current();
}
开发者ID:Achieve-development,项目名称:achieve,代码行数:20,代码来源:threads.c

示例2: rb_RPRuby_Sender_Kernel_each_backtrace_frame

/*
 * call-seq:
 *   Kernel.each_backtrace_frame( & block )
 *
 * Return array of hashes with object and method frame information for backtrace.
 * Specifying number_of_frames will cause only the last number_of_frames to be returned.
 * Kernel.backtrace returns all frames including the current context (__method__/__callee__).
 */
VALUE rb_RPRuby_Sender_Kernel_each_backtrace_frame(  int    argc,
                          VALUE*  args,
                          VALUE  rb_self )  {

  rb_thread_t*      c_thread          = (rb_thread_t *)RTYPEDDATA_DATA(rb_thread_current());
  //  Get the current frame - we're doing a backtrace, so our current working frame to start is the first previous thread
  rb_control_frame_t*    c_current_context_frame    = RUBY_VM_PREVIOUS_CONTROL_FRAME( RUBY_VM_PREVIOUS_CONTROL_FRAME( c_thread->cfp ) );
  
  //  c_top_of_control_frame describes the top edge of the stack trace
  //  set c_top_of_control_frame to the first frame in <main>
    rb_control_frame_t*    c_top_of_control_frame  =  RUBY_VM_NEXT_CONTROL_FRAME( RUBY_VM_NEXT_CONTROL_FRAME( (void *)( c_thread->stack + c_thread->stack_size ) ) );
  
  VALUE  rb_stored_backtrace_array  =  Qnil;
  
  //  if we were passed a stored backtrace array, use it
  if (  argc == 1
    &&  TYPE( args[ 0 ] ) == T_ARRAY )  {
    rb_stored_backtrace_array  =  args[ 0 ];
  }
        
  //  for each control frame:
    while ( c_current_context_frame < c_top_of_control_frame ) {

    VALUE  rb_frame_hash;
    //  if we are using a stored backtrace we don't need to ask for a new hash
    if ( rb_stored_backtrace_array == Qnil )  {
      rb_frame_hash  =  rb_RPRuby_Sender_Kernel_internal_backtraceHashForControlFrame(  & c_current_context_frame );
    }
    else {
      rb_frame_hash  =  rb_ary_shift( rb_stored_backtrace_array );
    }

    if ( rb_frame_hash == Qnil )  {
      break;
    }
    
    //  if we try to iterate using an Enumerator we will lose our context
    if ( ! rb_block_given_p() )  {
      
      //  we solve this by assuming that the desired context is the moment when each_backtrace_frame is called
      //  this allows us to store the backtrace and iterate it as we want
      //  the only downside is that we have to get the entire backtrace first in order to store it
      rb_stored_backtrace_array  =  rb_RPRuby_Sender_Kernel_backtrace(  0,
                                        NULL,
                                        rb_self );
    
      RETURN_ENUMERATOR( rb_self, 1, & rb_stored_backtrace_array );
    }
    
    //  otherwise, yield the block
    rb_yield( rb_frame_hash );
    
    //  only move the frame if we are not using a stored backtrace
    if ( rb_stored_backtrace_array == Qnil )  {
      c_current_context_frame = RUBY_VM_PREVIOUS_CONTROL_FRAME( c_current_context_frame );    
    }
  }
  
  return Qnil;
}
开发者ID:RidiculousPower,项目名称:sender,代码行数:68,代码来源:rb_Kernel.c

示例3: queue_do_pop

static VALUE
queue_do_pop(VALUE self, int should_block)
{
    struct waiting_delete args;
    args.waiting = GET_QUEUE_WAITERS(self);
    args.th	 = rb_thread_current();

    while (queue_length(self) == 0) {
	if (!should_block) {
	    rb_raise(rb_eThreadError, "queue empty");
	}
	else if (queue_closed_p(self)) {
	    return queue_closed_result(self);
	}
	else {
	    assert(queue_length(self) == 0);
	    assert(queue_closed_p(self) == 0);

	    rb_ary_push(args.waiting, args.th);
	    rb_ensure(queue_sleep, (VALUE)0, queue_delete_from_waiting, (VALUE)&args);
	}
    }

    return rb_ary_shift(GET_QUEUE_QUE(self));
}
开发者ID:hayaken8112,项目名称:.emacs.d,代码行数:25,代码来源:thread_sync.c

示例4: rb_czmq_ctx_socket

static VALUE rb_czmq_ctx_socket(VALUE obj, VALUE type)
{
    VALUE socket;
    int socket_type;
    struct nogvl_socket_args args;
    zmq_sock_wrapper *sock = NULL;
    errno = 0;
    ZmqGetContext(obj);
    if (TYPE(type) != T_FIXNUM && TYPE(type) != T_SYMBOL) rb_raise(rb_eTypeError, "wrong socket type %s (expected Fixnum or Symbol)", RSTRING_PTR(rb_obj_as_string(type)));
    socket_type = FIX2INT((SYMBOL_P(type)) ? rb_const_get_at(rb_mZmq, rb_to_id(type)) : type);

    socket = Data_Make_Struct(rb_czmq_ctx_socket_klass(socket_type), zmq_sock_wrapper, rb_czmq_mark_sock, rb_czmq_free_sock_gc, sock);
    args.ctx = ctx->ctx;
    args.type = socket_type;
    sock->socket = (void*)rb_thread_blocking_region(rb_czmq_nogvl_socket_new, (void *)&args, RUBY_UBF_IO, 0);
    ZmqAssertObjOnAlloc(sock->socket, sock);
#ifndef HAVE_RB_THREAD_BLOCKING_REGION
    sock->str_buffer = zlist_new();
    sock->frame_buffer = zlist_new();
    sock->msg_buffer = zlist_new();
#endif
    sock->handler = Qnil;
    sock->flags = 0;
    sock->ctx = ctx->ctx;
    sock->verbose = FALSE;
    sock->state = ZMQ_SOCKET_PENDING;
    sock->endpoint = Qnil;
    sock->thread = rb_thread_current();
    sock->recv_timeout = ZMQ_SOCKET_DEFAULT_TIMEOUT;
    sock->send_timeout = ZMQ_SOCKET_DEFAULT_TIMEOUT;
    rb_obj_call_init(socket, 0, NULL);
    return socket;
}
开发者ID:gwright,项目名称:rbczmq,代码行数:33,代码来源:context.c

示例5: enable_line_trace_for_thread

/**
 * enable_line_trace_for_thread
 * Turn on line event trace for current thread. Also set a flag
 * "gcloud_line_trace_set" to Qtrue in current thread's thread variable.
 */
static VALUE
enable_line_trace_for_thread(VALUE self)
{
    VALUE current_thread;
    VALUE thread_variables_hash;
    VALUE line_trace_set;
    ID locals_id;
    ID line_trace_thread_id;
    VALUE line_trace_thread_flag;

    CONST_ID(locals_id, "locals");
    CONST_ID(line_trace_thread_id, "gcloud_line_trace_set");
    line_trace_thread_flag = ID2SYM(line_trace_thread_id);

    current_thread = rb_thread_current();
    thread_variables_hash = rb_ivar_get(current_thread, locals_id);
    line_trace_set = rb_hash_aref(thread_variables_hash, line_trace_thread_flag);

    if (!RTEST(line_trace_set)) {
        rb_thread_add_event_hook(current_thread, line_trace_callback, RUBY_EVENT_LINE, self);
        rb_hash_aset(thread_variables_hash, line_trace_thread_flag, Qtrue);
    }

    return Qnil;
}
开发者ID:GoogleCloudPlatform,项目名称:gcloud-ruby,代码行数:30,代码来源:tracer.c

示例6: disable_return_trace_for_thread

/**
 *  disable_return_trace_for_thread
 *  Turn off return events trace hook for a given thread. If no thread is given, it
 *  turns off line event trace hook in current thread. It only takes action if
 *  the thread has a thread variable "gcloud_return_trace_set" that's true.
 */
static VALUE
disable_return_trace_for_thread(VALUE thread)
{
    VALUE thread_variables_hash;
    VALUE return_trace_set;
    ID locals_id;
    ID return_trace_thread_id;
    VALUE return_trace_thread_flag;

    CONST_ID(locals_id, "locals");
    CONST_ID(return_trace_thread_id, "gcloud_return_trace_set");
    return_trace_thread_flag = ID2SYM(return_trace_thread_id);

    if (!RTEST(thread)) {
        thread = rb_thread_current();
    }
    thread_variables_hash = rb_ivar_get(thread, locals_id);
    return_trace_set = rb_hash_aref(thread_variables_hash, return_trace_thread_flag);

    if (RTEST(return_trace_set)) {
        rb_thread_remove_event_hook(thread, (rb_event_hook_func_t)return_trace_callback);
        rb_hash_aset(thread_variables_hash, return_trace_thread_flag, Qfalse);
    }

    return Qnil;
}
开发者ID:GoogleCloudPlatform,项目名称:gcloud-ruby,代码行数:32,代码来源:tracer.c

示例7: blocking_function_execute

static VALUE blocking_function_execute(blocking_region_arg_t *arg)
{
    oci8_svcctx_t *svcctx = arg->svcctx;
    void *(*func)(void *) = arg->func;
    void *data = arg->data;
    struct timeval tv;
    sword rv;

    tv.tv_sec = 0;
    tv.tv_usec = 10000;
    svcctx->executing_thread = rb_thread_current();
    while ((rv = (sword)(VALUE)func(data)) == OCI_STILL_EXECUTING) {
        rb_thread_wait_for(tv);
        if (tv.tv_usec < 500000)
            tv.tv_usec <<= 1;
    }
    if (rv == OCI_ERROR) {
        if (oci8_get_error_code(oci8_errhp) == 1013) {
            OCIReset(svcctx->base.hp.ptr, oci8_errhp);
            svcctx->executing_thread = Qnil;
            rb_raise(eOCIBreak, "Canceled by user request.");
        }
    }
    svcctx->executing_thread = Qnil;
    return rv;
}
开发者ID:josuecortes,项目名称:CheckinGT,代码行数:26,代码来源:oci8lib.c

示例8: frame_count

static VALUE frame_count(VALUE self)
{
  rb_thread_t *th;
  GetThreadPtr(rb_thread_current(), th);

  rb_control_frame_t *cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
  rb_control_frame_t *limit_cfp = (void *)(th->stack + th->stack_size);

  int i = 1;
  while (cfp < limit_cfp) {
    cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);

    if (cfp >= limit_cfp)
      return INT2FIX(i);

    // skip invalid frames
    if (!valid_frame_p(cfp, limit_cfp))
      cfp = find_valid_frame(cfp, limit_cfp);

    if (!cfp)
      break;

    i++;
  }

  return INT2FIX(i);
}
开发者ID:ottomatias,项目名称:discourse,代码行数:27,代码来源:binding_of_caller.c

示例9: lock_mutex

static VALUE
lock_mutex(Mutex *mutex)
{
    VALUE current;
    current = rb_thread_current();

    rb_thread_critical = 1;

    if (!MUTEX_LOCKED_P(mutex)) {
	mutex->owner = current;
    }
    else {
	do {
	    wait_list(&mutex->waiting);
	    rb_thread_critical = 1;
	    if (!MUTEX_LOCKED_P(mutex)) {
		mutex->owner = current;
		break;
	    }
	} while (mutex->owner != current);
    }

    rb_thread_critical = 0;
    return Qnil;
}
开发者ID:asimoov,项目名称:emscripted-ruby,代码行数:25,代码来源:thread.c

示例10: enable_return_trace_for_thread

/**
 * enable_return_trace_for_thread
 * Turn on return events trace for current thread. Also set a flag
 * "gcloud_return_trace_set" to Qtrue in current thread's thread variable.
 */
static VALUE
enable_return_trace_for_thread(VALUE self)
{
    VALUE current_thread;
    VALUE thread_variables_hash;
    VALUE return_trace_set;

    ID locals_id;
    ID return_trace_thread_id;
    VALUE return_trace_thread_flag;

    CONST_ID(locals_id, "locals");
    CONST_ID(return_trace_thread_id, "gcloud_return_trace_set");
    return_trace_thread_flag = ID2SYM(return_trace_thread_id);

    current_thread = rb_thread_current();
    thread_variables_hash = rb_ivar_get(current_thread, locals_id);
    return_trace_set = rb_hash_aref(thread_variables_hash, return_trace_thread_flag);

    if (!RTEST(return_trace_set)) {
        rb_thread_add_event_hook2(current_thread, (rb_event_hook_func_t)return_trace_callback, RETURN_TRACEPOINT_EVENTS, self, RUBY_EVENT_HOOK_FLAG_RAW_ARG | RUBY_EVENT_HOOK_FLAG_SAFE);
        rb_hash_aset(thread_variables_hash, return_trace_thread_flag, Qtrue);
    }

    return Qnil;
}
开发者ID:GoogleCloudPlatform,项目名称:gcloud-ruby,代码行数:31,代码来源:tracer.c

示例11: rb_enable_method_trace_for_thread

static VALUE
rb_enable_method_trace_for_thread(VALUE self)
{
    VALUE current_thread;
    VALUE thread_variables_hash;
    VALUE trace_set;
    VALUE evaluator;
    ID current_evaluator_id;
    ID locals_id;
    ID eval_trace_thread_id;
    VALUE eval_trace_thread_flag;

    CONST_ID(current_evaluator_id, "current");
    CONST_ID(locals_id, "locals");
    CONST_ID(eval_trace_thread_id, "gcloud_eval_trace_set");
    eval_trace_thread_flag = ID2SYM(eval_trace_thread_id);

    current_thread = rb_thread_current();
    thread_variables_hash = rb_ivar_get(current_thread, locals_id);
    trace_set = rb_hash_aref(thread_variables_hash, eval_trace_thread_flag);
    evaluator = rb_funcall(self, current_evaluator_id, 0);

    if (!RTEST(trace_set)) {
        rb_thread_add_event_hook2(current_thread, (rb_event_hook_func_t)eval_trace_callback, RUBY_EVENT_CALL | RUBY_EVENT_C_CALL, evaluator, RUBY_EVENT_HOOK_FLAG_RAW_ARG | RUBY_EVENT_HOOK_FLAG_SAFE);
        rb_hash_aset(thread_variables_hash, eval_trace_thread_flag, Qtrue);
    }

    return Qnil;
}
开发者ID:GoogleCloudPlatform,项目名称:gcloud-ruby,代码行数:29,代码来源:evaluator.c

示例12: kern_async

// default behavior of async (doesn't accept Symbol)
// call-seq:
//      async { }
//      async Proc.new
static VALUE
kern_async(int argc, VALUE *argv, VALUE self)
{
    VALUE obj;
    rb_proc_t *proc;
    rb_iseq_t *niseq;

    rb_scan_args(argc, argv, "01", &obj);
    if (!NIL_P(obj)) {
        if (!rb_obj_is_proc(obj)) {
            VALUE thread = rb_thread_current();
            rb_thread_t * th;
            TypedData_Get_Struct(thread, rb_thread_t, RTYPEDDATA_TYPE(thread), th);
            if (self == th->vm->top_self) {
                return mod_async(CLASS_OF(self), obj);
            } else {
                rb_raise(rb_eTypeError, "wrong argument type (expected Proc)");
            }
        }
    } else if (rb_block_given_p()) {
        obj = rb_block_proc();
    } else {
        rb_raise(rb_eArgError, "Proc or block is required");
    }

    proc = (rb_proc_t *)DATA_PTR(obj);

    // うーーー
    niseq = transform(obj);
    proc->block.iseq = niseq;

    return obj;
}
开发者ID:rhenium,项目名称:async-ruby,代码行数:37,代码来源:async.c

示例13: wait_list_inner

static VALUE
wait_list_inner(List *list)
{
    push_list(list, rb_thread_current());
    rb_thread_stop();
    return Qnil;
}
开发者ID:genki,项目名称:fastthread,代码行数:7,代码来源:fastthread.c

示例14: wait_list_cleanup

static VALUE
wait_list_cleanup(List *list)
{
    /* cleanup in case of spurious wakeups */
    remove_one(list, rb_thread_current());
    return Qnil;
}
开发者ID:genki,项目名称:fastthread,代码行数:7,代码来源:fastthread.c

示例15: dnssd_service_stop

static VALUE
dnssd_service_stop(VALUE self) {
  VALUE thread;
  DNSServiceRef *client;

  get(cDNSSDService, self, DNSServiceRef, client);

  RDATA(self)->data = NULL;

  if (client == NULL)
    rb_raise(eDNSSDError, "service is already stopped");

  thread = rb_ivar_get(self, dnssd_iv_thread);
  rb_ivar_set(self, dnssd_iv_continue, Qfalse);

  if (!NIL_P(thread) && thread != rb_thread_current()) {
    rb_thread_run(thread);
    rb_funcall(thread, dnssd_id_join, 0);
  }

  dnssd_service_free_client(client);

  rb_ivar_set(self, dnssd_iv_type, Qnil);

  return self;
}
开发者ID:brianwells,项目名称:dnssd,代码行数:26,代码来源:service.c


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