blob: fde0efe4b18592c1678b28b57e356b14535e8623 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <linux/ioctl.h>
#include <linux/types.h>
#include <kms++/kms++.h>
struct sw_sync_create_fence_data {
__u32 value;
char name[32];
__s32 fence; /* fd of new fence */
};
#define SW_SYNC_IOC_MAGIC 'W'
#define SW_SYNC_IOC_CREATE_FENCE _IOWR(SW_SYNC_IOC_MAGIC, 0, struct sw_sync_create_fence_data)
#define SW_SYNC_IOC_INC _IOW (SW_SYNC_IOC_MAGIC, 1, __u32)
using namespace std;
namespace kms
{
SWSyncTimeline::SWSyncTimeline()
: m_value(0)
{
m_fd = open("/sys/kernel/debug/sync/sw_sync", 0);
if (m_fd == -1)
throw std::runtime_error("Failed to open sw_sync file");
}
SWSyncTimeline::~SWSyncTimeline()
{
close(m_fd);
}
SWSync *SWSyncTimeline::createFence(uint32_t value)
{
struct sw_sync_create_fence_data data = { value };
int ret;
ret = ioctl(m_fd, SW_SYNC_IOC_CREATE_FENCE, &data);
if (ret < 0)
return NULL;
return new SWSync(data.fence);
}
void SWSyncTimeline::signal(uint32_t value)
{
ioctl(m_fd, SW_SYNC_IOC_INC, &value);
m_value += value;
}
SWSync::SWSync(int fd)
: m_fd(fd)
{
}
SWSync::~SWSync()
{
close(m_fd);
}
}
|