Merge "libutils: Fix thread safety annotations in Mutex" am: f8fe94e546
am: 8105c31189
Change-Id: Idb3b730d5ec3a7c0101f7b5e782c587a252908d0
This commit is contained in:
commit
cce9c65f53
2 changed files with 19 additions and 3 deletions
|
|
@ -29,4 +29,20 @@ TEST(Mutex, compile) {
|
||||||
android::Mutex::Autolock _l(mLock);
|
android::Mutex::Autolock _l(mLock);
|
||||||
i = 0;
|
i = 0;
|
||||||
modifyLockedVariable();
|
modifyLockedVariable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ class CAPABILITY("mutex") Mutex {
|
||||||
void unlock() RELEASE();
|
void unlock() RELEASE();
|
||||||
|
|
||||||
// lock if possible; returns 0 on success, error otherwise
|
// lock if possible; returns 0 on success, error otherwise
|
||||||
status_t tryLock() TRY_ACQUIRE(true);
|
status_t tryLock() TRY_ACQUIRE(0);
|
||||||
|
|
||||||
#if defined(__ANDROID__)
|
#if defined(__ANDROID__)
|
||||||
// Lock the mutex, but don't wait longer than timeoutNs (relative time).
|
// 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,
|
// which is subject to NTP adjustments, and includes time during suspend,
|
||||||
// so a timeout may occur even though no processes could run.
|
// so a timeout may occur even though no processes could run.
|
||||||
// Not holding a partial wakelock may lead to a system suspend.
|
// 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
|
#endif
|
||||||
|
|
||||||
// Manages the mutex automatically. It'll be locked when Autolock is
|
// Manages the mutex automatically. It'll be locked when Autolock is
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue