Qt5: use the Genode main thread

Now that it is possible to resize the stack of the Genode main thread, it
is not necessary anymore to create a new Genode thread as Qt main thread.

Fixes #1134.
This commit is contained in:
Christian Prochaska 2014-04-30 14:23:20 +02:00 committed by Christian Helmuth
parent edfd90a1bc
commit 17c22b2ac9
3 changed files with 10 additions and 138 deletions

View File

@ -1,5 +1,5 @@
/*
* \brief Thread with configurable stack size
* \brief Thread with preconfigured stack size
* \author Christian Prochaska
* \date 2008-06-11
*/
@ -14,102 +14,18 @@
#ifndef _INCLUDE__BASE__THREAD_QT_H_
#define _INCLUDE__BASE__THREAD_QT_H_
#include <base/env.h>
#include <base/printf.h>
#include <base/thread.h>
enum { DEFAULT_STACK_SIZE = 4096*100 };
namespace Genode {
struct Thread_entry
class Thread_qt : public Thread<DEFAULT_STACK_SIZE>
{
virtual void entry() = 0;
};
class Thread_qt : public Thread_entry
{
private:
class Genode_thread : Thread_base
{
private:
Thread_entry *_thread_entry;
/**
* Thread_base interface
*/
void entry() { _thread_entry->entry(); }
public:
Genode_thread(const char *name,
size_t stack_size,
Thread_entry *thread_entry)
:
Thread_base(name, stack_size),
_thread_entry(thread_entry)
{
/* start Genode thread */
start();
}
};
protected:
const char *_name;
unsigned int _stack_size;
Genode_thread *_thread;
public:
/**
* Constructor
*
* \param name Thread name (for debugging)
*/
explicit Thread_qt(const char *name = "Qt <noname>")
:
_name(name),
_stack_size(DEFAULT_STACK_SIZE),
_thread(0) { }
~Thread_qt()
{
if (_thread)
destroy(env()->heap(), _thread);
}
/**
* Set the thread's stack size - don't call when the thread is running!
*/
bool set_stack_size(unsigned int stack_size)
{
/* error, if thread is already running */
if (_thread)
return false;
_stack_size = stack_size;
return true;
}
/**
* Start execution of the thread
*/
void start()
{
/* prevent double calls of 'start' */
if (_thread) return;
_thread = new (env()->heap()) Genode_thread(_name, _stack_size, this);
}
static Thread_base *myself()
{
return Thread_base::myself();
}
: Thread<DEFAULT_STACK_SIZE>(name) { }
};
}

View File

@ -13,65 +13,19 @@
#ifdef QT_MAIN_STACK_SIZE
#include <base/printf.h>
#include <base/semaphore.h>
#include <base/sleep.h>
#include <thread_qt.h>
#include <base/thread.h>
using namespace Genode;
extern int qt_main(int argc, char *argv[]);
class Main_thread : public Thread_qt
{
protected:
int _argc;
char **_argv;
Semaphore &_finished;
int _result;
public:
Main_thread(int argc, char *argv[], Semaphore &finished) :
Thread_qt("Qt main thread"),
_argc(argc),
_argv(argv),
_finished(finished),
_result(0) { }
virtual void entry()
{
/* call the real main() function */
_result = ::qt_main(_argc, _argv);
_finished.up();
sleep_forever();
}
int result() { return _result; }
};
#define qt_main main
int main(int argc, char *argv[])
{
// PDBG("QT_MAIN_STACK_SIZE == %d", QT_MAIN_STACK_SIZE);
Genode::Thread_base::myself()->stack_size(QT_MAIN_STACK_SIZE);
Semaphore finished;
Main_thread main_thread(argc, argv, finished);
main_thread.set_stack_size(QT_MAIN_STACK_SIZE);
main_thread.start();
/* wait for the thread to finish */
finished.down();
// PDBG("main_thread finished");
return main_thread.result();
return qt_main(argc, argv);
}
#endif /* QT_MAIN_STACK_SIZE */

View File

@ -639,8 +639,10 @@ void QThread::start(Priority priority)
if (d->genode_thread) {
if (d->stackSize > 0) {
if (!d->genode_thread->set_stack_size(d->stackSize)) {
qWarning("QThread::start: Thread stack size error");
try {
d->genode_thread->stack_size(d->stackSize);
} catch (...) {
qWarning("QThread::start: Thread stack allocation error");
// we failed to set the stacksize, and as the documentation states,
// the thread will fail to run...