diff options
Diffstat (limited to 'kms++/src')
-rw-r--r-- | kms++/src/swsync.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/kms++/src/swsync.cpp b/kms++/src/swsync.cpp new file mode 100644 index 0000000..fde0efe --- /dev/null +++ b/kms++/src/swsync.cpp @@ -0,0 +1,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); +} + +} |