Exemplo n.º 1
0
void* WorkerThread::workerThread()
{
    {
        MutexLocker lock(m_threadCreationMutex);
        m_workerContext = createWorkerContext(m_startupData->m_scriptURL, m_startupData->m_userAgent);

        if (m_runLoop.terminated()) {
            // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet,
            // forbidExecution() couldn't be called from stop().
           m_workerContext->script()->forbidExecution();
        }
    }

    WorkerScriptController* script = m_workerContext->script();
    script->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, m_startupData->m_scriptURL));
    // Free the startup data to cause its member variable deref's happen on the worker's thread (since
    // all ref/derefs of these objects are happening on the thread at this point). Note that
    // WorkerThread::~WorkerThread happens on a different thread where it was created.
    m_startupData.clear();

    runEventLoop();

    ThreadIdentifier threadID = m_threadID;

    ASSERT(m_workerContext->hasOneRef());

    // The below assignment will destroy the context, which will in turn notify messaging proxy.
    // We cannot let any objects survive past thread exit, because no other thread will run GC or otherwise destroy them.
    m_workerContext = 0;
    
    // The thread object may be already destroyed from notification now, don't try to access "this".
    detachThread(threadID);

    return 0;
}
Exemplo n.º 2
0
bool Redox::connectUnix(const string &path, function<void(int)> connection_callback) {

  path_ = path;
  user_connection_callback_ = connection_callback;

  if (!initEv())
    return false;

  // Connect over unix sockets
  ctx_ = redisAsyncConnectUnix(path.c_str());

  if (!initHiredis())
    return false;

  event_loop_thread_ = thread([this] { runEventLoop(); });

  // Block until connected and running the event loop, or until
  // a connection error happens and the event loop exits
  {
    unique_lock<mutex> ul(running_lock_);
    running_waiter_.wait(ul, [this]
    {
      unique_lock<mutex> ul(connect_lock_);
      return running_.load() || connect_state_ == CONNECT_ERROR;
    });
  }

  // Return if succeeded
  {
    unique_lock<mutex> ul(connect_lock_);
    return connect_state_ == CONNECTED;
  }
}
void ONScripter::waitEventSub(int count)
{
    remaining_time = count;
    timerEvent();

    runEventLoop();
    removeEvent( ONS_BREAK_EVENT );
}
Exemplo n.º 4
0
static void run(void)
{
	SET_CPU_IPL(0);
	clockEnable();
	screenEnable();
	menuEnable();
	showWelcome();
	receiverEnable();
	clockShow();
	runEventLoop();
}
Exemplo n.º 5
0
void WorkerThread::workerThread()
{
    // Propagate the mainThread's fenv to workers.
#if PLATFORM(IOS)
    FloatingPointEnvironment::singleton().propagateMainThreadEnvironment();
#endif

#if PLATFORM(GTK)
    GRefPtr<GMainContext> mainContext = adoptGRef(g_main_context_new());
    g_main_context_push_thread_default(mainContext.get());
#endif

    {
        LockHolder lock(m_threadCreationMutex);
        m_workerGlobalScope = createWorkerGlobalScope(m_startupData->m_scriptURL, m_startupData->m_userAgent, m_startupData->m_contentSecurityPolicyResponseHeaders, m_startupData->m_shouldBypassMainWorldContentSecurityPolicy, WTFMove(m_startupData->m_topOrigin));

        if (m_runLoop.terminated()) {
            // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet,
            // forbidExecution() couldn't be called from stop().
            m_workerGlobalScope->script()->forbidExecution();
        }
    }

    WorkerScriptController* script = m_workerGlobalScope->script();
    script->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, m_startupData->m_scriptURL));
    // Free the startup data to cause its member variable deref's happen on the worker's thread (since
    // all ref/derefs of these objects are happening on the thread at this point). Note that
    // WorkerThread::~WorkerThread happens on a different thread where it was created.
    m_startupData = nullptr;

    runEventLoop();

#if PLATFORM(GTK)
    g_main_context_pop_thread_default(mainContext.get());
#endif

    ThreadIdentifier threadID = m_threadID;

    ASSERT(m_workerGlobalScope->hasOneRef());

    // The below assignment will destroy the context, which will in turn notify messaging proxy.
    // We cannot let any objects survive past thread exit, because no other thread will run GC or otherwise destroy them.
    m_workerGlobalScope = nullptr;

    // Clean up WebCore::ThreadGlobalData before WTF::WTFThreadData goes away!
    threadGlobalData().destroy();

    // The thread object may be already destroyed from notification now, don't try to access "this".
    detachThread(threadID);
}
Exemplo n.º 6
0
void WorkerThread::workerThread()
{
    // Propagate the mainThread's fenv to workers.
#if PLATFORM(IOS)
    fesetenv(&mainThreadFEnv);
#endif

    {
        MutexLocker lock(m_threadCreationMutex);
        m_workerGlobalScope = createWorkerGlobalScope(m_startupData->m_scriptURL, m_startupData->m_userAgent, std::move(m_startupData->m_groupSettings), m_startupData->m_contentSecurityPolicy, m_startupData->m_contentSecurityPolicyType, m_startupData->m_topOrigin.release());

        if (m_runLoop.terminated()) {
            // The worker was terminated before the thread had a chance to run. Since the context didn't exist yet,
            // forbidExecution() couldn't be called from stop().
            m_workerGlobalScope->script()->forbidExecution();
        }
    }

    WorkerScriptController* script = m_workerGlobalScope->script();
#if ENABLE(INSPECTOR)
    InspectorInstrumentation::willEvaluateWorkerScript(workerGlobalScope(), m_startupData->m_startMode);
#endif
    script->evaluate(ScriptSourceCode(m_startupData->m_sourceCode, m_startupData->m_scriptURL));
    // Free the startup data to cause its member variable deref's happen on the worker's thread (since
    // all ref/derefs of these objects are happening on the thread at this point). Note that
    // WorkerThread::~WorkerThread happens on a different thread where it was created.
    m_startupData.clear();

    runEventLoop();

    ThreadIdentifier threadID = m_threadID;

    ASSERT(m_workerGlobalScope->hasOneRef());

    // The below assignment will destroy the context, which will in turn notify messaging proxy.
    // We cannot let any objects survive past thread exit, because no other thread will run GC or otherwise destroy them.
    m_workerGlobalScope = 0;

    // Clean up WebCore::ThreadGlobalData before WTF::WTFThreadData goes away!
    threadGlobalData().destroy();

    // The thread object may be already destroyed from notification now, don't try to access "this".
    detachThread(threadID);
}
Exemplo n.º 7
0
int main() {
    if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_EVENTS ) < 0 ) {
        printf( "Failed to initialize SDL: %s\n", SDL_GetError() );
        return 0;
    }

    SDL_Window* window = SDL_CreateWindow( "Let's Rock!", NULL, NULL, WIN_W, WIN_H, SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_SHOWN );

    if ( window == NULL ) {
        printf( "Failed to create SDL Window: %s\n", SDL_GetError() );
        return 0;
    }

    backBuffer = SDL_GetWindowSurface( window );
    srand( time( NULL ) );

    if ( !loadFiles() ) {
        printf( "Failed to load files!\n" );
        freeFiles();
        SDL_Quit();
        return 0;
    }

    /*
    ex1();
    ex2();
    */
    ex3();
    while ( runEventLoop() ) {
        SDL_UpdateWindowSurface( window );
        SDL_Delay( 20 );
    }

    SDL_DestroyWindow( window );
    SDL_Quit();
    return 0;
}
void ONScripter::waitEventSub(int count)
{
    if (break_id != NULL) return; // already in wait queue

    if (count != 0){
        timerEvent(count);
            
        if (count > 0)
            break_id = SDL_AddTimer(count, breakCallback, NULL);
    }
    
    if (count >= 0 && break_id == NULL){
        SDL_Event event;
        event.type = ONS_BREAK_EVENT;
        SDL_PushEvent( &event );
    }
    
    runEventLoop();

    removeEvent( ONS_BREAK_EVENT );
    
    if (break_id) SDL_RemoveTimer(break_id);
    break_id = NULL;
}