summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Gilling2012-03-07 17:30:33 -0600
committerErik Gilling2012-04-18 15:36:17 -0500
commit196b3a5f6f48649500909c66177967abaf05b898 (patch)
tree0451a808b8172db8bfdc37afedc335e7cd71f66c /libsync/sync.c
parent545ab46063f083239b29e59b8b491656d93f2a38 (diff)
downloadplatform-system-core-196b3a5f6f48649500909c66177967abaf05b898.tar.gz
platform-system-core-196b3a5f6f48649500909c66177967abaf05b898.tar.xz
platform-system-core-196b3a5f6f48649500909c66177967abaf05b898.zip
sync: Add lib sync helper library
Used to talk to kernel synchronization framework Change-Id: I66e1f4a90f5d58d384bf1cec09db52101f182c5e Signed-off-by: Erik Gilling <konkers@android.com>
Diffstat (limited to 'libsync/sync.c')
-rw-r--r--libsync/sync.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/libsync/sync.c b/libsync/sync.c
new file mode 100644
index 000000000..311da14cb
--- /dev/null
+++ b/libsync/sync.c
@@ -0,0 +1,115 @@
1/*
2 * sync.c
3 *
4 * Copyright 2012 Google, Inc
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include <fcntl.h>
20#include <stdint.h>
21#include <string.h>
22
23#include <sys/ioctl.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26
27#include <sync/sync.h>
28
29int sync_wait(int fd, unsigned int timeout)
30{
31 __u32 to = timeout;
32
33 return ioctl(fd, SYNC_IOC_WAIT, &to);
34}
35
36int sync_merge(const char *name, int fd1, int fd2)
37{
38 struct sync_merge_data data;
39 int err;
40
41 data.fd2 = fd2;
42 strlcpy(data.name, name, sizeof(data.name));
43
44 err = ioctl(fd1, SYNC_IOC_MERGE, &data);
45 if (err < 0)
46 return err;
47
48 return data.fence;
49}
50
51struct sync_fence_info_data *sync_fence_info(int fd)
52{
53 struct sync_fence_info_data *info;
54 int err;
55
56 info = malloc(4096);
57 if (info == NULL)
58 return NULL;
59
60 info->len = 4096;
61 err = ioctl(fd, SYNC_IOC_FENCE_INFO, info);
62 if (err < 0) {
63 free(info);
64 return NULL;
65 }
66
67 return info;
68}
69
70struct sync_pt_info *sync_pt_info(struct sync_fence_info_data *info,
71 struct sync_pt_info *itr)
72{
73 if (itr == NULL)
74 itr = (struct sync_pt_info *) info->pt_info;
75 else
76 itr = (struct sync_pt_info *) ((__u8 *)itr + itr->len);
77
78 if ((__u8 *)itr - (__u8 *)info >= (int)info->len)
79 return NULL;
80
81 return itr;
82}
83
84void sync_fence_info_free(struct sync_fence_info_data *info)
85{
86 free(info);
87}
88
89
90int sw_sync_timeline_create(void)
91{
92 return open("/dev/sw_sync", O_RDWR);
93}
94
95int sw_sync_timeline_inc(int fd, unsigned count)
96{
97 __u32 arg = count;
98
99 return ioctl(fd, SW_SYNC_IOC_INC, &arg);
100}
101
102int sw_sync_fence_create(int fd, const char *name, unsigned value)
103{
104 struct sw_sync_create_fence_data data;
105 int err;
106
107 data.value = value;
108 strlcpy(data.name, name, sizeof(data.name));
109
110 err = ioctl(fd, SW_SYNC_IOC_CREATE_FENCE, &data);
111 if (err < 0)
112 return err;
113
114 return data.fence;
115}