Sha256: a8b778ba06385f8b021011811fc6654033d97b341abc3be706e2be99c98583d8

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

#include <QApplication>
#include <qnamespace.h>
#include <QtDebug>
#include "sunscraperthread.h"
#include "sunscraperworker.h"

#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
pthread_t SunscraperThread::m_thread;
#endif

extern void qt_set_current_thread_to_main_thread();

void SunscraperThread::invoke()
{
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
    pthread_create(&m_thread, NULL, &SunscraperThread::thread_routine, NULL);
#endif
}

void *SunscraperThread::thread_routine(void *)
{
    /* Better error messages. */
    int   argc   = 1;
    char *argv[] = { (char*) "Sunscraper", NULL};

    /* Why (char*)? Because argv can (theoretically) be modified. *
     * But Qt won't do that with argv[0]. I know, trust me.       */

    QInternal::callFunction(QInternal::SetCurrentThreadToMainThread, NULL);

    QApplication app(argc, argv);
    app.setApplicationName("Sunscraper-Embed");

    SunscraperWorker::unlock();

    /*
     * The magic value 42 means we want exit from the loop.
     * E.g. alerts from within the page may exit the loop with value 0.
     */
    while(app.exec() != 42);

    /* Our host application exits. */

    return NULL;
}

void SunscraperThread::commitSuicide()
{
    QApplication::exit(42);

#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
    pthread_join(m_thread, NULL);
#endif
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sunscraper-1.2.0 ext/embed/sunscraperthread.cpp
sunscraper-1.2.0.pre2 ext/embed/sunscraperthread.cpp
sunscraper-1.2.0.pre1 ext/embed/sunscraperthread.cpp