Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
a13b7713
Commit
a13b7713
authored
6 months ago
by
Deucе
Browse files
Options
Downloads
Patches
Plain Diff
Add missing re-lock in xptone_open_locked()
While we're here, add debug assertions to the pthread stuff.
parent
b9bbf9b6
No related branches found
No related tags found
No related merge requests found
Pipeline
#7914
passed
6 months ago
Stage: build
Stage: test
Stage: cleanup
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/xpbeep.c
+37
-26
37 additions, 26 deletions
src/xpdev/xpbeep.c
with
37 additions
and
26 deletions
src/xpdev/xpbeep.c
+
37
−
26
View file @
a13b7713
...
@@ -70,6 +70,16 @@
...
@@ -70,6 +70,16 @@
#ifdef XPDEV_THREAD_SAFE
#ifdef XPDEV_THREAD_SAFE
#include
"threadwrap.h"
#include
"threadwrap.h"
#ifndef NDEBUG
#define chk_pthread_mutex_init(a, b) assert(pthread_mutex_init(a, b) == 0)
#define chk_pthread_mutex_lock(a) assert(pthread_mutex_lock(a) == 0)
#define chk_pthread_mutex_unlock(a) assert(pthread_mutex_unlock(a) == 0)
#else
#define chk_pthread_mutex_init(a, b) pthread_mutex_init(a, b)
#define chk_pthread_mutex_lock(a) pthread_mutex_lock(a)
#define chk_pthread_mutex_unlock(a) pthread_mutex_unlock(a)
#endif
static
bool
sample_thread_running
=
false
;
static
bool
sample_thread_running
=
false
;
static
sem_t
sample_pending_sem
;
static
sem_t
sample_pending_sem
;
static
sem_t
sample_complete_sem
;
static
sem_t
sample_complete_sem
;
...
@@ -433,11 +443,12 @@ xptone_open_locked(void)
...
@@ -433,11 +443,12 @@ xptone_open_locked(void)
handle_type
=
SOUND_DEVICE_PULSEAUDIO
;
handle_type
=
SOUND_DEVICE_PULSEAUDIO
;
handle_rc
++
;
handle_rc
++
;
#ifdef XPDEV_THREAD_SAFE
#ifdef XPDEV_THREAD_SAFE
pthread_mutex_unlock
(
&
handle_mutex
);
chk_
pthread_mutex_unlock
(
&
handle_mutex
);
pthread_mutex_lock
(
&
sample_mutex
);
chk_
pthread_mutex_lock
(
&
sample_mutex
);
if
(
samples_posted
==
0
)
if
(
samples_posted
==
0
)
xp_play_sample_locked
((
unsigned
char
*
)
"
\x80
"
,
1
,
false
);
xp_play_sample_locked
((
unsigned
char
*
)
"
\x80
"
,
1
,
false
);
pthread_mutex_unlock
(
&
sample_mutex
);
chk_pthread_mutex_unlock
(
&
sample_mutex
);
chk_pthread_mutex_lock
(
&
handle_mutex
);
#else
#else
xptone
(
0
,
1
,
WAVE_SHAPE_SQUARE
);
xptone
(
0
,
1
,
WAVE_SHAPE_SQUARE
);
#endif
#endif
...
@@ -681,11 +692,11 @@ xptone_open(void)
...
@@ -681,11 +692,11 @@ xptone_open(void)
bool
ret
;
bool
ret
;
#ifdef XPDEV_THREAD_SAFE
#ifdef XPDEV_THREAD_SAFE
pthread_once
(
&
sample_initialized_pto
,
init_sample
);
pthread_once
(
&
sample_initialized_pto
,
init_sample
);
pthread_mutex_lock
(
&
handle_mutex
);
chk_
pthread_mutex_lock
(
&
handle_mutex
);
#endif
#endif
ret
=
xptone_open_locked
();
ret
=
xptone_open_locked
();
#ifdef XPDEV_THREAD_SAFE
#ifdef XPDEV_THREAD_SAFE
pthread_mutex_unlock
(
&
handle_mutex
);
chk_
pthread_mutex_unlock
(
&
handle_mutex
);
#endif
#endif
return
ret
;
return
ret
;
}
}
...
@@ -755,12 +766,12 @@ void
...
@@ -755,12 +766,12 @@ void
xptone_complete
(
void
)
xptone_complete
(
void
)
{
{
#ifdef XPDEV_THREAD_SAFE
#ifdef XPDEV_THREAD_SAFE
pthread_mutex_lock
(
&
handle_mutex
);
chk_
pthread_mutex_lock
(
&
handle_mutex
);
#endif
#endif
// coverity[sleep]
// coverity[sleep]
xptone_complete_locked
();
xptone_complete_locked
();
#ifdef XPDEV_THREAD_SAFE
#ifdef XPDEV_THREAD_SAFE
pthread_mutex_unlock
(
&
handle_mutex
);
chk_
pthread_mutex_unlock
(
&
handle_mutex
);
#endif
#endif
}
}
...
@@ -836,12 +847,12 @@ xptone_close(void)
...
@@ -836,12 +847,12 @@ xptone_close(void)
bool
ret
;
bool
ret
;
#ifdef XPDEV_THREAD_SAFE
#ifdef XPDEV_THREAD_SAFE
pthread_mutex_lock
(
&
handle_mutex
);
chk_
pthread_mutex_lock
(
&
handle_mutex
);
#endif
#endif
// coverity[sleep]
// coverity[sleep]
ret
=
xptone_close_locked
();
ret
=
xptone_close_locked
();
#ifdef XPDEV_THREAD_SAFE
#ifdef XPDEV_THREAD_SAFE
pthread_mutex_unlock
(
&
handle_mutex
);
chk_
pthread_mutex_unlock
(
&
handle_mutex
);
#endif
#endif
return
ret
;
return
ret
;
}
}
...
@@ -1033,19 +1044,19 @@ void xp_play_sample_thread(void *data)
...
@@ -1033,19 +1044,19 @@ void xp_play_sample_thread(void *data)
else
else
waited
=
false
;
waited
=
false
;
posted_last
=
false
;
posted_last
=
false
;
pthread_mutex_lock
(
&
handle_mutex
);
chk_
pthread_mutex_lock
(
&
handle_mutex
);
if
(
handle_type
==
SOUND_DEVICE_CLOSED
)
{
if
(
handle_type
==
SOUND_DEVICE_CLOSED
)
{
must_close
=
true
;
must_close
=
true
;
if
(
!
xptone_open_locked
())
{
if
(
!
xptone_open_locked
())
{
sem_post
(
&
sample_complete_sem
);
sem_post
(
&
sample_complete_sem
);
pthread_mutex_unlock
(
&
handle_mutex
);
chk_
pthread_mutex_unlock
(
&
handle_mutex
);
continue
;
continue
;
}
}
}
}
if
(
pthread_mutex_lock
(
&
sample_mutex
)
!=
0
)
{
if
(
pthread_mutex_lock
(
&
sample_mutex
)
!=
0
)
{
pthread_mutex_unlock
(
&
handle_mutex
);
chk_
pthread_mutex_unlock
(
&
handle_mutex
);
goto
error_return
;
goto
error_return
;
}
}
this_sample_size
=
sample_size
;
this_sample_size
=
sample_size
;
...
@@ -1054,12 +1065,12 @@ void xp_play_sample_thread(void *data)
...
@@ -1054,12 +1065,12 @@ void xp_play_sample_thread(void *data)
sample
=
(
unsigned
char
*
)
malloc
(
sample_size
);
sample
=
(
unsigned
char
*
)
malloc
(
sample_size
);
if
(
sample
==
NULL
)
{
if
(
sample
==
NULL
)
{
sem_post
(
&
sample_complete_sem
);
sem_post
(
&
sample_complete_sem
);
pthread_mutex_unlock
(
&
sample_mutex
);
chk_
pthread_mutex_unlock
(
&
sample_mutex
);
pthread_mutex_unlock
(
&
handle_mutex
);
chk_
pthread_mutex_unlock
(
&
handle_mutex
);
continue
;
continue
;
}
}
memcpy
(
sample
,
sample_buffer
,
this_sample_size
);
memcpy
(
sample
,
sample_buffer
,
this_sample_size
);
pthread_mutex_unlock
(
&
sample_mutex
);
chk_
pthread_mutex_unlock
(
&
sample_mutex
);
do_xp_play_sample
(
sample
,
this_sample_size
,
&
freed
);
do_xp_play_sample
(
sample
,
this_sample_size
,
&
freed
);
if
(
freed
)
if
(
freed
)
...
@@ -1075,12 +1086,12 @@ void xp_play_sample_thread(void *data)
...
@@ -1075,12 +1086,12 @@ void xp_play_sample_thread(void *data)
xptone_close_locked
();
xptone_close_locked
();
}
}
}
}
pthread_mutex_unlock
(
&
handle_mutex
);
chk_
pthread_mutex_unlock
(
&
handle_mutex
);
}
}
error_return:
error_return:
#ifdef _WIN32
#ifdef _WIN32
pthread_mutex_lock
(
&
handle_mutex
);
chk_
pthread_mutex_lock
(
&
handle_mutex
);
if
(
handle_type
==
SOUND_DEVICE_WIN32
)
{
if
(
handle_type
==
SOUND_DEVICE_WIN32
)
{
if
(
wh
[
curr_wh
].
dwFlags
&
WHDR_PREPARED
)
{
if
(
wh
[
curr_wh
].
dwFlags
&
WHDR_PREPARED
)
{
while
(
waveOutUnprepareHeader
(
waveOut
,
&
wh
[
curr_wh
],
sizeof
(
wh
[
curr_wh
]))
==
WAVERR_STILLPLAYING
)
while
(
waveOutUnprepareHeader
(
waveOut
,
&
wh
[
curr_wh
],
sizeof
(
wh
[
curr_wh
]))
==
WAVERR_STILLPLAYING
)
...
@@ -1088,7 +1099,7 @@ error_return:
...
@@ -1088,7 +1099,7 @@ error_return:
}
}
FREE_AND_NULL
(
wh
[
curr_wh
].
lpData
);
FREE_AND_NULL
(
wh
[
curr_wh
].
lpData
);
}
}
pthread_mutex_unlock
(
&
handle_mutex
);
chk_
pthread_mutex_unlock
(
&
handle_mutex
);
#endif
#endif
FREE_AND_NULL
(
sample
);
FREE_AND_NULL
(
sample
);
...
@@ -1102,8 +1113,8 @@ error_return:
...
@@ -1102,8 +1113,8 @@ error_return:
static
void
static
void
init_sample
(
void
)
init_sample
(
void
)
{
{
pthread_mutex_init
(
&
sample_mutex
,
NULL
);
chk_
pthread_mutex_init
(
&
sample_mutex
,
NULL
);
pthread_mutex_init
(
&
handle_mutex
,
NULL
);
chk_
pthread_mutex_init
(
&
handle_mutex
,
NULL
);
sem_init
(
&
sample_pending_sem
,
0
,
0
);
sem_init
(
&
sample_pending_sem
,
0
,
0
);
sem_init
(
&
sample_complete_sem
,
0
,
0
);
sem_init
(
&
sample_complete_sem
,
0
,
0
);
}
}
...
@@ -1116,9 +1127,9 @@ static bool xp_play_sample_locked(unsigned char *sample, size_t size, bool backg
...
@@ -1116,9 +1127,9 @@ static bool xp_play_sample_locked(unsigned char *sample, size_t size, bool backg
}
}
while
(
samples_posted
>
0
)
{
while
(
samples_posted
>
0
)
{
pthread_mutex_unlock
(
&
sample_mutex
);
chk_
pthread_mutex_unlock
(
&
sample_mutex
);
sem_wait
(
&
sample_complete_sem
);
sem_wait
(
&
sample_complete_sem
);
pthread_mutex_lock
(
&
sample_mutex
);
chk_
pthread_mutex_lock
(
&
sample_mutex
);
samples_posted
--
;
samples_posted
--
;
}
}
sample_buffer
=
sample
;
sample_buffer
=
sample
;
...
@@ -1127,9 +1138,9 @@ static bool xp_play_sample_locked(unsigned char *sample, size_t size, bool backg
...
@@ -1127,9 +1138,9 @@ static bool xp_play_sample_locked(unsigned char *sample, size_t size, bool backg
sem_post
(
&
sample_pending_sem
);
sem_post
(
&
sample_pending_sem
);
if
(
!
background
)
{
if
(
!
background
)
{
while
(
samples_posted
>
0
)
{
while
(
samples_posted
>
0
)
{
pthread_mutex_unlock
(
&
sample_mutex
);
chk_
pthread_mutex_unlock
(
&
sample_mutex
);
sem_wait
(
&
sample_complete_sem
);
sem_wait
(
&
sample_complete_sem
);
pthread_mutex_lock
(
&
sample_mutex
);
chk_
pthread_mutex_lock
(
&
sample_mutex
);
samples_posted
--
;
samples_posted
--
;
}
}
}
}
...
@@ -1145,9 +1156,9 @@ bool xp_play_sample(unsigned char *sample, size_t size, bool background)
...
@@ -1145,9 +1156,9 @@ bool xp_play_sample(unsigned char *sample, size_t size, bool background)
bool
ret
;
bool
ret
;
pthread_once
(
&
sample_initialized_pto
,
init_sample
);
pthread_once
(
&
sample_initialized_pto
,
init_sample
);
pthread_mutex_lock
(
&
sample_mutex
);
chk_
pthread_mutex_lock
(
&
sample_mutex
);
ret
=
xp_play_sample_locked
(
sample
,
size
,
background
);
ret
=
xp_play_sample_locked
(
sample
,
size
,
background
);
pthread_mutex_unlock
(
&
sample_mutex
);
chk_
pthread_mutex_unlock
(
&
sample_mutex
);
return
ret
;
return
ret
;
}
}
#else
#else
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment