provider_ object relies on cache_ vector to be alive, but the order of destruction between these objects at exit are not guaranteed. This can lead to crash at the exit especially on ASAN build. By putting cache_ as a member it is guaranteed that cache_ is not destructed until provider_ is destructed. Test: m ; m AconfigDemoActivity Test: atest aconfig.test Test: observe no crash on _hwasan build Change-Id: If9e23e99c501bf8f06fcab003622948b9e730352
93 lines
1.8 KiB
Plaintext
93 lines
1.8 KiB
Plaintext
#pragma once
|
|
|
|
{{ if not for_test- }}
|
|
{{ if has_fixed_read_only- }}
|
|
#ifndef {package_macro}
|
|
#define {package_macro}(FLAG) {package_macro}_##FLAG
|
|
#endif
|
|
{{ for item in class_elements- }}
|
|
{{ if item.is_fixed_read_only- }}
|
|
#ifndef {package_macro}_{item.flag_macro}
|
|
#define {package_macro}_{item.flag_macro} {item.default_value}
|
|
#endif
|
|
{{ endif }}
|
|
{{ -endfor }}
|
|
{{ -endif }}
|
|
{{ -endif }}
|
|
|
|
#ifdef __cplusplus
|
|
|
|
#include <memory>
|
|
|
|
namespace {cpp_namespace} \{
|
|
|
|
class flag_provider_interface \{
|
|
public:
|
|
virtual ~flag_provider_interface() = default;
|
|
{{ for item in class_elements}}
|
|
virtual bool {item.flag_name}() = 0;
|
|
|
|
{{ if for_test }}
|
|
virtual void {item.flag_name}(bool val) = 0;
|
|
{{ -endif }}
|
|
{{ -endfor }}
|
|
|
|
{{ if for_test }}
|
|
virtual void reset_flags() \{}
|
|
{{ -endif }}
|
|
};
|
|
|
|
extern std::unique_ptr<flag_provider_interface> provider_;
|
|
|
|
{{ for item in class_elements}}
|
|
inline bool {item.flag_name}() \{
|
|
{{ if for_test }}
|
|
return provider_->{item.flag_name}();
|
|
{{ -else- }}
|
|
{{ if item.readwrite- }}
|
|
return provider_->{item.flag_name}();
|
|
{{ -else- }}
|
|
{{ if item.is_fixed_read_only }}
|
|
return {package_macro}_{item.flag_macro};
|
|
{{ -else- }}
|
|
return {item.default_value};
|
|
{{ -endif }}
|
|
{{ -endif }}
|
|
{{ -endif }}
|
|
}
|
|
|
|
{{ if for_test }}
|
|
inline void {item.flag_name}(bool val) \{
|
|
provider_->{item.flag_name}(val);
|
|
}
|
|
{{ -endif }}
|
|
{{ -endfor }}
|
|
|
|
{{ if for_test }}
|
|
inline void reset_flags() \{
|
|
return provider_->reset_flags();
|
|
}
|
|
{{ -endif }}
|
|
|
|
}
|
|
|
|
extern "C" \{
|
|
#endif // __cplusplus
|
|
|
|
{{ for item in class_elements }}
|
|
bool {header}_{item.flag_name}();
|
|
|
|
{{ if for_test }}
|
|
void set_{header}_{item.flag_name}(bool val);
|
|
{{ -endif }}
|
|
{{ -endfor }}
|
|
|
|
{{ if for_test }}
|
|
void {header}_reset_flags();
|
|
{{ -endif }}
|
|
|
|
#ifdef __cplusplus
|
|
} // extern "C"
|
|
#endif
|
|
|