AsyncWorker is a GObject-style library (liboasyncworker.so) that will ease implementing a task queue. By
which I mean a system like a printer spool, but for functions (or methods) rather than printer-tasks. So for
each queue instance, there’s always maximum one task being processed. Tasks can’t be preempted (it’s not a kernel scheduler),
but tasks that haven’t run or aren’t running can be removed. Of course can the kernel preempt tasks (the entire proces). I mean
that within your application, you can’t preempt a task: to make another task happen before the current task ended. While using
the same queue instance.
Creating a task happens by creating a OAsyncWorkerItem instance, which is of course a simple GObject. The object
holds, for example, a reference to a launcher function (the task itself), a callback (to cleanup your stuff after
the launcher finished), a launcher-arguments pointer (user data for the launcher) and a priority.
Once you add the item to the OAsyncWorker instance, the worker will make sure that at some point in the future, the
item will be processed. The higher the priority of an item, the faster it will be selected to be processed.
My plans for this one are to replace a specific GList with a GAsyncQueue. And to let all the signals (it has signals like
item_finished, item_added and item_removed) emit in the GMainLoop.
There’s some basic support (on platforms that support this) to set CPU affinity on a queue-instance. This way you,
as the programmer, can specify on which processors the queue may process it’s tasks. I haven’t yet added support
for the other sched.h functions. You can, of course, use multiple queues simultanously.
There’s no support for cancellation of the current-item (but you can remove items that haven’t ran). The reason is
rather simple: GThread isn’t supporting thread cancellation (for good reasoning). Yet, you can of course implement your own
cancellation-points and a cancel trigger. I might add functionality to ease this (not sure yet).
You’ll still need to use gdk_threads_enter() and gdk_threads_leave() in the launcher and callback functions of your
tasks. For example in case you’re planning to perform gtk stuff. You wont need to do that in the signal-handlers.
Mikael Hallendal invented both the name AsyncWorker and the namespace
to which I renamed this library. That namespace is “O”. It means “Onion”. It’s indeed to make sure that now we have
“Egg”, “Bacon” and “Onion”. Yet you can’t blame me for it!
pvanhoof - EggAsyncWorker ? :) Hallski - eek luis - I think Egg is a curse :) Hallski - OnionAsyncWorker pvanhoof - lol Hallski - so we have an entire omelette Hallski - with Egg, Bacon and now Onion
You can find asyncworker as a module in CVS here. You can find a simple sample that illustrates all this a little bit here.
Please note that the API isn’t stable (this is bleeding edge and very new). I did, however, already added some API documentation (so you can already generate API-documentation).