mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-01 05:57:37 +00:00
Use mutex_guard to lock su_info
This commit is contained in:
parent
947dae4900
commit
b763b81f56
@ -5,6 +5,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include <db.h>
|
#include <db.h>
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
#define DEFAULT_SHELL "/system/bin/sh"
|
#define DEFAULT_SHELL "/system/bin/sh"
|
||||||
|
|
||||||
@ -29,8 +30,7 @@ public:
|
|||||||
|
|
||||||
su_info(unsigned uid = 0);
|
su_info(unsigned uid = 0);
|
||||||
~su_info();
|
~su_info();
|
||||||
void lock();
|
mutex_guard lock();
|
||||||
void unlock();
|
|
||||||
bool is_fresh();
|
bool is_fresh();
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
|
@ -33,12 +33,8 @@ su_info::~su_info() {
|
|||||||
pthread_mutex_destroy(&_lock);
|
pthread_mutex_destroy(&_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void su_info::lock() {
|
mutex_guard su_info::lock() {
|
||||||
pthread_mutex_lock(&_lock);
|
return mutex_guard(_lock);
|
||||||
}
|
|
||||||
|
|
||||||
void su_info::unlock() {
|
|
||||||
pthread_mutex_unlock(&_lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool su_info::is_fresh() {
|
bool su_info::is_fresh() {
|
||||||
@ -96,10 +92,7 @@ static shared_ptr<su_info> get_su_info(unsigned uid) {
|
|||||||
info = cached;
|
info = cached;
|
||||||
}
|
}
|
||||||
|
|
||||||
info->lock();
|
auto g = info->lock();
|
||||||
run_finally unlock([&] {
|
|
||||||
info->unlock();
|
|
||||||
});
|
|
||||||
|
|
||||||
if (info->access.policy == QUERY) {
|
if (info->access.policy == QUERY) {
|
||||||
// Not cached, get data from database
|
// Not cached, get data from database
|
||||||
|
Loading…
x
Reference in New Issue
Block a user