<commit_before>/****************************************************************************
**
** Copyright (C) Qxt Foundation. Some rights reserved.
**
** This file is part of the QxtCore module of the Qt eXTension library
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of th Common Public License, version 1.0, as published by
** IBM.
**
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
** FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the CPL along with this file.
** See the LICENSE file and the cpl1.0.txt file included with the source
** distribution for more information. If you did not receive a copy of the
** license, contact the Qxt Foundation.
**
** <http://libqxt.sourceforge.net>  <<EMAIL>>
**
****************************************************************************/

/**
\class QxtJob QxtJob

\ingroup core

\brief Execute a Job on a QThread. once or multiple times.

QxtJob allows easily starting jobs on different threads.\n
exec() will ask for the QThread to run the job on.
The Qthread needs an event loop. 4.3 and later versions of Qt have 
a non virtual QThread with a default event loop, allowing easy deployment of jobs.

\code
QThread thread;
thread.start();
LockJob().exec(&thread);
\endcode
*/

#include "qxtjob_p.h"
#include <cassert>


QxtJob::QxtJob()
{
    QXT_INIT_PRIVATE(QxtJob);
    qxt_d().running.set(false);
    connect(&qxt_d(),SIGNAL(done()),this,SIGNAL(done()));
}
/*!
execute the Job on \p onthread \n
*/
void QxtJob::exec(QThread * onthread)
{
    qxt_d().moveToThread(onthread);
    connect(this,SIGNAL(subseed()),&qxt_d(),SLOT(inwrap_d()),Qt::QueuedConnection);

    qxt_d().running.set(true);
    emit(subseed());
}
/*!
The dtor joins.
Means it blocks until the job is finished
*/
QxtJob::~QxtJob()
{
    join();
}
/*!
block until the Job finished \n
Note that the current thread will be blocked. \n
If you use this, you better be damn sure you actually want a thread.\n
Maybe you actualy want to use QxtSignalWaiter.
*/
void QxtJob::join()
{
    while(qxt_d().running.get()==true)
    {
        /**
        oh yeah that sucks ass, 
        but since any kind of waitcondition will just fail due to undeterminnism,
        we have no chance then polling.
        And no, a mutex won't work either.
        using join for anything else then testcases sounds kindof retarded anyway.
        */
        usleep(1000);
    }

}
void QxtJobPrivate::inwrap_d()
{
    synca.wakeAll();
    qxt_p().run();
    running.set(false);
    emit(done());
}








<commit_msg>A quick and dirty patch to make QxtJob build on Windows.<commit_after>/****************************************************************************
**
** Copyright (C) Qxt Foundation. Some rights reserved.
**
** This file is part of the QxtCore module of the Qt eXTension library
**
** This library is free software; you can redistribute it and/or modify it
** under the terms of th Common Public License, version 1.0, as published by
** IBM.
**
** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
** FITNESS FOR A PARTICULAR PURPOSE.
**
** You should have received a copy of the CPL along with this file.
** See the LICENSE file and the cpl1.0.txt file included with the source
** distribution for more information. If you did not receive a copy of the
** license, contact the Qxt Foundation.
**
** <http://libqxt.sourceforge.net>  <<EMAIL>>
**
****************************************************************************/

/**
\class QxtJob QxtJob

\ingroup core

\brief Execute a Job on a QThread. once or multiple times.

QxtJob allows easily starting jobs on different threads.\n
exec() will ask for the QThread to run the job on.
The Qthread needs an event loop. 4.3 and later versions of Qt have 
a non virtual QThread with a default event loop, allowing easy deployment of jobs.

\code
QThread thread;
thread.start();
LockJob().exec(&thread);
\endcode
*/

#include "qxtjob_p.h"
#include <cassert>
#ifdef Q_WS_WIN
#include <qt_windows.h>
#endif


QxtJob::QxtJob()
{
    QXT_INIT_PRIVATE(QxtJob);
    qxt_d().running.set(false);
    connect(&qxt_d(),SIGNAL(done()),this,SIGNAL(done()));
}
/*!
execute the Job on \p onthread \n
*/
void QxtJob::exec(QThread * onthread)
{
    qxt_d().moveToThread(onthread);
    connect(this,SIGNAL(subseed()),&qxt_d(),SLOT(inwrap_d()),Qt::QueuedConnection);

    qxt_d().running.set(true);
    emit(subseed());
}
/*!
The dtor joins.
Means it blocks until the job is finished
*/
QxtJob::~QxtJob()
{
    join();
}
/*!
block until the Job finished \n
Note that the current thread will be blocked. \n
If you use this, you better be damn sure you actually want a thread.\n
Maybe you actualy want to use QxtSignalWaiter.
*/
void QxtJob::join()
{
    while(qxt_d().running.get()==true)
    {
        /**
        oh yeah that sucks ass, 
        but since any kind of waitcondition will just fail due to undeterminnism,
        we have no chance then polling.
        And no, a mutex won't work either.
        using join for anything else then testcases sounds kindof retarded anyway.
        */
#ifdef Q_WS_WIN
        ::Sleep(1);
#else
        usleep(1000);
#endif  
    }

}
void QxtJobPrivate::inwrap_d()
{
    synca.wakeAll();
    qxt_p().run();
    running.set(false);
    emit(done());
}









{'fraction_non_alphanumeric': 0.16057233704292528, 'fraction_numerical': 0.0037095919448860626, 'mean_word_length': 3.81053525913339, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7107754', 'n_tokens_mistral': 1733, 'n_tokens_neox': 1673, 'n_words': 652}