예제 #1
0
파일: map.c 프로젝트: bigdatafly/torch-ipc
int map_join(lua_State *L) {
   int rc = 0;
   int err_rc = -1;
   map_t *map = (map_t *)lua_touserdata(L, 1);
   for (uint32_t i = 0; i < map->num_threads; i++) {
      if (map->threads[i].rb) {
         int ret = pthread_join(map->threads[i].thread, NULL);
         if (ret) return LUA_HANDLE_ERROR(L, ret);
         if (map->threads[i].ret) {
            err_rc = rc;
         }
         while (ringbuffer_peek(map->threads[i].rb)) {
            rb_load(L, map->threads[i].rb);
            rc++;
         }
         ringbuffer_destroy(map->threads[i].rb);
      }
   }
   free(map->threads);
   map->threads = NULL;
   map->num_threads = 0;
   if (err_rc >= 0) {
      return LUA_HANDLE_ERROR_STR(L, lua_tostring(L, err_rc - rc));
   }
   return rc;
}
예제 #2
0
파일: load.c 프로젝트: Sophrinix/MacRuby
static VALUE
rb_f_load(VALUE rcv, SEL sel, int argc, VALUE *argv)
{
    VALUE fname, wrap;

    rb_scan_args(argc, argv, "11", &fname, &wrap);
    rb_load(fname, RTEST(wrap));
    return Qtrue;
}
예제 #3
0
void
rb_load_protect(VALUE fname, int wrap, int *state)
{
    int status;

    PUSH_TAG();
    if ((status = EXEC_TAG()) == 0) {
	rb_load(fname, wrap);
    }
    POP_TAG();
    if (state)
	*state = status;
}
예제 #4
0
파일: map.c 프로젝트: bigdatafly/torch-ipc
int map_check_errors(lua_State *L) {
   map_t *map = (map_t *)lua_touserdata(L, 1);
   for (uint32_t i = 0; i < map->num_threads; i++) {
      if (map->threads[i].ret) {
         pthread_join(map->threads[i].thread, NULL);
         while (ringbuffer_peek(map->threads[i].rb)) {
            rb_load(L, map->threads[i].rb);
         }
         ringbuffer_destroy(map->threads[i].rb);
         map->threads[i].rb = NULL;
         return LUA_HANDLE_ERROR_STR(L, lua_tostring(L, -1));
      }
   }
   return 0;
}
예제 #5
0
파일: map.c 프로젝트: bigdatafly/torch-ipc
static void* thread_func(void *arg) {
#ifdef _OPENMP
   // prevent MKL/BLAS from crashing on the reader threads
   // its use of open-mp eats up way too many threads
   omp_set_num_threads(1);
#endif
   map_thread_t *map_thread = (map_thread_t *)arg;
   lua_State *L = luaL_newstate();
   if (_ipc_static_init_thread) {
      _ipc_static_init_thread(L);
   } else {
      luaL_openlibs(L);
   }
   // in order to deserialize arguments we need torch and libipc
   // TODO: detect these on the main thread when serializing arguments
   int top = lua_gettop(L);
   if (luaL_loadstring(L, "require 'torch'; require 'libipc'; pcall(require, 'twutil')")) {
      lua_close(L);
      return NULL;
   }
   map_thread->ret = lua_pcall(L, 0, 0, 0);
   if (map_thread->ret) {
      fprintf(stderr, "WARN: ipc.map thread pcall failed: %s\n", lua_tostring(L, -1));
   } else {
      top = lua_gettop(L);
      int i = 0;
      while (ringbuffer_peek(map_thread->rb)) {
         rb_load(L, map_thread->rb);
         i++;
      }
      map_thread->ret = lua_pcall(L, i - 1, LUA_MULTRET, 0);
      if (map_thread->ret) {
         fprintf(stderr, "WARN: ipc.map thread pcall failed: %s\n", lua_tostring(L, -1));
      }
   }
   int k = lua_gettop(L) - top;
   for (int i = 1; i <= k; i++) {
      int ret = rb_save_with_growth(L, top + i, map_thread->rb);
      if (ret) {
         fprintf(stderr, "WARN: ipc.map thread failed to write results: %s\n", strerror(-ret));
         map_thread->ret = ret;
         break;
      }
   }
   lua_close(L);
   return 0;
}
예제 #6
0
파일: cliser.c 프로젝트: hardiku/torch-ipc
static int sock_recv_msg(lua_State *L, int sock, ringbuffer_t *rb, copy_context_t *copy_context) {
   size_t len;
   int ret = sock_recv(sock, &len, sizeof(len), copy_context);
   if (ret < 0) return LUA_HANDLE_ERROR(L, errno);
   if (ret != sizeof(len)) return LUA_HANDLE_ERROR_STR(L, "failed to recv the correct number of bytes");
   if (len > SEND_RECV_SIZE) return LUA_HANDLE_ERROR_STR(L, "message size is too large");
   ret = sock_recv(sock, ringbuffer_buf_ptr(rb), len, copy_context);
   if (ret < 0) return LUA_HANDLE_ERROR(L, errno);
   if ((size_t)ret != len) return LUA_HANDLE_ERROR_STR(L, "failed to recv the correct number of bytes");
   ringbuffer_reset_read_pos(rb);
   ringbuffer_push_write_pos(rb);
   if (ringbuffer_write(rb, NULL, ret) != (size_t)ret) {
      ringbuffer_pop_write_pos(rb);
      return LUA_HANDLE_ERROR_STR(L, "failed to write the correct number of bytes into the ringbuffer");
   }
   ret = rb_load(L, rb);
   if (ret < 0) return LUA_HANDLE_ERROR(L, ret);
   return ret;
}
예제 #7
0
static int workqueue_queue_read(lua_State *L, queue_t *queue, int doNotBlock) {
   pthread_mutex_lock(&queue->mutex);
   while (1) {
      if (queue->num_items) {
         int ret = rb_load(L, queue->rb);
         queue->num_items--;
         pthread_cond_signal(&queue->write_avail_cond);
         pthread_mutex_unlock(&queue->mutex);
         if (ret < 0) return LUA_HANDLE_ERROR(L, ret);
         return ret;
      } else if (doNotBlock) {
         break;
      } else {
         pthread_cond_wait(&queue->read_avail_cond, &queue->mutex);
      }
   }
   pthread_mutex_unlock(&queue->mutex);
   return 0;
}
예제 #8
0
파일: load.c 프로젝트: Sophrinix/MacRuby
static VALUE
load_try(VALUE path)
{
    rb_load(path, 0);
    return Qnil;
}
예제 #9
0
파일: rhosupport.c 프로젝트: 4nkh/rhodes
VALUE require_compiled(VALUE fname, VALUE* result, int bLoad)
{
    VALUE path;
    char* szName1 = 0;
    VALUE retval = Qtrue;
    
    if (TYPE(fname) != T_STRING)
        rb_raise(rb_eLoadError, "can not load non-string");

    szName1 = RSTRING_PTR(fname);

    if ( String_endsWith(szName1,".rb") ) 
    {
        rb_str_chop_bang(fname); rb_str_chop_bang(fname); rb_str_chop_bang(fname);
    }
    //rb_funcall(fname, rb_intern("sub!"), 2, rb_str_new2(".rb"), rb_str_new2("") );
    szName1 = RSTRING_PTR(fname);

    if ( strcmp("strscan",szName1)==0 || strcmp("enumerator",szName1)==0 ||
        strcmp("stringio",szName1)==0 || strcmp("socket",szName1)==0 )
        return Qtrue;

    RHO_LOCK(require_lock);

    if ( !bLoad && isAlreadyLoaded(fname) == Qtrue )
        goto RCompExit;

    path = find_file(fname);

    if ( path != 0 )
    {
        VALUE seq;

        RAWLOG_INFO1("require_compiled: %s", szName1);

        //optimize require
        //rb_ary_push(GET_VM()->loaded_features, path);
        rb_ary_push(GET_VM()->loaded_features, fname);

#ifdef RHODES_EMULATOR
        if ( strstr( RSTRING_PTR(path), ".rb") == 0 )
            rb_str_cat(path,".rb",3);

        GET_VM()->src_encoding_index = rb_utf8_encindex();
        rb_load(path, 0);

        if( rho_simconf_getBool("reload_app_changes") )
        {
            if ( strncmp( RSTRING_PTR(path), rho_native_rhopath(), strlen(rho_native_rhopath()) ) == 0 )
                rb_ary_delete(GET_VM()->loaded_features, fname);
        }
#else
        //rb_gc_disable();
        seq = loadISeqFromFile(path);
        

        //*result = rb_funcall(seq, rb_intern("eval"), 0 );
        *result = rb_iseq_eval(seq);
        
        //rb_gc_enable();
#endif
        goto RCompExit;
    }

    RAWLOG_ERROR1("require_compiled: error: can not find %s", RSTRING_PTR(fname));
    retval = Qnil;

RCompExit:
    RHO_UNLOCK(require_lock);
    return retval;
}
예제 #10
0
파일: initrb.c 프로젝트: numinit/initrb
static VALUE initrb_interpreter_boot(VALUE file) {
    rb_load(file, Qfalse);
    return Qtrue;
}