Re: [gtk-vnc-devel] [RFC] GThread based coroutines
- From: Anthony Liguori <anthony codemonkey ws>
- To: "Daniel P. Berrange" <berrange redhat com>
- Cc: gtk-vnc-devel List <gtk-vnc-devel lists sourceforge net>
- Subject: Re: [gtk-vnc-devel] [RFC] GThread based coroutines
- Date: Thu, 20 Dec 2007 17:23:18 -0500
Daniel P. Berrange wrote:
On Tue, Dec 18, 2007 at 10:51:05PM -0500, Anthony Liguori wrote:
Hi,
Attached a thread-based coroutine implementation. This should make the
Windows port much easier. I've tested it with gvncviewer and vinagre
(with multiple tabs) so I think it works pretty well. The basic idea is
to use a GCond and GMutex to run all threads in lock-step. It was
tricky getting the ucontext coroutines working properly so
testing/review is greatly appreciated!
Also, I'm hoping someone who has a bit more autoconf foo can help me
with the proper autoconf/automake integration. We need to detect
ucontext in configure and if it's available, compile in
ucontext_coroutine.[ch], continuation.[ch]. Otherwise, we need to add a
dependency to gthread-2.0 and compile in gthread_coroutine.[ch].
Here's an updated patch with autoconf magic. There wre a couple of things
I needed to deal with:
When we do 'make install' we also install the coroutine headers. This
doesn't work so well because your patch has #ifdef in the coroutine.h
to then #include either the gthread or ucontext header, and this #ifdef
depends on a variable set from configure.ac
I observed that the structs required for ucontext vs gthread were more or
less the same except for the GThread * vs struct continuation. So I unified
them into a generic 'void *context'. In the implementation this context
points to a GThread * or a 'struct continuation *' as needed. The latter
means the 'container_of' trick doesn't work, so I simply added 'void *owner'
to the 'struct continuation'.
The GThread patch doesn't go correct (well any) GThread cleanup when the
coroutine exits - we need to join & also free the GThread * object. I
didn't try to address this.
Actually, when a coroutine exits, the thread resources should be freed
since the threads are created as non-joinable. I looked over the glib
manual again and that seems to be the behavior.
Regards,
Anthony Liguori
configure now has '--with-coroutine=ucontext|gthread', defaulting to
'ucontext' and automatically switching to 'gthread' if it can't find
the getcontext/makecontext/swapcontext function calls.
a/src/coroutine.c | 121 ----------------------------------------
b/src/coroutine_gthread.c | 129 +++++++++++++++++++++++++++++++++++++++++++
b/src/coroutine_ucontext.c | 133 +++++++++++++++++++++++++++++++++++++++++++++
configure.ac | 35 +++++++++++
src/Makefile.am | 20 +++++-
src/continuation.h | 1
src/coroutine.h | 8 +-
7 files changed, 317 insertions(+), 130 deletions(-)
Regards,
Dan.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]