25 #ifndef RTOSC_THREAD_LINK
26 #define RTOSC_THREAD_LINK
28 #include <jack/ringbuffer.h>
36 typedef const char *
msg_t;
47 ThreadLink(
size_t max_message_length,
size_t max_messages)
48 :MaxMsg(max_message_length),
49 BufferSize(MaxMsg*max_messages),
50 write_buffer(new char[BufferSize]),
51 read_buffer(new char[BufferSize])
53 ring = jack_ringbuffer_create(BufferSize);
54 jack_ringbuffer_mlock(ring);
59 jack_ringbuffer_free(ring);
60 delete[] write_buffer;
68 void write(
const char *dest,
const char *args, ...)
74 if(jack_ringbuffer_write_space(ring) >= len)
75 jack_ringbuffer_write(ring,write_buffer,len);
86 if(jack_ringbuffer_write_space(ring) >= len)
87 jack_ringbuffer_write(ring,write_buffer,len);
96 if(jack_ringbuffer_write_space(ring) >= len)
97 jack_ringbuffer_write(ring,msg,len);
105 return jack_ringbuffer_read_space(ring);
113 jack_ringbuffer_get_read_vector(ring,(jack_ringbuffer_data_t*)r);
116 assert(jack_ringbuffer_read_space(ring) >= len);
117 assert(len <= MaxMsg);
118 jack_ringbuffer_read(ring, read_buffer, len);
133 char *
buffer(
void) {
return write_buffer;}
140 const size_t BufferSize;
145 jack_ringbuffer_t *ring;