Re: Waiting forGMainLoop events

2013-06-26 Thread Kip Warner
On Wed, 2013-06-26 at 20:00 -0400, Jasper St. Pierre wrote:
> So, Bogdan, I'm going to ask the question: why do you want to do this?
> 
> It's a very unusual use of GMainLoop. What problem are you trying to solve?

Something else I'd like to preface Jasper's question with is another
one. Bogdon, are you attempting to do this from a secondary thread?

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Jasper St. Pierre
So, Bogdan, I'm going to ask the question: why do you want to do this?

It's a very unusual use of GMainLoop. What problem are you trying to solve?


On Wed, Jun 26, 2013 at 7:45 PM, Kip Warner  wrote:

> On Thu, 2013-06-27 at 01:41 +0200, Bogdan Lotko wrote:
> > poll() is not sleep()!
>
> Hey Bogdan. It depends what you mean. I think we're all saying the same
> thing, but differently. All polling that doesn't hammer a resource has
> to sleep, but the caller doesn't explicitly have to do this because the
> callee does.
>
> --
> Kip Warner -- Software Engineer
> OpenPGP encrypted/signed mail preferred
> http://www.thevertigo.com
>
> ___
> gtk-list mailing list
> gtk-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-list
>
>


-- 
  Jasper
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Kip Warner
On Thu, 2013-06-27 at 01:41 +0200, Bogdan Lotko wrote:
> poll() is not sleep()!

Hey Bogdan. It depends what you mean. I think we're all saying the same
thing, but differently. All polling that doesn't hammer a resource has
to sleep, but the caller doesn't explicitly have to do this because the
callee does.

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Kip Warner
On Wed, 2013-06-26 at 19:23 -0400, Paul Davis wrote:
> by definition you cannot determine if events are ready without something
> semantically equivalent to poll(2). whether or not you block in that
> poll-equivalent thing is a different story.

You knew what I meant.

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Paul Davis
by definition you cannot determine if events are ready without something
semantically equivalent to poll(2). whether or not you block in that
poll-equivalent thing is a different story.

using a main loop that never blocks is a design error. it implies burning
cpu time for no reason, which typically only happens when someone can't
figure how to integrate "another event source" into the main loop. glib
makes this easy for just about kind of event source, so there isn't much of
an excuse for this sort of design.


On Wed, Jun 26, 2013 at 7:21 PM, Kip Warner  wrote:

> On Wed, 2013-06-26 at 19:16 -0400, Paul Davis wrote:
> > the OP asked:
> >
> > Is it possible to wait for GMainLoop event  without processing them?
>
> He said after that that he'd like to avoid a loop with sleep (polling).
>
> > query polls but does not process events. only dispatch does that.
>
> Maybe that's good enough for him, I don't know. But if he doesn't want
> polling, then it won't be.
>
> --
> Kip Warner -- Software Engineer
> OpenPGP encrypted/signed mail preferred
> http://www.thevertigo.com
>
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Kip Warner
On Wed, 2013-06-26 at 19:16 -0400, Paul Davis wrote:
> the OP asked:
> 
> Is it possible to wait for GMainLoop event  without processing them?

He said after that that he'd like to avoid a loop with sleep (polling).

> query polls but does not process events. only dispatch does that.

Maybe that's good enough for him, I don't know. But if he doesn't want
polling, then it won't be.

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Paul Davis
the OP asked:

Is it possible to wait for GMainLoop event  without processing them?

query polls but does not process events. only dispatch does that.



On Wed, Jun 26, 2013 at 7:09 PM, Kip Warner  wrote:

> On Wed, 2013-06-26 at 19:04 -0400, Paul Davis wrote:
> > while (1) {
> >   call prepare
> >   call query, which will block.
> >   do stuff.
> >   then call dispatch.
> >   do more stuff.
> > }
>
> g_main_context_query () polls.
>
> --
> Kip Warner -- Software Engineer
> OpenPGP encrypted/signed mail preferred
> http://www.thevertigo.com
>
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Kip Warner
On Wed, 2013-06-26 at 19:04 -0400, Paul Davis wrote:
> while (1) {
>   call prepare
>   call query, which will block.
>   do stuff.
>   then call dispatch.
>   do more stuff.
> }

g_main_context_query () polls.

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Paul Davis
On Wed, Jun 26, 2013 at 6:49 PM, Kip Warner  wrote:

> On Wed, 2013-06-26 at 18:43 -0400, Paul Davis wrote:
> > geez, does nobody read docs any more ?
>
> Chill.
>
> >
> https://developer.gnome.org/glib/2.30/glib-The-Main-Event-Loop.html#g-main-context-pending
>
> > sorry wrong link. same page, near top, see "Customizing the main loop
> > iteration"
> >
> I am probably just not reading it right, but how can a caller use the
> component functions to do what he is asking, namely check if there are
> events, blocking until there are some, and doing so without polling?
>

while (1) {
  call prepare
  call query, which will block.
  do stuff.
  then call dispatch.
  do more stuff.
}
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Kip Warner
On Wed, 2013-06-26 at 18:43 -0400, Paul Davis wrote:
> geez, does nobody read docs any more ?

Chill.

> https://developer.gnome.org/glib/2.30/glib-The-Main-Event-Loop.html#g-main-context-pending

> sorry wrong link. same page, near top, see "Customizing the main loop
> iteration"
> 
I am probably just not reading it right, but how can a caller use the
component functions to do what he is asking, namely check if there are
events, blocking until there are some, and doing so without polling?

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Bogdan Lotko

Hello,

geez, does nobody read docs any more ?


yes: :-)

"Checks if any sources have pending events for the given context."

What about blocking?

regards,

b



On 6/27/2013 00:43, Paul Davis wrote:

geez, does nobody read docs any more ?

https://developer.gnome.org/glib/2.30/glib-The-Main-Event-Loop.html#g-main-context-pending


On Wed, Jun 26, 2013 at 6:38 PM, Kip Warner > wrote:


On Thu, 2013-06-27 at 00:33 +0200, Bogdan Lotko wrote:
> Hello,
>
> unfortunately the gtk_events_pending() does not block.
>
> I'd like to avoid the loop with sleep().
>
> with best regards,
>
> bogdan

Hey Bogdan. Yes, you are right. Could you maybe tell us a little bit
more about what it is that you are trying to do?

--
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com

___
gtk-list mailing list
gtk-list@gnome.org 
https://mail.gnome.org/mailman/listinfo/gtk-list





--

*Bogdan Lotko*

b.lo...@chello.at
Phone: +43 1 2852458
Mobile: +43 676 6615012
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Paul Davis
sorry wrong link. same page, near top, see "Customizing the main loop
iteration"


On Wed, Jun 26, 2013 at 6:43 PM, Paul Davis wrote:

> geez, does nobody read docs any more ?
>
>
> https://developer.gnome.org/glib/2.30/glib-The-Main-Event-Loop.html#g-main-context-pending
>
>
> On Wed, Jun 26, 2013 at 6:38 PM, Kip Warner  wrote:
>
>> On Thu, 2013-06-27 at 00:33 +0200, Bogdan Lotko wrote:
>> > Hello,
>> >
>> > unfortunately the gtk_events_pending() does not block.
>> >
>> > I'd like to avoid the loop with sleep().
>> >
>> > with best regards,
>> >
>> > bogdan
>>
>> Hey Bogdan. Yes, you are right. Could you maybe tell us a little bit
>> more about what it is that you are trying to do?
>>
>> --
>> Kip Warner -- Software Engineer
>> OpenPGP encrypted/signed mail preferred
>> http://www.thevertigo.com
>>
>> ___
>> gtk-list mailing list
>> gtk-list@gnome.org
>> https://mail.gnome.org/mailman/listinfo/gtk-list
>>
>>
>
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Paul Davis
geez, does nobody read docs any more ?

https://developer.gnome.org/glib/2.30/glib-The-Main-Event-Loop.html#g-main-context-pending


On Wed, Jun 26, 2013 at 6:38 PM, Kip Warner  wrote:

> On Thu, 2013-06-27 at 00:33 +0200, Bogdan Lotko wrote:
> > Hello,
> >
> > unfortunately the gtk_events_pending() does not block.
> >
> > I'd like to avoid the loop with sleep().
> >
> > with best regards,
> >
> > bogdan
>
> Hey Bogdan. Yes, you are right. Could you maybe tell us a little bit
> more about what it is that you are trying to do?
>
> --
> Kip Warner -- Software Engineer
> OpenPGP encrypted/signed mail preferred
> http://www.thevertigo.com
>
> ___
> gtk-list mailing list
> gtk-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-list
>
>
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Kip Warner
On Thu, 2013-06-27 at 00:33 +0200, Bogdan Lotko wrote:
> Hello,
> 
> unfortunately the gtk_events_pending() does not block.
> 
> I'd like to avoid the loop with sleep().
> 
> with best regards,
> 
> bogdan

Hey Bogdan. Yes, you are right. Could you maybe tell us a little bit
more about what it is that you are trying to do?

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Bogdan Lotko

Hello Kip,

Thank you for the answer.

Unfortunately this will not help.

If the method "Runs a single iteration of the mainloop" as stated in the 
documentation it's not OK - I won't be able to lock the mutex.

By the way, if I correctly understand the documentation the

g_main_context_iteration( GMainContext *context, gboolean may_block  );

that I plan to use has also the possibility to block if no events are 
pending.


What I need is waiting for an event, without executing it.

with best regards,

bogdan


On 6/26/2013 23:32, Kip Warner wrote:

On Wed, 2013-06-26 at 19:02 +0200, Bogdan Lotko wrote:

Hello,

Is it possible to wait for GMainLoop event  without processing them?

the following pseudo-code illustrates the problem:

while( notEndLoop )
{
 waitForEvent();

 lockMutex;

 // Run a single iteration
 g_main_context_iteration( context, false );

unlockMutex
}

Please note, that I have to lock the mutex before running an iteration.

Thank you for your help

with best regards,

bogdan

Hey Bogdan,

I'm not sure if this is helpful, but take a look at the
gtk_main_iteration_do(gboolean blocking) function, specifically setting
the blocking parameter to false and checking the return. From the
documentation:

 Runs a single iteration of the mainloop. If no events are
 available either return or block depending on the value of
 blocking.

 blocking : TRUE if you want GTK+ to block if no events
 are pending

 Returns : TRUE if gtk_main_quit() has been called for
 the innermost mainloop

Take care,




--

*Bogdan Lotko*

b.lo...@chello.at
Phone: +43 1 2852458
Mobile: +43 676 6615012
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Kip Warner
On Wed, 2013-06-26 at 14:32 -0700, Kip Warner wrote:
> On Wed, 2013-06-26 at 19:02 +0200, Bogdan Lotko wrote:
> > Hello,
> > 
> > Is it possible to wait for GMainLoop event  without processing them?
> > 
> > the following pseudo-code illustrates the problem:
> > 
> > while( notEndLoop )
> > {
> > waitForEvent();
> > 
> > lockMutex;
> > 
> > // Run a single iteration
> > g_main_context_iteration( context, false );
> > 
> >unlockMutex
> > }
> > 
> > Please note, that I have to lock the mutex before running an iteration.
> > 
> > Thank you for your help
> > 
> > with best regards,
> > 
> > bogdan
> 
> Hey Bogdan,
> 
> I'm not sure if this is helpful, but take a look at the
> gtk_main_iteration_do(gboolean blocking) function, specifically setting
> the blocking parameter to false and checking the return. From the
> documentation:

Hey Bogdan. I just re-read your post and realized you want to not
process the event. In this case, I believe gtk_main_iteration_do() does
process the event if is one to process. If you just want to check if
there are any events at all, without processing them, try
gtk_events_pending().

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: Waiting forGMainLoop events

2013-06-26 Thread Kip Warner
On Wed, 2013-06-26 at 19:02 +0200, Bogdan Lotko wrote:
> Hello,
> 
> Is it possible to wait for GMainLoop event  without processing them?
> 
> the following pseudo-code illustrates the problem:
> 
> while( notEndLoop )
> {
> waitForEvent();
> 
> lockMutex;
> 
> // Run a single iteration
> g_main_context_iteration( context, false );
> 
>unlockMutex
> }
> 
> Please note, that I have to lock the mutex before running an iteration.
> 
> Thank you for your help
> 
> with best regards,
> 
> bogdan

Hey Bogdan,

I'm not sure if this is helpful, but take a look at the
gtk_main_iteration_do(gboolean blocking) function, specifically setting
the blocking parameter to false and checking the return. From the
documentation:

Runs a single iteration of the mainloop. If no events are
available either return or block depending on the value of
blocking.

blocking : TRUE if you want GTK+ to block if no events
are pending

Returns : TRUE if gtk_main_quit() has been called for
the innermost mainloop

Take care,

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com


signature.asc
Description: This is a digitally signed message part
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list