Skip to content

Commit 87a6e0e

Browse files
committed
Provide a copy of 'pthread_mutexattr_setprotocol' so that Android 8.1 can again be supported.
Closes #16
1 parent 24dc5a0 commit 87a6e0e

File tree

6 files changed

+61
-4
lines changed

6 files changed

+61
-4
lines changed

android/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ android {
44
defaultConfig {
55
applicationId "org.lyrion.squeezelite"
66
compileSdk 34
7-
minSdkVersion 28
7+
minSdkVersion 27
88
targetSdkVersion 34
99
buildToolsVersion = "34.0.0"
10-
versionCode 700
11-
versionName "0.7.0"
10+
versionCode 701
11+
versionName "0.7.1"
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
ndkVersion "27.2.12479018"
1414
ndk {

android/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ sources = [
114114
'../dop.c',
115115
'../dsd2pcm/dsd2pcm.c',
116116
'src/android.c',
117+
'src/thread.c',
117118
'src/pa/os/unix/pa_unix_hostapis.c',
118119
'src/pa/os/unix/pa_pthread_util.c',
119120
'src/pa/os/unix/pa_unix_util.c',

android/src/thread.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2008 The Android Open Source Project
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in
12+
* the documentation and/or other materials provided with the
13+
* distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26+
* SUCH DAMAGE.
27+
*/
28+
29+
#include <pthread.h>
30+
#include <errno.h>
31+
32+
#define MUTEXATTR_PROTOCOL_MASK 0x0020
33+
#define MUTEXATTR_PROTOCOL_SHIFT 5
34+
35+
/**
36+
This code is a copy of pthread_mutexattr_setprotocol from:
37+
https://android.googlesource.com/platform/bionic/+/master/libc/bionic/pthread_mutex.cpp
38+
...as such the license of this is as above.
39+
40+
This is coped here so that Android 8.1 can be supported.
41+
*/
42+
int pthread_mutexattr_setprotocol_squeezelite(pthread_mutexattr_t* attr, int protocol) {
43+
if (protocol != PTHREAD_PRIO_NONE && protocol != PTHREAD_PRIO_INHERIT) {
44+
return EINVAL;
45+
}
46+
*attr = (*attr & ~MUTEXATTR_PROTOCOL_MASK) | (protocol << MUTEXATTR_PROTOCOL_SHIFT);
47+
return 0;
48+
}

fastlane/metadata/android/en-US/changelogs/700.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
• Add option to control stopping of player when powered off.
44
• Fix handling of media keys.
55
• Add option to delay start on boot by 5, 10, 20, or 30 seconds.
6-
• New icon.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
• New icon.
2+
• Provide a copy of 'pthread_mutexattr_setprotocol' so that Android 8.1 can again be supported.

squeezelite.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,14 @@ typedef int64_t s64_t;
335335

336336
#define mutex_type pthread_mutex_t
337337
#define mutex_create(m) pthread_mutex_init(&m, NULL)
338+
339+
#ifdef ANDROID
340+
extern int pthread_mutexattr_setprotocol_squeezelite(pthread_mutexattr_t* attr, int protocol);
341+
#define mutex_create_p(m) pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_setprotocol_squeezelite(&attr, PTHREAD_PRIO_INHERIT); pthread_mutex_init(&m, &attr); pthread_mutexattr_destroy(&attr)
342+
#else
338343
#define mutex_create_p(m) pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT); pthread_mutex_init(&m, &attr); pthread_mutexattr_destroy(&attr)
344+
#endif
345+
339346
#define mutex_lock(m) pthread_mutex_lock(&m)
340347
#define mutex_unlock(m) pthread_mutex_unlock(&m)
341348
#define mutex_destroy(m) pthread_mutex_destroy(&m)

0 commit comments

Comments
 (0)