Mercurial > sdl-ios-xcode
comparison src/SDL_compat.c @ 5113:481dabb098ef
Improved timer implementation
The new timer model is formalized as using a separate thread to handle timer callbacks. This was the case on almost every platform before, but it's now a requirement, and simplifies the implementation and makes it perform consistently across platforms.
Goals:
* Minimize timer thread blocking
* Dispatch timers as accurately as possible
* SDL_AddTimer() and SDL_RemoveTimer() are completely threadsafe
* SDL_RemoveTimer() doesn't crash with a timer that's expired or removed
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 27 Jan 2011 14:45:06 -0800 |
parents | da347bfed240 |
children | c8e049de174c |
comparison
equal
deleted
inserted
replaced
5112:0846f18eb625 | 5113:481dabb098ef |
---|---|
1758 break; | 1758 break; |
1759 } | 1759 } |
1760 return previous; | 1760 return previous; |
1761 } | 1761 } |
1762 | 1762 |
1763 static Uint32 | |
1764 SDL_SetTimerCallback(Uint32 interval, void* param) | |
1765 { | |
1766 return ((SDL_OldTimerCallback)param)(interval); | |
1767 } | |
1768 | |
1769 int | |
1770 SDL_SetTimer(Uint32 interval, SDL_OldTimerCallback callback) | |
1771 { | |
1772 static SDL_TimerID compat_timer; | |
1773 | |
1774 if (compat_timer) { | |
1775 SDL_RemoveTimer(compat_timer); | |
1776 compat_timer = 0; | |
1777 } | |
1778 | |
1779 if (interval && callback) { | |
1780 compat_timer = SDL_AddTimer(interval, SDL_SetTimerCallback, callback); | |
1781 if (!compat_timer) { | |
1782 return -1; | |
1783 } | |
1784 } | |
1785 return 0; | |
1786 } | |
1787 | |
1763 int | 1788 int |
1764 SDL_putenv(const char *_var) | 1789 SDL_putenv(const char *_var) |
1765 { | 1790 { |
1766 char *ptr = NULL; | 1791 char *ptr = NULL; |
1767 char *var = SDL_strdup(_var); | 1792 char *var = SDL_strdup(_var); |