diff options
author | Hector Martin | 2009-10-12 06:10:50 +0200 |
---|---|---|
committer | Hector Martin | 2009-10-12 06:10:50 +0200 |
commit | 07378b9203f949fb7a475115051edb09f134d8ff (patch) | |
tree | fe787e4a29d23c1718264fbec7feb58377944ccd | |
parent | ac37795c7cca4d297ff860678a4197ee94d80f20 (diff) | |
download | usbmuxd-07378b9203f949fb7a475115051edb09f134d8ff.tar.gz usbmuxd-07378b9203f949fb7a475115051edb09f134d8ff.tar.bz2 |
optimize: persist fdlist for duration of main_loop
constant malloc and realloc was wasting lots of time
-rw-r--r-- | common/utils.c | 5 | ||||
-rw-r--r-- | common/utils.h | 1 | ||||
-rw-r--r-- | daemon/main.c | 5 |
3 files changed, 9 insertions, 2 deletions
diff --git a/common/utils.c b/common/utils.c index 6803941..f66d889 100644 --- a/common/utils.c +++ b/common/utils.c @@ -65,6 +65,11 @@ void fdlist_free(struct fdlist *list) list->fds = NULL; } +void fdlist_reset(struct fdlist *list) +{ + list->count = 0; +} + void collection_init(struct collection *col) { col->list = malloc(sizeof(void *)); diff --git a/common/utils.h b/common/utils.h index ad4ac9d..f9cfa93 100644 --- a/common/utils.h +++ b/common/utils.h @@ -39,6 +39,7 @@ struct fdlist { void fdlist_create(struct fdlist *list); void fdlist_add(struct fdlist *list, enum fdowner owner, int fd, short events); void fdlist_free(struct fdlist *list); +void fdlist_reset(struct fdlist *list); struct collection { void **list; diff --git a/daemon/main.c b/daemon/main.c index 893f26d..f85d034 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -138,6 +138,7 @@ int main_loop(int listenfd) int to, cnt, i, dto; struct fdlist pollfds; + fdlist_create(&pollfds); while(!should_exit) { usbmuxd_log(LL_FLOOD, "main_loop iteration"); to = usb_get_timeout(); @@ -147,7 +148,7 @@ int main_loop(int listenfd) if(dto < to) to = dto; - fdlist_create(&pollfds); + fdlist_reset(&pollfds); fdlist_add(&pollfds, FD_LISTEN, listenfd, POLLIN); usb_get_fds(&pollfds); client_get_fds(&pollfds); @@ -201,8 +202,8 @@ int main_loop(int listenfd) } } } - fdlist_free(&pollfds); } + fdlist_free(&pollfds); return 0; } |