Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
dcd48df0
Commit
dcd48df0
authored
Jan 22, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bug in timer when the list of timers changed.
Fix contributed by Michael Bicha
parent
c4bf458e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
40 deletions
+51
-40
SDL_timer.c
src/timer/SDL_timer.c
+51
-40
No files found.
src/timer/SDL_timer.c
View file @
dcd48df0
...
@@ -113,56 +113,67 @@ SDL_ThreadedTimerCheck(void)
...
@@ -113,56 +113,67 @@ SDL_ThreadedTimerCheck(void)
SDL_bool
removed
;
SDL_bool
removed
;
SDL_mutexP
(
SDL_timer_mutex
);
SDL_mutexP
(
SDL_timer_mutex
);
list_changed
=
SDL_FALSE
;
now
=
SDL_GetTicks
();
now
=
SDL_GetTicks
();
for
(
prev
=
NULL
,
t
=
SDL_timers
;
t
;
t
=
next
)
{
do
{
removed
=
SDL_FALSE
;
list_changed
=
SDL_FALSE
;
ms
=
t
->
interval
-
SDL_TIMESLICE
;
for
(
prev
=
NULL
,
t
=
SDL_timers
;
t
;
t
=
next
)
{
next
=
t
->
next
;
removed
=
SDL_FALSE
;
if
((
int
)
(
now
-
t
->
last_alarm
)
>
(
int
)
ms
)
{
ms
=
t
->
interval
-
SDL_TIMESLICE
;
struct
_SDL_TimerID
timer
;
next
=
t
->
next
;
if
((
int
)
(
now
-
t
->
last_alarm
)
>
(
int
)
ms
)
{
struct
_SDL_TimerID
timer
;
if
((
now
-
t
->
last_alarm
)
<
t
->
interval
)
{
if
((
now
-
t
->
last_alarm
)
<
t
->
interval
)
{
t
->
last_alarm
+=
t
->
interval
;
t
->
last_alarm
+=
t
->
interval
;
}
else
{
t
->
last_alarm
=
now
;
}
#ifdef DEBUG_TIMERS
printf
(
"Executing timer %p (thread = %lu)
\n
"
,
t
,
SDL_ThreadID
());
#endif
timer
=
*
t
;
SDL_mutexV
(
SDL_timer_mutex
);
ms
=
timer
.
cb
(
timer
.
interval
,
timer
.
param
);
SDL_mutexP
(
SDL_timer_mutex
);
if
(
list_changed
)
{
/* Abort, list of timers modified */
/* FIXME: what if ms was changed? */
break
;
}
if
(
ms
!=
t
->
interval
)
{
if
(
ms
)
{
t
->
interval
=
ROUND_RESOLUTION
(
ms
);
}
else
{
}
else
{
/* Remove timer from the list */
t
->
last_alarm
=
now
;
}
#ifdef DEBUG_TIMERS
#ifdef DEBUG_TIMERS
printf
(
"SDL: Removing timer %p
\n
"
,
t
);
printf
(
"Executing timer %p (thread = %lu)
\n
"
,
t
,
SDL_ThreadID
());
#endif
#endif
if
(
prev
)
{
timer
=
*
t
;
prev
->
next
=
next
;
SDL_mutexV
(
SDL_timer_mutex
);
ms
=
timer
.
cb
(
timer
.
interval
,
timer
.
param
);
SDL_mutexP
(
SDL_timer_mutex
);
if
(
list_changed
)
{
next
=
t
->
next
;
for
(
prev
=
SDL_timers
;
prev
;
prev
=
prev
->
next
)
{
if
(
prev
->
next
==
t
)
break
;
}
}
if
(
ms
!=
t
->
interval
)
{
if
(
ms
)
{
t
->
interval
=
ROUND_RESOLUTION
(
ms
);
}
else
{
}
else
{
SDL_timers
=
next
;
/* Remove timer from the list */
#ifdef DEBUG_TIMERS
printf
(
"SDL: Removing timer %p
\n
"
,
t
);
#endif
if
(
prev
)
{
prev
->
next
=
next
;
}
else
{
SDL_timers
=
next
;
}
SDL_free
(
t
);
--
SDL_timer_running
;
removed
=
SDL_TRUE
;
}
}
SDL_free
(
t
);
}
--
SDL_timer_running
;
if
(
list_changed
)
{
removed
=
SDL_TRUE
;
/* Abort, list of timers modified */
break
;
}
}
}
}
/* Don't update prev if the timer has disappeared */
if
(
!
removed
)
{
prev
=
t
;
}
}
}
/* Don't update prev if the timer has disappeared */
}
while
(
list_changed
);
if
(
!
removed
)
{
prev
=
t
;
}
}
SDL_mutexV
(
SDL_timer_mutex
);
SDL_mutexV
(
SDL_timer_mutex
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment