Permalink
Browse files

wip

  • Loading branch information...
mlang committed Jun 2, 2018
1 parent c1d7048 commit ea1291d64ff915743b31bfc207d41ec15c0f8629
Showing with 245 additions and 82 deletions.
  1. +21 −0 RTMutex.h
  2. +44 −0 RTPipe.h
  3. +180 −82 render.cpp
View
@@ -0,0 +1,21 @@
#ifndef RTMUTEX_H_DEFINED
#define RTMUTEX_H_DEFINED
#include <iostream>
#include <native/mutex.h>
class RTMutex {
RT_MUTEX mutex;
public:
RTMutex(char const *name) {
if (rt_mutex_create(&mutex, name) < 0) {
std::cerr << "Failed to create mutex " << name << std::endl;
throw std::bad_alloc();
}
}
~RTMutex() { rt_mutex_delete(&mutex); }
void lock() { rt_mutex_acquire(&mutex, TM_INFINITE); }
void unlock() { rt_mutex_release(&mutex); }
};
#endif // RTMUTEX_H_DEFINED
View
@@ -0,0 +1,44 @@
#ifndef RTPIPE_H_DEFINED
#define RTPIPE_H_DEFINED
#include <fcntl.h>
#include <Bela.h> // rt_fprintf
#include <native/pipe.h>
class RTPipe {
char const *name;
RT_PIPE pipe;
int fd = -1;
public:
RTPipe(char const *name, size_t pool = 0) : name(name) {
int ret = rt_pipe_create(&pipe, name, P_MINOR_AUTO, pool);
if (ret < 0) {
std::cerr << "Failed to create pipe " << name << std::endl;
throw std::bad_alloc();
}
}
~RTPipe() {
rt_pipe_delete(&pipe);
if (fd != -1)
close(fd);
}
int open() {
std::string path = "/proc/xenomai/registry/rtipc/xddp/";
path += name;
fd = ::open(path.c_str(), O_RDWR);
if (fd < 0) {
std::cerr << "Failed to open pipe " << name << std::endl;
throw std::bad_alloc();
}
return fd;
}
int fileDescriptor() const { return fd; }
void write(void *buf, size_t size, int mode = P_NORMAL) {
int ret = rt_pipe_write(&pipe, buf, size, mode);
if (ret < 0) {
rt_fprintf(stderr, "Failed to write to pipe %s\n", name);
}
}
};
#endif // RTPIPE_H_DEFINED
Oops, something went wrong.

0 comments on commit ea1291d

Please sign in to comment.