summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikhail Naganov <mnaganov@google.com>2019-03-29 22:28:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2019-03-29 22:28:01 +0000
commitf8fe94e5465ce5836df5e565c8f49414084a35e6 (patch)
tree0f5d530394e6fa0635ebd84f58e7bb105a2bcdf9
parenta42823b264fa6f9c970b87e6a16588a46a6af476 (diff)
parente1a285ddc1c728d95222aeddbe82b94ac5eb3304 (diff)
downloadsystem_core-f8fe94e5465ce5836df5e565c8f49414084a35e6.tar.gz
system_core-f8fe94e5465ce5836df5e565c8f49414084a35e6.tar.bz2
system_core-f8fe94e5465ce5836df5e565c8f49414084a35e6.zip
Merge "libutils: Fix thread safety annotations in Mutex"
-rw-r--r--libutils/Mutex_test.cpp18
-rw-r--r--libutils/include/utils/Mutex.h4
2 files changed, 19 insertions, 3 deletions
diff --git a/libutils/Mutex_test.cpp b/libutils/Mutex_test.cpp
index 8a1805f51..79f4302d0 100644
--- a/libutils/Mutex_test.cpp
+++ b/libutils/Mutex_test.cpp
@@ -29,4 +29,20 @@ TEST(Mutex, compile) {
android::Mutex::Autolock _l(mLock);
i = 0;
modifyLockedVariable();
-} \ No newline at end of file
+}
+
+TEST(Mutex, tryLock) {
+ if (mLock.tryLock() != 0) {
+ return;
+ }
+ mLock.unlock();
+}
+
+#if defined(__ANDROID__)
+TEST(Mutex, timedLock) {
+ if (mLock.timedLock(1) != 0) {
+ return;
+ }
+ mLock.unlock();
+}
+#endif
diff --git a/libutils/include/utils/Mutex.h b/libutils/include/utils/Mutex.h
index 29c2e8ce1..1325bf37f 100644
--- a/libutils/include/utils/Mutex.h
+++ b/libutils/include/utils/Mutex.h
@@ -108,7 +108,7 @@ class CAPABILITY("mutex") Mutex {
void unlock() RELEASE();
// lock if possible; returns 0 on success, error otherwise
- status_t tryLock() TRY_ACQUIRE(true);
+ status_t tryLock() TRY_ACQUIRE(0);
#if defined(__ANDROID__)
// Lock the mutex, but don't wait longer than timeoutNs (relative time).
@@ -122,7 +122,7 @@ class CAPABILITY("mutex") Mutex {
// which is subject to NTP adjustments, and includes time during suspend,
// so a timeout may occur even though no processes could run.
// Not holding a partial wakelock may lead to a system suspend.
- status_t timedLock(nsecs_t timeoutNs) TRY_ACQUIRE(true);
+ status_t timedLock(nsecs_t timeoutNs) TRY_ACQUIRE(0);
#endif
// Manages the mutex automatically. It'll be locked when Autolock is