Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
7f803494
Commit
7f803494
authored
Jun 19, 2010
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
player_control: hold mutex in pc_play(), pc_pause()
Race condition fix.
parent
a6ef6961
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
9 deletions
+42
-9
player_control.c
src/player_control.c
+42
-9
No files found.
src/player_control.c
View file @
7f803494
...
...
@@ -34,6 +34,9 @@
struct
player_control
pc
;
static
void
pc_enqueue_song_locked
(
struct
song
*
song
);
void
pc_init
(
unsigned
buffer_chunks
,
unsigned
int
buffered_before_play
)
{
pc
.
buffer_chunks
=
buffer_chunks
;
...
...
@@ -103,15 +106,19 @@ pc_play(struct song *song)
{
assert
(
song
!=
NULL
);
player_lock
();
if
(
pc
.
state
!=
PLAYER_STATE_STOP
)
player_command
(
PLAYER_COMMAND_STOP
);
player_command
_locked
(
PLAYER_COMMAND_STOP
);
assert
(
pc
.
next_song
==
NULL
);
pc_enqueue_song
(
song
);
pc_enqueue_song
_locked
(
song
);
assert
(
pc
.
next_song
==
NULL
);
player_unlock
();
idle_add
(
IDLE_PLAYER
);
}
...
...
@@ -151,8 +158,21 @@ pc_kill(void)
void
pc_pause
(
void
)
{
player_lock
();
if
(
pc
.
state
!=
PLAYER_STATE_STOP
)
{
player_command_locked
(
PLAYER_COMMAND_PAUSE
);
idle_add
(
IDLE_PLAYER
);
}
player_unlock
();
}
static
void
pc_pause_locked
(
void
)
{
if
(
pc
.
state
!=
PLAYER_STATE_STOP
)
{
player_command
(
PLAYER_COMMAND_PAUSE
);
player_command
_locked
(
PLAYER_COMMAND_PAUSE
);
idle_add
(
IDLE_PLAYER
);
}
}
...
...
@@ -160,20 +180,24 @@ pc_pause(void)
void
pc_set_pause
(
bool
pause_flag
)
{
player_lock
();
switch
(
pc
.
state
)
{
case
PLAYER_STATE_STOP
:
break
;
case
PLAYER_STATE_PLAY
:
if
(
pause_flag
)
pc_pause
();
pc_pause
_locked
();
break
;
case
PLAYER_STATE_PAUSE
:
if
(
!
pause_flag
)
pc_pause
();
pc_pause
_locked
();
break
;
}
player_unlock
();
}
void
...
...
@@ -203,8 +227,10 @@ pc_get_state(void)
void
pc_clear_error
(
void
)
{
player_lock
();
pc
.
error
=
PLAYER_ERROR_NOERROR
;
pc
.
errored_song
=
NULL
;
player_unlock
();
}
enum
player_error
...
...
@@ -258,16 +284,23 @@ pc_get_error_message(void)
return
NULL
;
}
void
pc_enqueue_song
(
struct
song
*
song
)
static
void
pc_enqueue_song
_locked
(
struct
song
*
song
)
{
assert
(
song
!=
NULL
);
player_lock
();
assert
(
pc
.
next_song
==
NULL
);
pc
.
next_song
=
song
;
player_command_locked
(
PLAYER_COMMAND_QUEUE
);
}
void
pc_enqueue_song
(
struct
song
*
song
)
{
assert
(
song
!=
NULL
);
player_lock
();
pc_enqueue_song_locked
(
song
);
player_unlock
();
}
...
...
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