summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Hall2017-02-12 18:17:22 -0600
committerJesse Hall2017-02-23 20:44:50 -0600
commit89530820d7f5837f00f3f04e18dfa05c7506eb68 (patch)
tree139b29fe359550c6999821b9dd499ed228849ed7 /libsync/sync.c
parent081806e5f2e9f8b573827b0f3d4b35d8ddb64cb9 (diff)
downloadplatform-system-core-89530820d7f5837f00f3f04e18dfa05c7506eb68.tar.gz
platform-system-core-89530820d7f5837f00f3f04e18dfa05c7506eb68.tar.xz
platform-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/sync.c')
-rw-r--r--libsync/sync.c96
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)
98 return data.fence; 98 return data.fence;
99} 99}
100 100
101struct sync_fence_info_data *sync_fence_info(int fd) 101static struct sync_fence_info_data *legacy_sync_fence_info(int fd)
102{ 102{
103 struct sync_fence_info_data *legacy_info; 103 struct sync_fence_info_data *legacy_info;
104 struct sync_pt_info *legacy_pt_info; 104 struct sync_pt_info *legacy_pt_info;
105 struct sync_file_info *info; 105 int err;
106 struct sync_fence_info *fence_info;
107 int err, num_fences, i;
108 106
109 legacy_info = malloc(4096); 107 legacy_info = malloc(4096);
110 if (legacy_info == NULL) 108 if (legacy_info == NULL)
@@ -112,46 +110,57 @@ struct sync_fence_info_data *sync_fence_info(int fd)
112 110
113 legacy_info->len = 4096; 111 legacy_info->len = 4096;
114 err = ioctl(fd, SYNC_IOC_LEGACY_FENCE_INFO, legacy_info); 112 err = ioctl(fd, SYNC_IOC_LEGACY_FENCE_INFO, legacy_info);
115 if (err < 0 && errno != ENOTTY) { 113 if (err < 0) {
116 free(legacy_info); 114 free(legacy_info);
117 return NULL; 115 return NULL;
118 } else if (err == 0) {
119 return legacy_info;
120 } 116 }
117 return legacy_info;
118}
121 119
122 info = calloc(1, sizeof(*info)); 120static struct sync_file_info *modern_sync_file_info(int fd)
123 if (info == NULL) 121{
124 goto free; 122 struct sync_file_info local_info;
123 struct sync_file_info *info;
124 int err;
125 125
126 err = ioctl(fd, SYNC_IOC_FILE_INFO, info); 126 memset(&local_info, 0, sizeof(local_info));
127 err = ioctl(fd, SYNC_IOC_FILE_INFO, &local_info);
127 if (err < 0) 128 if (err < 0)
128 goto free; 129 return NULL;
129 130
130 num_fences = info->num_fences; 131 info = calloc(1, sizeof(struct sync_file_info) +
131 132 local_info.num_fences * sizeof(struct sync_fence_info));
132 if (num_fences) { 133 if (!info)
133 info->flags = 0; 134 return NULL;
134 info->num_fences = num_fences; 135 info->sync_fence_info = (__u64)(uintptr_t)(info + 1);
135 info->sync_fence_info = (uint64_t) calloc(num_fences, 136
136 sizeof(struct sync_fence_info)); 137 err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
137 if ((void *)info->sync_fence_info == NULL) 138 if (err < 0) {
138 goto free; 139 free(info);
139 140 return NULL;
140 err = ioctl(fd, SYNC_IOC_FILE_INFO, info);
141 if (err < 0) {
142 free((void *)info->sync_fence_info);
143 goto free;
144 }
145 } 141 }
146 142
143 return info;
144}
145
146static struct sync_fence_info_data *sync_file_info_to_legacy_fence_info(
147 const struct sync_file_info *info)
148{
149 struct sync_fence_info_data *legacy_info;
150 struct sync_pt_info *legacy_pt_info;
151 const struct sync_fence_info *fence_info = sync_get_fence_info(info);
152 const uint32_t num_fences = info->num_fences;
153
154 legacy_info = malloc(4096);
155 if (legacy_info == NULL)
156 return NULL;
147 legacy_info->len = sizeof(*legacy_info) + 157 legacy_info->len = sizeof(*legacy_info) +
148 num_fences * sizeof(struct sync_pt_info); 158 num_fences * sizeof(struct sync_pt_info);
149 strlcpy(legacy_info->name, info->name, sizeof(legacy_info->name)); 159 strlcpy(legacy_info->name, info->name, sizeof(legacy_info->name));
150 legacy_info->status = info->status; 160 legacy_info->status = info->status;
151 161
152 legacy_pt_info = (struct sync_pt_info *)legacy_info->pt_info; 162 legacy_pt_info = (struct sync_pt_info *)legacy_info->pt_info;
153 fence_info = (struct sync_fence_info *)info->sync_fence_info; 163 for (uint32_t i = 0; i < num_fences; i++) {
154 for (i = 0 ; i < num_fences ; i++) {
155 legacy_pt_info[i].len = sizeof(*legacy_pt_info); 164 legacy_pt_info[i].len = sizeof(*legacy_pt_info);
156 strlcpy(legacy_pt_info[i].obj_name, fence_info[i].obj_name, 165 strlcpy(legacy_pt_info[i].obj_name, fence_info[i].obj_name,
157 sizeof(legacy_pt_info->obj_name)); 166 sizeof(legacy_pt_info->obj_name));
@@ -161,14 +170,24 @@ struct sync_fence_info_data *sync_fence_info(int fd)
161 legacy_pt_info[i].timestamp_ns = fence_info[i].timestamp_ns; 170 legacy_pt_info[i].timestamp_ns = fence_info[i].timestamp_ns;
162 } 171 }
163 172
164 free((void *)info->sync_fence_info);
165 free(info);
166 return legacy_info; 173 return legacy_info;
174}
167 175
168free: 176struct sync_fence_info_data *sync_fence_info(int fd)
169 free(legacy_info); 177{
170 free(info); 178 struct sync_fence_info_data *legacy_info;
171 return NULL; 179
180 legacy_info = legacy_sync_fence_info(fd);
181 if (legacy_info || errno != ENOTTY)
182 return legacy_info;
183
184 struct sync_file_info* file_info;
185 file_info = modern_sync_file_info(fd);
186 if (!file_info)
187 return NULL;
188 legacy_info = sync_file_info_to_legacy_fence_info(file_info);
189 sync_file_info_free(file_info);
190 return legacy_info;
172} 191}
173 192
174struct sync_pt_info *sync_pt_info(struct sync_fence_info_data *info, 193struct 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)
190 free(info); 209 free(info);
191} 210}
192 211
212void sync_file_info_free(struct sync_file_info *info)
213{
214 free(info);
215}
216
193 217
194int sw_sync_timeline_create(void) 218int sw_sync_timeline_create(void)
195{ 219{