Permalink
Browse files

communication

  • Loading branch information...
mlang committed Jun 4, 2018
1 parent ea1291d commit 0d2b772d5771118d568c2cb496f1d8cd03edfb0e
Showing with 174 additions and 64 deletions.
  1. +1 −1 AuxTask.h
  2. +0 −21 RTMutex.h
  3. +8 −6 RTPipe.h
  4. +39 −0 RTQueue.h
  5. +126 −36 render.cpp
View
@@ -117,7 +117,7 @@ class AuxTask<NonRT, void (Class::*)()> : AuxTaskNonRT {
function_type const member_function;
Class * const instance;
};
static void call(void *ptr, int size) {
static void call(void *ptr, int) {
auto task = static_cast<storage *>(ptr);
(task->instance->*task->member_function)();
}
View

This file was deleted.

Oops, something went wrong.
View
@@ -4,6 +4,8 @@
#include <fcntl.h>
#include <Bela.h> // rt_fprintf
#include <native/pipe.h>
#include <iostream>
#include <system_error>
class RTPipe {
char const *name;
@@ -13,8 +15,7 @@ class RTPipe {
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();
throw std::system_error(-ret, std::system_category(), name);
}
}
~RTPipe() {
@@ -27,14 +28,15 @@ class RTPipe {
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();
throw std::system_error(errno, std::system_category(), path);
}
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);
template<typename T> void write(T const &obj, int mode = P_NORMAL) {
static_assert(std::is_trivially_copyable<T>::value,
"objects written to a pipe need to be trivially copyable");
int ret = rt_pipe_write(&pipe, &obj, sizeof(T), mode);
if (ret < 0) {
rt_fprintf(stderr, "Failed to write to pipe %s\n", name);
}
View
@@ -0,0 +1,39 @@
#ifndef RTQUEUE_H_DEFINED
#define RTQUEUE_H_DEFINED
#include <native/queue.h>
#include <iostream>
class RTQueue {
RT_QUEUE queue;
public:
RTQueue(char const *name, size_t pool = 0x10000) {
int ret = rt_queue_create(&queue, name, pool, TM_INFINITE, Q_FIFO);
if (ret < 0) {
throw std::system_error(-ret, std::system_category(), name);
}
}
~RTQueue() { rt_queue_delete(&queue); }
void *alloc(size_t size) {
return rt_queue_alloc(&queue, size);
}
void free(void *buf) {
rt_queue_free(&queue, buf);
}
template<typename T, typename... Args> int send(Args&&... args) {
return rt_queue_send(&queue,
new (alloc(sizeof(T))) T(std::forward<Args>(args)...), sizeof(T),
Q_NORMAL
);
}
template<typename T> int write(T const &obj) {
static_assert(std::is_trivially_copyable<T>::value,
"objects written to a queue need to be trivially copyable");
return rt_queue_write(&queue, &obj, sizeof(T), Q_NORMAL);
}
ssize_t receive(void *&buf) {
return rt_queue_receive(&queue, &buf, TM_NONBLOCK);
}
};
#endif
Oops, something went wrong.

0 comments on commit 0d2b772

Please sign in to comment.