diff options
author | Jesse Hall <jessehall@google.com> | 2017-02-12 16:17:22 -0800 |
---|---|---|
committer | Jesse Hall <jessehall@google.com> | 2017-02-23 18:44:50 -0800 |
commit | 89530820d7f5837f00f3f04e18dfa05c7506eb68 (patch) | |
tree | 139b29fe359550c6999821b9dd499ed228849ed7 /libsync | |
parent | 081806e5f2e9f8b573827b0f3d4b35d8ddb64cb9 (diff) | |
download | system_core-89530820d7f5837f00f3f04e18dfa05c7506eb68.tar.gz system_core-89530820d7f5837f00f3f04e18dfa05c7506eb68.tar.bz2 system_core-89530820d7f5837f00f3f04e18dfa05c7506eb68.zip |
sync: refactor sync_fence_info
Split the sync_fence_info implementation into multiple functions. This
clarifies the logic, and allows the parts to be reused in the upcoming
sync_file_info function.
Test: sync-unit-tests on bullhead
Change-Id: I0ea37067dddf41b831670f08eb99e0b7fd52adce
Diffstat (limited to 'libsync')
-rw-r--r-- | libsync/sync.c | 96 |
1 files changed, 60 insertions, 36 deletions
diff --git a/libsync/sync.c b/libsync/sync.c index 0e9ad4382..6680f1102 100644 --- a/libsync/sync.c +++ b/libsync/sync.c @@ -98,13 +98,11 @@ int sync_merge(const char *name, int fd1, int fd2) return data.fence; } -struct sync_fence_info_data *sync_fence_info(int fd) +static struct sync_fence_info_data *legacy_sync_fence_info(int fd) { struct sync_fence_info_data *legacy_info; struct sync_pt_info *legacy_pt_info; - struct sync_file_info *info; - struct sync_fence_info *fence_info; - int err, num_fences, i; + int err; legacy_info = malloc(4096); if (legacy_info == NULL) @@ -112,46 +110,57 @@ struct sync_fence_info_data *sync_fence_info(int fd) legacy_info->len = 4096; err = ioctl(fd, SYNC_IOC_LEGACY_FENCE_INFO, legacy_info); - if (err < 0 && errno != ENOTTY) { + if (err < 0) { free(legacy_info); return NULL; - } else if (err == 0) { - return legacy_info; } + return legacy_info; +} - info = calloc(1, sizeof(*info)); - if (info == NULL) - goto free; +static struct sync_file_info *modern_sync_file_info(int fd) +{ + struct sync_file_info local_info; + struct sync_file_info *info; + int err; - err = ioctl(fd, SYNC_IOC_FILE_INFO, info); + memset(&local_info, 0, sizeof(local_info)); + err = ioctl(fd, SYNC_IOC_FILE_INFO, &local_info); if (err < 0) - goto free; - - num_fences = info->num_fences; - - if (num_fences) { - info->flags = 0; - info->num_fences = num_fences; - info->sync_fence_info = (uint64_t) calloc(num_fences, - sizeof(struct sync_fence_info)); - if ((void *)info->sync_fence_info == NULL) - goto free; - - err = ioctl(fd, SYNC_IOC_FILE_INFO, info); - if (err < 0) { - free((void *)info->sync_fence_info); - goto free; - } + return NULL; + + info = calloc(1, sizeof(struct sync_file_info) + + local_info.num_fences * sizeof(struct sync_fence_info)); + if (!info) + return NULL; + info->sync_fence_info = (__u64)(uintptr_t)(info + 1); + + err = ioctl(fd, SYNC_IOC_FILE_INFO, info); + if (err < 0) { + free(info); + return NULL; } + return info; +} + +static struct sync_fence_info_data *sync_file_info_to_legacy_fence_info( + const struct sync_file_info *info) +{ + struct sync_fence_info_data *legacy_info; + struct sync_pt_info *legacy_pt_info; + const struct sync_fence_info *fence_info = sync_get_fence_info(info); + const uint32_t num_fences = info->num_fences; + + legacy_info = malloc(4096); + if (legacy_info == NULL) + return NULL; legacy_info->len = sizeof(*legacy_info) + num_fences * sizeof(struct sync_pt_info); strlcpy(legacy_info->name, info->name, sizeof(legacy_info->name)); legacy_info->status = info->status; legacy_pt_info = (struct sync_pt_info *)legacy_info->pt_info; - fence_info = (struct sync_fence_info *)info->sync_fence_info; - for (i = 0 ; i < num_fences ; i++) { + for (uint32_t i = 0; i < num_fences; i++) { legacy_pt_info[i].len = sizeof(*legacy_pt_info); strlcpy(legacy_pt_info[i].obj_name, fence_info[i].obj_name, sizeof(legacy_pt_info->obj_name)); @@ -161,14 +170,24 @@ struct sync_fence_info_data *sync_fence_info(int fd) legacy_pt_info[i].timestamp_ns = fence_info[i].timestamp_ns; } - free((void *)info->sync_fence_info); - free(info); return legacy_info; +} -free: - free(legacy_info); - free(info); - return NULL; +struct sync_fence_info_data *sync_fence_info(int fd) +{ + struct sync_fence_info_data *legacy_info; + + legacy_info = legacy_sync_fence_info(fd); + if (legacy_info || errno != ENOTTY) + return legacy_info; + + struct sync_file_info* file_info; + file_info = modern_sync_file_info(fd); + if (!file_info) + return NULL; + legacy_info = sync_file_info_to_legacy_fence_info(file_info); + sync_file_info_free(file_info); + return legacy_info; } struct sync_pt_info *sync_pt_info(struct sync_fence_info_data *info, @@ -190,6 +209,11 @@ void sync_fence_info_free(struct sync_fence_info_data *info) free(info); } +void sync_file_info_free(struct sync_file_info *info) +{ + free(info); +} + int sw_sync_timeline_create(void) { |