BLooper: API to hijack existing thread.
I need this to use loopers in WebKit, which spawns threads and expects to be able to turn them into event loops later on. This is the pattern already used in BApplication, we may as well make it available elsewhere. Change-Id: I5939ca89d33cb3bcc92567b302c2038d976af598 Reviewed-on: https://review.haiku-os.org/735 Reviewed-by: Axel Dörfler <axeld@pinc-software.de> Reviewed-by: waddlesplash <waddlesplash@gmail.com>
This commit is contained in:
parent
4bba0571c6
commit
151343ebc8
@ -1,14 +1,15 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008-2014 Haiku, Inc. All rights reserved.
|
* Copyright 2008-2018 Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Niels Sascha Reedijk, niels.reedijk@gmail.com
|
* Niels Sascha Reedijk, niels.reedijk@gmail.com
|
||||||
* John Scipione, jscipione@gmail.com
|
* John Scipione, jscipione@gmail.com
|
||||||
|
* Adrien Destugues, pulkomandy@pulkomandy.tk
|
||||||
*
|
*
|
||||||
* Corresponds to:
|
* Corresponds to:
|
||||||
* headers/os/app/Looper.h hrev47355
|
* headers/os/app/Looper.h hrev52501
|
||||||
* src/kits/app/Looper.cpp hrev47355
|
* src/kits/app/Looper.cpp hrev52501
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -603,6 +604,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\fn thread_id BLooper::Loop()
|
||||||
|
\brief Run the event loop in the current thread.
|
||||||
|
|
||||||
|
This method runs the event loop in an already existing thread. It blocks
|
||||||
|
until the looper stops looping. This can
|
||||||
|
be used to turn an existing thread into a BLooper.
|
||||||
|
|
||||||
|
Make sure the looper is not yet running before you call this method.
|
||||||
|
|
||||||
|
\since Haiku R1
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn void BLooper::Quit()
|
\fn void BLooper::Quit()
|
||||||
\brief Hook method that is called after a \c B_QUIT_REQUESTED message.
|
\brief Hook method that is called after a \c B_QUIT_REQUESTED message.
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
|
|
||||||
// Loop control
|
// Loop control
|
||||||
virtual thread_id Run();
|
virtual thread_id Run();
|
||||||
|
void Loop();
|
||||||
virtual void Quit();
|
virtual void Quit();
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
bool Lock();
|
bool Lock();
|
||||||
|
@ -590,15 +590,7 @@ BApplication::Run()
|
|||||||
if (fInitError != B_OK)
|
if (fInitError != B_OK)
|
||||||
return fInitError;
|
return fInitError;
|
||||||
|
|
||||||
AssertLocked();
|
Loop();
|
||||||
|
|
||||||
if (fRunCalled)
|
|
||||||
debugger("BApplication::Run was already called. Can only be called once.");
|
|
||||||
|
|
||||||
fThread = find_thread(NULL);
|
|
||||||
fRunCalled = true;
|
|
||||||
|
|
||||||
task_looper();
|
|
||||||
|
|
||||||
delete fPulseRunner;
|
delete fPulseRunner;
|
||||||
return fThread;
|
return fThread;
|
||||||
|
@ -457,6 +457,24 @@ BLooper::Run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BLooper::Loop()
|
||||||
|
{
|
||||||
|
AssertLocked();
|
||||||
|
|
||||||
|
if (fRunCalled) {
|
||||||
|
// Not allowed to call Loop() or Run() more than once
|
||||||
|
debugger("can't call BLooper::Loop twice!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fThread = find_thread(NULL);
|
||||||
|
fRunCalled = true;
|
||||||
|
|
||||||
|
task_looper();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BLooper::Quit()
|
BLooper::Quit()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user