Just got some information on data logging for haptic thread. It's basically a data structure for the buffering of data on a haptic thread but I didn't understood completely how to use this for my application. It's basically a header. I'm attaching it here:
/******
*
* Written by Dan Morris
* dmorris@cs.stanford.edu
* http://cs.stanford.edu/~dmorris
*
* You can do anything you want with this file as long as this header
* stays on it and I am credited when it's appropriate.
*
******/
#ifndef _BLOCK_LINKED_LIST_H_
#define _BLOCK_LINKED_LIST_H_
// This is a custom data structure that I used for buffering data on
// its way out to disk. It is not a random access data structure;
// it just buffers up objects of type T and flushes them out to disk.
//
// If you're using flusher and writer threads, the general protocol
// is to only allow the writer to call the push_back function, and
// let the reader use the safe_flush function to do its flushing.
// Then at some point when the writer is done forever, the reader can
// call flush() to flush the remaining blocks that were currently in use
// by the writer.
//
// This is a lock-free solution to the producer-consumer problem with the
// constraint that immediate consumption is not important.
//
// This addresses a common access pattern for applications that have a time-
// critical thread (e.g. a haptics thread) that generates data that
// needs to be logged to disk. This approach avoids any disk access or
// mutex access on the high-priority thread. I've used this data
// structure for haptics (where a high-priority thread generates forces)
// and neurophysiology/psychophysics (where a high-priority thread
// controls an experiment).
//
// Note that in this mode, the "flusher" thread should _not_ also put
// data into the array; i.e. the writer thread "owns" the push_back
// function.
// The node type for the linked list
template class block_linked_list_node {
public:
// An array of T's
T* data;
block_linked_list_node* next;
block_linked_list_node() {
data = new T[chunk_size];
next = 0;
}
~block_linked_list_node() {
delete [] data;
}
};
// The data structure itself
template class block_linked_list {
public:
// The head of the list
block_linked_list_node* head;
// The number of T's in the list
size_t total_count;
// A pointer to the curren