Rename prop_bt.
Presumably "bt" was "binary tree", but "trie_node" is a bit more
specific and removes the guesswork.
Test: treehugger
Change-Id: Ib5fb2dcbcf261ce516728099d484ed9cd6c069bd
diff --git a/libc/system_properties/include/system_properties/prop_area.h b/libc/system_properties/include/system_properties/prop_area.h
index e32a8d7..187ff75 100644
--- a/libc/system_properties/include/system_properties/prop_area.h
+++ b/libc/system_properties/include/system_properties/prop_area.h
@@ -53,14 +53,14 @@
// +-----+ +-----+ +-----+ +===========+
// Represents a node in the trie.
-struct prop_bt {
+struct prop_trie_node {
uint32_t namelen;
// The property trie is updated only by the init process (single threaded) which provides
// property service. And it can be read by multiple threads at the same time.
// As the property trie is not protected by locks, we use atomic_uint_least32_t types for the
// left, right, children "pointers" in the trie node. To make sure readers who see the
- // change of "pointers" can also notice the change of prop_bt structure contents pointed by
+ // change of "pointers" can also notice the change of prop_trie_node structure contents pointed by
// the "pointers", we always use release-consume ordering pair when accessing these "pointers".
// prop "points" to prop_info structure if there is a propery associated with the trie node.
@@ -79,14 +79,14 @@
char name[0];
- prop_bt(const char* name, const uint32_t name_length) {
+ prop_trie_node(const char* name, const uint32_t name_length) {
this->namelen = name_length;
memcpy(this->name, name, name_length);
this->name[name_length] = '\0';
}
private:
- BIONIC_DISALLOW_COPY_AND_ASSIGN(prop_bt);
+ BIONIC_DISALLOW_COPY_AND_ASSIGN(prop_trie_node);
};
class prop_area {
@@ -105,7 +105,7 @@
atomic_init(&serial_, 0u);
memset(reserved_, 0, sizeof(reserved_));
// Allocate enough space for the root node.
- bytes_used_ = sizeof(prop_bt);
+ bytes_used_ = sizeof(prop_trie_node);
// To make property reads wait-free, we reserve a
// PROP_VALUE_MAX-sized block of memory, the "dirty backup area",
// just after the root node. When we're about to modify a
@@ -136,30 +136,29 @@
uint32_t version() const {
return version_;
}
- char* dirty_backup_area() {
- return data_ + sizeof (prop_bt);
- }
+ char* dirty_backup_area() { return data_ + sizeof(prop_trie_node); }
private:
static prop_area* map_fd_ro(const int fd);
void* allocate_obj(const size_t size, uint_least32_t* const off);
- prop_bt* new_prop_bt(const char* name, uint32_t namelen, uint_least32_t* const off);
+ prop_trie_node* new_prop_trie_node(const char* name, uint32_t namelen, uint_least32_t* const off);
prop_info* new_prop_info(const char* name, uint32_t namelen, const char* value, uint32_t valuelen,
uint_least32_t* const off);
void* to_prop_obj(uint_least32_t off);
- prop_bt* to_prop_bt(atomic_uint_least32_t* off_p);
+ prop_trie_node* to_prop_trie_node(atomic_uint_least32_t* off_p);
prop_info* to_prop_info(atomic_uint_least32_t* off_p);
- prop_bt* root_node();
+ prop_trie_node* root_node();
- prop_bt* find_prop_bt(prop_bt* const bt, const char* name, uint32_t namelen, bool alloc_if_needed);
+ prop_trie_node* find_prop_trie_node(prop_trie_node* const trie, const char* name,
+ uint32_t namelen, bool alloc_if_needed);
- const prop_info* find_property(prop_bt* const trie, const char* name, uint32_t namelen,
+ const prop_info* find_property(prop_trie_node* const trie, const char* name, uint32_t namelen,
const char* value, uint32_t valuelen, bool alloc_if_needed);
- bool foreach_property(prop_bt* const trie, void (*propfn)(const prop_info* pi, void* cookie),
- void* cookie);
+ bool foreach_property(prop_trie_node* const trie,
+ void (*propfn)(const prop_info* pi, void* cookie), void* cookie);
// The original design doesn't include pa_size or pa_data_size in the prop_area struct itself.
// Since we'll need to be backwards compatible with that design, we don't gain much by adding it
diff --git a/libc/system_properties/prop_area.cpp b/libc/system_properties/prop_area.cpp
index 42bee9f..4668eed 100644
--- a/libc/system_properties/prop_area.cpp
+++ b/libc/system_properties/prop_area.cpp
@@ -154,16 +154,15 @@
return data_ + *off;
}
-prop_bt* prop_area::new_prop_bt(const char* name, uint32_t namelen, uint_least32_t* const off) {
+prop_trie_node* prop_area::new_prop_trie_node(const char* name, uint32_t namelen,
+ uint_least32_t* const off) {
uint_least32_t new_offset;
- void* const p = allocate_obj(sizeof(prop_bt) + namelen + 1, &new_offset);
- if (p != nullptr) {
- prop_bt* bt = new (p) prop_bt(name, namelen);
- *off = new_offset;
- return bt;
- }
+ void* const p = allocate_obj(sizeof(prop_trie_node) + namelen + 1, &new_offset);
+ if (p == nullptr) return nullptr;
- return nullptr;
+ prop_trie_node* node = new (p) prop_trie_node(name, namelen);
+ *off = new_offset;
+ return node;
}
prop_info* prop_area::new_prop_info(const char* name, uint32_t namelen, const char* value,
@@ -200,9 +199,9 @@
return (data_ + off);
}
-inline prop_bt* prop_area::to_prop_bt(atomic_uint_least32_t* off_p) {
+inline prop_trie_node* prop_area::to_prop_trie_node(atomic_uint_least32_t* off_p) {
uint_least32_t off = atomic_load_explicit(off_p, memory_order_consume);
- return reinterpret_cast<prop_bt*>(to_prop_obj(off));
+ return reinterpret_cast<prop_trie_node*>(to_prop_obj(off));
}
inline prop_info* prop_area::to_prop_info(atomic_uint_least32_t* off_p) {
@@ -210,8 +209,8 @@
return reinterpret_cast<prop_info*>(to_prop_obj(off));
}
-inline prop_bt* prop_area::root_node() {
- return reinterpret_cast<prop_bt*>(to_prop_obj(0));
+inline prop_trie_node* prop_area::root_node() {
+ return reinterpret_cast<prop_trie_node*>(to_prop_obj(0));
}
static int cmp_prop_name(const char* one, uint32_t one_len, const char* two, uint32_t two_len) {
@@ -223,9 +222,9 @@
return strncmp(one, two, one_len);
}
-prop_bt* prop_area::find_prop_bt(prop_bt* const bt, const char* name, uint32_t namelen,
- bool alloc_if_needed) {
- prop_bt* current = bt;
+prop_trie_node* prop_area::find_prop_trie_node(prop_trie_node* const trie, const char* name,
+ uint32_t namelen, bool alloc_if_needed) {
+ prop_trie_node* current = trie;
while (true) {
if (!current) {
return nullptr;
@@ -239,46 +238,46 @@
if (ret < 0) {
uint_least32_t left_offset = atomic_load_explicit(¤t->left, memory_order_relaxed);
if (left_offset != 0) {
- current = to_prop_bt(¤t->left);
+ current = to_prop_trie_node(¤t->left);
} else {
if (!alloc_if_needed) {
return nullptr;
}
uint_least32_t new_offset;
- prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
- if (new_bt) {
+ prop_trie_node* new_node = new_prop_trie_node(name, namelen, &new_offset);
+ if (new_node) {
atomic_store_explicit(¤t->left, new_offset, memory_order_release);
}
- return new_bt;
+ return new_node;
}
} else {
uint_least32_t right_offset = atomic_load_explicit(¤t->right, memory_order_relaxed);
if (right_offset != 0) {
- current = to_prop_bt(¤t->right);
+ current = to_prop_trie_node(¤t->right);
} else {
if (!alloc_if_needed) {
return nullptr;
}
uint_least32_t new_offset;
- prop_bt* new_bt = new_prop_bt(name, namelen, &new_offset);
- if (new_bt) {
+ prop_trie_node* new_node = new_prop_trie_node(name, namelen, &new_offset);
+ if (new_node) {
atomic_store_explicit(¤t->right, new_offset, memory_order_release);
}
- return new_bt;
+ return new_node;
}
}
}
}
-const prop_info* prop_area::find_property(prop_bt* const trie, const char* name, uint32_t namelen,
- const char* value, uint32_t valuelen,
+const prop_info* prop_area::find_property(prop_trie_node* const trie, const char* name,
+ uint32_t namelen, const char* value, uint32_t valuelen,
bool alloc_if_needed) {
if (!trie) return nullptr;
const char* remaining_name = name;
- prop_bt* current = trie;
+ prop_trie_node* current = trie;
while (true) {
const char* sep = strchr(remaining_name, '.');
const bool want_subtree = (sep != nullptr);
@@ -288,13 +287,13 @@
return nullptr;
}
- prop_bt* root = nullptr;
+ prop_trie_node* root = nullptr;
uint_least32_t children_offset = atomic_load_explicit(¤t->children, memory_order_relaxed);
if (children_offset != 0) {
- root = to_prop_bt(¤t->children);
+ root = to_prop_trie_node(¤t->children);
} else if (alloc_if_needed) {
uint_least32_t new_offset;
- root = new_prop_bt(remaining_name, substr_size, &new_offset);
+ root = new_prop_trie_node(remaining_name, substr_size, &new_offset);
if (root) {
atomic_store_explicit(¤t->children, new_offset, memory_order_release);
}
@@ -304,7 +303,7 @@
return nullptr;
}
- current = find_prop_bt(root, remaining_name, substr_size, alloc_if_needed);
+ current = find_prop_trie_node(root, remaining_name, substr_size, alloc_if_needed);
if (!current) {
return nullptr;
}
@@ -330,13 +329,13 @@
}
}
-bool prop_area::foreach_property(prop_bt* const trie,
+bool prop_area::foreach_property(prop_trie_node* const trie,
void (*propfn)(const prop_info* pi, void* cookie), void* cookie) {
if (!trie) return false;
uint_least32_t left_offset = atomic_load_explicit(&trie->left, memory_order_relaxed);
if (left_offset != 0) {
- const int err = foreach_property(to_prop_bt(&trie->left), propfn, cookie);
+ const int err = foreach_property(to_prop_trie_node(&trie->left), propfn, cookie);
if (err < 0) return false;
}
uint_least32_t prop_offset = atomic_load_explicit(&trie->prop, memory_order_relaxed);
@@ -347,12 +346,12 @@
}
uint_least32_t children_offset = atomic_load_explicit(&trie->children, memory_order_relaxed);
if (children_offset != 0) {
- const int err = foreach_property(to_prop_bt(&trie->children), propfn, cookie);
+ const int err = foreach_property(to_prop_trie_node(&trie->children), propfn, cookie);
if (err < 0) return false;
}
uint_least32_t right_offset = atomic_load_explicit(&trie->right, memory_order_relaxed);
if (right_offset != 0) {
- const int err = foreach_property(to_prop_bt(&trie->right), propfn, cookie);
+ const int err = foreach_property(to_prop_trie_node(&trie->right), propfn, cookie);
if (err < 0) return false;
}