Jump to content

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

 

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...