Jump to content
PaulB

uGFX 2.8 gfxQueueGSyncGet

Recommended Posts

I am using gfxQueueGSyncGet with a timeout, and it often returns immediately without waiting, when there is nothing in the Q.

It uses gfxSemWait, and here I think there is a problem with adding the delaytime (in ms) to the timespec.

It has the following two lines :

                tm.tv_sec += ms / 1000;
                tm.tv_nsec += (ms % 1000) * 1000000;


This can set tv_nsec to be more than 1E9, and the following call to sem_timedwait then fails immediately with errno set to EINVAL, instead of waiting for timeout.

I think that any overflow of tv_nsec should be added as another sec :

                tm.tv_sec += tm.tv_nsec / 1000000000;
                tm.tv_nsec %= 1000000000;

 

I imagine that this will also affect anything else that uses gfxSemWait.

Regards

 

Share this post


Link to post
Share on other sites

The strategy you are suggesting will not work and is unnecessary.

The ms parameter is in milliseconds. The whole number of seconds will always be ms/1000. Adding anything else to it will cause it to be too much. Similarly the nsecs field gets the fraction of the second and is expressed in nano-seconds. Ms%1000 gives you that component. It just needs to be multiplied by 1000000 to convert from milliseconds to nanoseconds.

 

If you are getting overflow it is because your compiler is not extending the arithmetic on the left hand side of the expression to 64bit as it is supposed to as the tv_nsecs field is 64bit. The way around this is to add constant expanders to the constant in the left hand side ie change 1000000 to 1000000ULL. Unfortunately this is compiler dependant and not all compilers support that syntax but it is a work-around for the compiler not following the C standards properly.

Share this post


Link to post
Share on other sites

Thanks for the reply.

What you say is correct, when the timespec is being set to a milliseconds value, as in

            ts.tv_sec = ms / 1000;
            ts.tv_nsec = (ms % 1000) * 1000000;

 

I may well have missed something, but in gfxSemWait, the milliseconds value is being added to an existing timespec, which already has a nsec component.

The sum of the existing and new fractions may well be more than 1E9 ns, which is invalid. (Putting in a debug check for this condition shows that it often is).

This is what I meant by overflow, sorry that was a misleading term.

Share this post


Link to post
Share on other sites
Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×