Giter Club home page Giter Club logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
I believe there is a mistake in the conversion formula of the 
SDL_CondWaitTimeout implementation:

clock_gettime(&now);

abstime.tv_sec = now.tv_sec + (ms / 1000);
abstime.tv_nsec = (now.tv_nsec + (ms % 1000) * 1000) * 1000;

The last line code should be:
abstime.tv_nsec = now.tv_nsec + ((ms % 1000) * 1000) * 1000;

Original comment by [email protected] on 5 Nov 2014 at 4:32

from sdl-wii.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
Moreover clock_gettime should return the elapsed time from 1970.

Whilst LWP_CondTimedWait expects the time elapsed from the CPU bootstrap (i.e. 
clicks).

So clock_gettime is the wrong function to use in this case. 

gettime() should be used instead along with ticks_to_secs and tick_nanosecs 
functions of lwp_watchdog.h. 

Anyhow also tick_nanosecs of libogc is buggy.

Moreover also clock_gettime is buggy since in the current wrong implementation 
the tv_sec is calculated as the seconds elapsed from 1970 and tv_nsec (which 
should be the number of nanoseconds expired in the current second) is the 
nanoseconds elapsed from the CPU bootstrap.

See my post here:

http://devkitpro.org/viewtopic.php?f=3&t=3056





Original comment by [email protected] on 14 Dec 2014 at 12:50

from sdl-wii.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
I believe that the correct implementation should be

#include <ogc/lwp_watchdog.h>

int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
{
    struct timespec now;
    struct timespec abstime;
    u64 ticks; 

    if (!cond)
    {
        SDL_SetError("Passed a NULL condition variable");
        return -1;
    }

    ticks=gettime();

    now.tv_sec = ticks_to_secs(ticks);
#define tick_nanosecs(ticks) 
((((u64)(ticks)*8000)/(u64)(TB_TIMER_CLOCK/125))%1000000000) //To remove when 
it will be fixed il libogc
    now.tv_nsec = tick_nanosecs(ticks);

    abstime.tv_sec = now.tv_sec + (ms / 1000);
    abstime.tv_nsec = now.tv_nsec + ((ms % 1000) * 1000) * 1000;
    if (abstime.tv_nsec > 1000000000)
    {
        abstime.tv_sec += 1;
        abstime.tv_nsec -= 1000000000;
    }

    return LWP_CondTimedWait(cond->cond, mutex->id, &abstime);
}

Original comment by [email protected] on 14 Dec 2014 at 1:14

from sdl-wii.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
Indeed I checked that WP_CondTimedWait's timespec parameter passes relative 
time instead of absolute time as specified in the documentation. So the 
implementation should be:

int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
{
    struct timespec time; 

    if (!cond)
    {
        SDL_SetError("Passed a NULL condition variable");
        return -1;
    }
    time.tv_sec = (ms / 1000);
    time.tv_nsec = (ms % 1000) * 1000000;

    return LWP_CondTimedWait(cond->cond, mutex->id, &time);
}

Original comment by [email protected] on 21 Dec 2014 at 5:38

from sdl-wii.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 19, 2024
Committed the changes in the SVN

Original comment by [email protected] on 21 Dec 2014 at 5:59

  • Changed state: Fixed

from sdl-wii.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.