aboutsummaryrefslogtreecommitdiffstats
path: root/libc/bionic/system_properties.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/bionic/system_properties.cpp')
-rw-r--r--libc/bionic/system_properties.cpp40
1 files changed, 23 insertions, 17 deletions
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index a62ce14f4..32d1e3114 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -1102,7 +1102,7 @@ int __system_property_area_init() {
return fsetxattr_failed ? -2 : 0;
}
-unsigned int __system_property_area_serial() {
+uint32_t __system_property_area_serial() {
prop_area* pa = __system_property_area__;
if (!pa) {
return -1;
@@ -1163,8 +1163,10 @@ int __system_property_read(const prop_info* pi, char* name, char* value) {
}
void __system_property_read_callback(const prop_info* pi,
- void (*callback)(void* cookie, const char* name,
- const char* value),
+ void (*callback)(void* cookie,
+ const char* name,
+ const char* value,
+ uint32_t serial),
void* cookie) {
while (true) {
uint32_t serial = __system_property_serial(pi); // acquire semantics
@@ -1177,7 +1179,7 @@ void __system_property_read_callback(const prop_info* pi,
// TODO: see todo in __system_property_read function
atomic_thread_fence(memory_order_acquire);
if (serial == load_const_atomic(&(pi->serial), memory_order_relaxed)) {
- callback(cookie, pi->name, value_buf);
+ callback(cookie, pi->name, value_buf, serial);
return;
}
}
@@ -1329,30 +1331,34 @@ int __system_property_add(const char* name, unsigned int namelen, const char* va
}
// Wait for non-locked serial, and retrieve it with acquire semantics.
-unsigned int __system_property_serial(const prop_info* pi) {
+uint32_t __system_property_serial(const prop_info* pi) {
uint32_t serial = load_const_atomic(&pi->serial, memory_order_acquire);
while (SERIAL_DIRTY(serial)) {
- __futex_wait(const_cast<volatile void*>(reinterpret_cast<const void*>(&pi->serial)), serial,
- nullptr);
+ __futex_wait(const_cast<_Atomic(uint_least32_t)*>(&pi->serial), serial, nullptr);
serial = load_const_atomic(&pi->serial, memory_order_acquire);
}
return serial;
}
-unsigned int __system_property_wait_any(unsigned int serial) {
+uint32_t __system_property_wait_any(uint32_t old_serial) {
prop_area* pa = __system_property_area__;
- uint32_t my_serial;
-
- if (!pa) {
- return 0;
- }
+ if (!pa) return 0;
+ uint32_t new_serial;
do {
- __futex_wait(pa->serial(), serial, nullptr);
- my_serial = atomic_load_explicit(pa->serial(), memory_order_acquire);
- } while (my_serial == serial);
+ __futex_wait(pa->serial(), old_serial, nullptr);
+ new_serial = atomic_load_explicit(pa->serial(), memory_order_acquire);
+ } while (new_serial == old_serial);
+ return new_serial;
+}
- return my_serial;
+uint32_t __system_property_wait(const prop_info* pi, uint32_t old_serial) {
+ uint32_t new_serial;
+ do {
+ __futex_wait(const_cast<_Atomic(uint_least32_t)*>(&pi->serial), old_serial, nullptr);
+ new_serial = load_const_atomic(&pi->serial, memory_order_acquire);
+ } while (new_serial == old_serial);
+ return new_serial;
}
const prop_info* __system_property_find_nth(unsigned n) {