-
Notifications
You must be signed in to change notification settings - Fork 49
Parallel Libtrace HOWTO: Start Callback
Shane Alcock edited this page Sep 18, 2015
·
4 revisions
Since we're going to need some thread local storage, we are going to begin by defining what our storage looks like and write the code to create and initialise this storage as soon as the thread starts.
We do this by defining what is called a "start callback", i.e. a function that is called when a thread starts for the first time (before any packets are read by that thread). Most non-trivial parallel libtrace programs will probably need some sort of local storage so you will generally require a start callback for your processing threads.
The code for our start callback is given below:
/* Structure for storing our counters */
struct counters {
uint64_t packets;
uint64_t payload;
};
/* The start callback function */
static void *start_processing(libtrace_t *trace, libtrace_thread_t *thread,
void *global) {
/* Create and initialise a counter struct */
struct counters *c = (struct counters *)malloc(sizeof(struct counters));
c->packets = 0;
c->payload = 0;
/* Return our counter struct; it will now be available as one of the
* arguments for all of the other processing callbacks.
*/
return c;
}