Esempio n. 1
0
static int unload_module(void) {
	unsigned int i = 0;

	LNOTICE("unloaded module %s", module_name);

	for (i = 0; i < profile_size; i++) {

		close_socket(i);
		free_profile(i);
	}
	
	                 
#if UV_VERSION_MAJOR == 0
	uv_async_send(&async_handle);
	uv_loop_delete(loop);
#else

	if (uv_loop_alive(loop)) {
        	uv_async_send(&async_handle);
	}
   
	uv_stop(loop);
	uv_loop_close(loop);
	free(loop);
#endif
	/* Close socket */
	return 0;
}
Esempio n. 2
0
static bool StartIoTjs(JObject* process) {

  // Get jerry global object.
  JObject global = JObject::Global();

  // Create environtment.
  Environment env(uv_default_loop());

  // Bind environment to global object.
  global.SetNative((uintptr_t)(&env), NULL);

  // Call the entry.
  // load and call iotjs.js
  InitIoTjs(process);

  bool more;
  do {
    more = uv_run(env.loop(), UV_RUN_ONCE);
    more |= ProcessNextTick();
    if (more == false) {
      more = uv_loop_alive(env.loop());
    }
  } while (more);

  ProcessEmitExit(0);

  return true;
}
Esempio n. 3
0
int nub_thread_create(nub_loop_t* loop, nub_thread_t* thread) {
  uv_async_t* async_handle;
  int er;

  async_handle = (uv_async_t*) malloc(sizeof(*async_handle));
  CHECK_NE(NULL, async_handle);
  er = uv_async_init(&loop->uvloop, async_handle, nub__work_signal_cb);
  ASSERT(0 == er);
  async_handle->data = thread;
  thread->async_signal_ = async_handle;

  ASSERT(uv_loop_alive(&loop->uvloop));

  er = uv_sem_init(&thread->thread_lock_sem_, 0);
  ASSERT(0 == er);

  er = uv_sem_init(&thread->sem_wait_, 1);
  ASSERT(0 == er);

  fuq_init(&thread->incoming_);
  thread->disposed = 0;
  thread->nubloop = loop;
  thread->disposed_cb_ = NULL;
  thread->work.thread = thread;
  thread->work.work_type = NUB_LOOP_QUEUE_NONE;
  ++loop->ref_;

  return uv_thread_create(&thread->uvthread, nub__thread_entry_cb, thread);
}
Esempio n. 4
0
EventLoop::~EventLoop() {
	uv_ref((uv_handle_t*) &deleteObjectsHandle);
	uv_prepare_stop(&deleteObjectsHandle);
	uv_close((uv_handle_t*) &deleteObjectsHandle, nullptr);

	// Wait remaining handle to close
	uv_run(&loop, UV_RUN_DEFAULT);

	if(uv_loop_alive(&loop)) {
		log(LL_Warning, "Loop still used but delete requested, handles:\n");
		uv_walk(&loop,
		        [](uv_handle_t* handle, void* arg) {
			        EventLoop* self = (EventLoop*) arg;
			        const char* type;
			        switch(handle->type) {
#define X(uc, lc) \
	case UV_##uc: \
		type = #lc; \
		break;
				        UV_HANDLE_TYPE_MAP(X)
#undef X
				        default:
					        type = "<unknown>";
			        }

			        self->log(LL_Warning, "  [%08X] %s %p\n", handle->flags, type, handle);
		        },
		        this);
Esempio n. 5
0
static bool
uv_loop_source_check(void *data)
{
    uv_loop_t *loop = data;

    uv_update_time(loop);

    bool returnValue = uv_loop_alive(loop);
    SOL_DBG("Returning %s", returnValue ? "true" : "false");
    return returnValue;
}
Esempio n. 6
0
static bool StartIoTjs(Environment* env) {
  // Get jerry global object.
  JObject global = JObject::Global();

  // Bind environment to global object.
  global.SetNative((uintptr_t)(env), NULL);

  // Initialize builtin modules.
  JObject* process = InitModules();

  // Call the entry.
  // load and call iotjs.js
  env->GoStateRunningMain();

  RunIoTjs(process);

  // Run event loop.
  env->GoStateRunningLoop();

  bool more;
  do {
    more = uv_run(env->loop(), UV_RUN_ONCE);
    more |= ProcessNextTick();
    if (more == false) {
      more = uv_loop_alive(env->loop());
    }
  } while (more);

  env->GoStateExiting();

  // Emit 'exit' event.
  ProcessEmitExit(0);

  // Release bulitin modules.
  CleanupModules();

  return true;
}
Esempio n. 7
0
File: loop.c Progetto: nubjs/libnub
void nub_loop_dispose(nub_loop_t* loop) {
  ASSERT(0 == uv_loop_alive(&loop->uvloop));
  ASSERT(1 == fuq_empty(&loop->blocking_queue_));
  ASSERT(0 == loop->ref_);
  ASSERT(NULL != loop->work_ping_);
  ASSERT(0 == uv_has_ref((uv_handle_t*) loop->work_ping_));
  ASSERT(1 == fuq_empty(&loop->thread_dispose_queue_));

  uv_close((uv_handle_t*) loop->work_ping_, nub__free_handle_cb);
  uv_close((uv_handle_t*) &loop->queue_processor_, NULL);
  ASSERT(0 == uv_is_active((uv_handle_t*) loop->work_ping_));

  fuq_dispose(&loop->thread_dispose_queue_);
  uv_mutex_destroy(&loop->thread_dispose_lock_);
  uv_sem_destroy(&loop->loop_lock_sem_);
  fuq_dispose(&loop->blocking_queue_);
  uv_mutex_destroy(&loop->queue_processor_lock_);
  fuq_dispose(&loop->work_queue_);
  uv_mutex_destroy(&loop->work_lock_);

  CHECK_EQ(0, uv_run(&loop->uvloop, UV_RUN_NOWAIT));
  CHECK_NE(UV_EBUSY, uv_loop_close(&loop->uvloop));
}
Esempio n. 8
0
/**
 * stop UVRunner()
 */
bool
UVEventLoop::StopUVRunner(const bool force, const bool andWait)
{
	if (!runUV) return true;
	if (!force) {
		if (uv_loop_alive(loop)) {
			DEBUG_OUT("UVRun::Stop() loop is still active ...");
			return false;
		}
	}
	runUV = false;
	if (force) {
// afics if i  mutex this, the run thread will see that it should exit anyway, and it should be mutexed as it isn't otherwise safe
//		uv_stop(loop);
	}

	if (andWait) {
		DEBUG_OUT("waiting ...");
		uv_thread_join(&runner); // wait for the worker to finish
//		while (uvIsRunning); // a fallback, hopefully never necessary to do it this way
		DEBUG_OUT("we waited and we got there");
	}
	return true;
}
Esempio n. 9
0
/**
 * the core of the event loop
 */
void
UVEventLoop::Runner(void *up)
{
	int status=0;
	UVEventLoop *l = (UVEventLoop*)up;
	l->uvIsRunning = true;
	while (l->runUV) {
		l->Lock();
		l->HandleRunnerQueues();
		l->Unlock();

		if ((status = uv_run(l->loop, UV_RUN_NOWAIT)) < 0) { // error ... == 0 means all ok ... > 0 all ok but need run again
		}
		if (!uv_loop_alive(l->loop)) {
#ifdef _MSC_VER
			Sleep(1);
#else
			usleep(1);
#endif
		}
	}
	l->uvIsRunning = false;
	DEBUG_OUT("UVEventLoop::UVWorker() closing");
}
Esempio n. 10
0
 bool alive() { return uv_loop_alive(m_uvloop.get()); }