11 #ifndef AUDIOTHREAD_FIFO_H_INCLUDED
12 #define AUDIOTHREAD_FIFO_H_INCLUDED
42 fifo (RingBufferSize),
48 fifodata =
new char[ RingBufferSize * 2 ];
59 return fifo.getTotalSize() == fifo.getFreeSpace();
73 return fifo.getFreeSpace();
98 template <
class Functor>
107 const int allocSize =
static_cast<int>(roundUpToCacheLineBoundary (
sizeof (WorkItem<Functor>)));
108 int idx1, idx2, sz1, sz2;
109 fifo.prepareToWrite (allocSize, idx1, sz1, idx2, sz2);
111 if (sz1 + sz2 < allocSize)
116 new (fifodata + idx1) WorkItem<Functor> (f);
117 fifo.finishedWrite (allocSize);
132 bool didSomething =
false;
134 while (fifo.getNumReady() > 0)
136 int idx1, idx2, sz1, sz2;
137 fifo.prepareToRead (1, idx1, sz1, idx2, sz2);
139 Work* w =
reinterpret_cast<Work*
> (fifodata + idx1);
141 const int sizeofWorkItem = (*w->execAndDestructFn) (w);
142 const int allocSize = roundUpToCacheLineBoundary (sizeofWorkItem);
143 fifo.finishedRead (allocSize);
157 acceptingJobs =
false;
167 typedef int (*WorkExecAndDestructFunctionPtr) (
void* workItemStorage);
173 Work (WorkExecAndDestructFunctionPtr f) :
174 execAndDestructFn (f)
176 WorkExecAndDestructFunctionPtr execAndDestructFn;
180 template <
class Functor>
181 struct WorkItem :
public Work
183 explicit WorkItem (Functor
const& fun) :
184 Work (&WorkItem::myExecAndDestruct),
189 static int myExecAndDestruct (
void* workItemStorage)
192 WorkItem* that =
reinterpret_cast<WorkItem*
> (workItemStorage);
195 return static_cast<int>(
sizeof (WorkItem));
219 int roundUpToCacheLineBoundary (
int x)
231 #endif // AUDIOTHREAD_FIFO_H_INCLUDED
bool synchronize()
Execute all the calls in the queue.
Definition: nonblocking_call_queue.h:130
int getFreeSpace()
Return the amount of free space in the queue.
Definition: nonblocking_call_queue.h:71
Allows a function call to be executed on a different thread, in a fast lock-safe and thread-safe mann...
Definition: nonblocking_call_queue.h:37
bool callf(Functor const &f)
Calls a function, via the queue, on a different thread.
Definition: nonblocking_call_queue.h:99
void stop()
Definition: nonblocking_call_queue.h:155
bool isEmpty()
return true if the queue is empty.
Definition: nonblocking_call_queue.h:57