From 14c5c60863b7f65f206ad3716ec3c8c824602897 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 29 May 2017 18:56:00 +0800 Subject: [PATCH] Improve excessive rapid root access performance --- jni/Android.mk | 3 ++- jni/su | 2 +- jni/utils/list.c | 38 ++++++++++++++++++++++++++++++++++++++ jni/utils/list.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 jni/utils/list.c create mode 100644 jni/utils/list.h diff --git a/jni/Android.mk b/jni/Android.mk index ef67f5f48..cd6a2160b 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -19,6 +19,7 @@ LOCAL_SRC_FILES := \ utils/misc.c \ utils/vector.c \ utils/xwrap.c \ + utils/list.c \ daemon/daemon.c \ daemon/socket_trans.c \ daemon/log_monitor.c \ @@ -40,7 +41,7 @@ LOCAL_SRC_FILES := \ su/db.c \ su/misc.c \ su/pts.c \ - su/su_client.c \ + su/su_daemon.c \ su/su_socket.c LOCAL_CFLAGS := -Wno-implicit-exception-spec-mismatch diff --git a/jni/su b/jni/su index 34fede716..4f570658c 160000 --- a/jni/su +++ b/jni/su @@ -1 +1 @@ -Subproject commit 34fede71678201a0c7a7183d3ac0f8777f9238b2 +Subproject commit 4f570658cce06f5b07edb8cc4c2cd0f900bfec11 diff --git a/jni/utils/list.c b/jni/utils/list.c new file mode 100644 index 000000000..d7f5768c2 --- /dev/null +++ b/jni/utils/list.c @@ -0,0 +1,38 @@ +/* list.h - Double link list implementation + */ + +#include +#include + +#include "list.h" + +void init_list_head(struct list_head *head) { + head->next = head; + head->prev = head; +} + +void list_insert(struct list_head *pos, struct list_head *node) { + // First construct our new node + node->next = pos->next; + node->prev = pos; + // Maintain the list + pos->next->prev = node; + pos->next = node; +} + +void list_insert_end(struct list_head *head, struct list_head *node) { + list_insert(head->prev, node); +} + +void list_pop(struct list_head *pos) { + // Maintain the list + pos->prev->next = pos->next; + pos->next->prev = pos->prev; + // Remove references + pos->next = pos; + pos->prev = pos; +} + +void list_pop_end(struct list_head *head) { + return list_pop(head->prev); +} diff --git a/jni/utils/list.h b/jni/utils/list.h new file mode 100644 index 000000000..9108f5d70 --- /dev/null +++ b/jni/utils/list.h @@ -0,0 +1,30 @@ +/* list.h - Double link list implementation + */ + +#ifndef _LIST_H_ +#define _LIST_H_ + +#include + +struct list_head { + struct list_head *next; + struct list_head *prev; +}; + +void init_list_head(struct list_head *head); +void list_insert(struct list_head *pos, struct list_head *node); +void list_insert_end(struct list_head *head, struct list_head *node); +void list_pop(struct list_head *pos); +void list_pop_end(struct list_head *head); + +#define list_entry(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + +#define list_for_each(pos, head) \ + for (pos = (head)->next; pos != (head); pos = pos->next) + +#define list_for_each_r(pos, head) \ + for (pos = (head)->prev; pos != (head); pos = pos->prev) + +#endif \ No newline at end of file