Add flush_my_map_info_list() and fix a bug in the Mac load_map_info_list().

(If you fclose(3) rather than pclose(3) a FILE* you got from popen(3),
future popen(3)s fail obscurely, at least on Mac OS.)

(cherry picked from commit 2bf76e143da933184d1392fb9bea3a3896c37e76)

Change-Id: I5578fe06753061b0dbc5ee951ebf31eb2bab0389
This commit is contained in:
Elliott Hughes 2012-06-13 14:21:23 -07:00 committed by Brian Carlstrom
parent bfec3a3150
commit 89054056a7
3 changed files with 25 additions and 4 deletions

View File

@ -63,6 +63,10 @@ map_info_t* acquire_my_map_info_list();
* previous acquired using acquire_my_map_info_list(). */
void release_my_map_info_list(map_info_t* milist);
/* Flushes the cached memory map so the next call to
* acquire_my_map_info_list() gets fresh data. */
void flush_my_map_info_list();
#ifdef __cplusplus
}
#endif

View File

@ -83,7 +83,7 @@ map_info_t* load_map_info_list(pid_t pid) {
milist = mi;
}
}
fclose(fp);
pclose(fp);
return milist;
}
@ -220,7 +220,7 @@ map_info_t* acquire_my_map_info_list() {
pthread_mutex_lock(&g_my_map_info_list_mutex);
int64_t time = now_ns();
if (g_my_map_info_list) {
if (g_my_map_info_list != NULL) {
my_map_info_data_t* data = (my_map_info_data_t*)g_my_map_info_list->data;
int64_t age = time - data->timestamp;
if (age >= MAX_CACHE_AGE) {
@ -232,10 +232,10 @@ map_info_t* acquire_my_map_info_list() {
}
}
if (!g_my_map_info_list) {
if (g_my_map_info_list == NULL) {
my_map_info_data_t* data = (my_map_info_data_t*)malloc(sizeof(my_map_info_data_t));
g_my_map_info_list = load_map_info_list(getpid());
if (g_my_map_info_list) {
if (g_my_map_info_list != NULL) {
ALOGV("Loaded my_map_info_list %p.", g_my_map_info_list);
g_my_map_info_list->data = data;
data->refs = 1;
@ -265,3 +265,15 @@ void release_my_map_info_list(map_info_t* milist) {
pthread_mutex_unlock(&g_my_map_info_list_mutex);
}
}
void flush_my_map_info_list() {
pthread_mutex_lock(&g_my_map_info_list_mutex);
if (g_my_map_info_list != NULL) {
my_map_info_data_t* data = (my_map_info_data_t*) g_my_map_info_list->data;
dec_ref(g_my_map_info_list, data);
g_my_map_info_list = NULL;
}
pthread_mutex_unlock(&g_my_map_info_list_mutex);
}

View File

@ -66,6 +66,11 @@ extern "C" __attribute__ ((noinline)) int f() {
}
int main() {
flush_my_map_info_list();
f();
flush_my_map_info_list();
f();
return 0;
}