Changeset 22a9ccc


Ignore:
Timestamp:
02/09/10 11:21:16 (11 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
f6730d8
Parents:
8414770
Message:
  • Updated licensing and documentation for all the IO writer modules
  • Got rid of annoying "Write thread leaving" message!
  • Added Id keyword support to all IO modules
Location:
lib
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • lib/ior-bzip.c

    r8414770 r22a9ccc  
    2828 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2929 *
    30  * $Id: format_erf.c 1517 2010-02-08 01:11:04Z salcock $
     30 * $Id$
    3131 *
    3232 */
  • lib/ior-peek.c

    r8414770 r22a9ccc  
    2828 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2929 *
    30  * $Id: format_erf.c 1517 2010-02-08 01:11:04Z salcock $
     30 * $Id$
    3131 *
    3232 */
  • lib/ior-stdio.c

    r8414770 r22a9ccc  
    2828 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2929 *
    30  * $Id: libtrace.h.in 1511 2010-02-05 03:23:49Z salcock $
     30 * $Id$
    3131 *
    3232 */
  • lib/ior-thread.c

    r8414770 r22a9ccc  
    2828 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2929 *
    30  * $Id: format_erf.c 1517 2010-02-08 01:11:04Z salcock $
     30 * $Id$
    3131 *
    3232 */
  • lib/ior-zlib.c

    r8414770 r22a9ccc  
    2828 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2929 *
    30  * $Id: format_erf.c 1517 2010-02-08 01:11:04Z salcock $
     30 * $Id$
    3131 *
    3232 */
  • lib/iow-bzip.c

    rc66068d r22a9ccc  
     1/*
     2 * This file is part of libtrace
     3 *
     4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton,
     5 * New Zealand.
     6 *
     7 * Authors: Daniel Lawson
     8 *          Perry Lorier
     9 *          Shane Alcock
     10 *         
     11 * All rights reserved.
     12 *
     13 * This code has been developed by the University of Waikato WAND
     14 * research group. For further information please see http://www.wand.net.nz/
     15 *
     16 * libtrace is free software; you can redistribute it and/or modify
     17 * it under the terms of the GNU General Public License as published by
     18 * the Free Software Foundation; either version 2 of the License, or
     19 * (at your option) any later version.
     20 *
     21 * libtrace is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with libtrace; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     29 *
     30 * $Id$
     31 *
     32 */
     33
    134#include "wandio.h"
    235#include <bzlib.h>
     
    639#include <stdlib.h>
    740#include <string.h>
     41
     42/* Libtrace IO module implement a bzip writer */
    843
    944enum err_t {
  • lib/iow-stdio.c

    rc66068d r22a9ccc  
     1/*
     2 * This file is part of libtrace
     3 *
     4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton,
     5 * New Zealand.
     6 *
     7 * Authors: Daniel Lawson
     8 *          Perry Lorier
     9 *          Shane Alcock
     10 *         
     11 * All rights reserved.
     12 *
     13 * This code has been developed by the University of Waikato WAND
     14 * research group. For further information please see http://www.wand.net.nz/
     15 *
     16 * libtrace is free software; you can redistribute it and/or modify
     17 * it under the terms of the GNU General Public License as published by
     18 * the Free Software Foundation; either version 2 of the License, or
     19 * (at your option) any later version.
     20 *
     21 * libtrace is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with libtrace; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     29 *
     30 * $Id$
     31 *
     32 */
     33
     34
    135#include "wandio.h"
    236#include <sys/types.h>
     
    640#include <unistd.h>
    741#include <string.h>
     42
     43/* Libtrace IO module implementing a standard IO writer, i.e. no decompression
     44 */
    845
    946struct stdiow_t {
  • lib/iow-thread.c

    r15e9390 r22a9ccc  
     1/*
     2 * This file is part of libtrace
     3 *
     4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton,
     5 * New Zealand.
     6 *
     7 * Authors: Daniel Lawson
     8 *          Perry Lorier
     9 *          Shane Alcock
     10 *         
     11 * All rights reserved.
     12 *
     13 * This code has been developed by the University of Waikato WAND
     14 * research group. For further information please see http://www.wand.net.nz/
     15 *
     16 * libtrace is free software; you can redistribute it and/or modify
     17 * it under the terms of the GNU General Public License as published by
     18 * the Free Software Foundation; either version 2 of the License, or
     19 * (at your option) any later version.
     20 *
     21 * libtrace is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with libtrace; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     29 *
     30 * $Id$
     31 *
     32 */
     33
    134#include "wandio.h"
    235#include <sys/types.h>
     
    841#include <stdbool.h>
    942
     43/* Libtrace IO module implementing a threaded writer.
     44 *
     45 * This module enables another IO writer, called the "child", to perform its
     46 * writing using a separate thread. The main thread writes data into a series
     47 * of 1MB buffers. Meanwhile, the writing thread writes out of these buffers
     48 * using the callback for the child reader. pthread conditions are used to
     49 * communicate between the two threads, e.g. when there are buffers available
     50 * for the main thread to copy data into or when there is data available for
     51 * the write thread to write.
     52 */
     53
    1054/* 1MB Buffer */
    1155#define BUFFERSIZE (1024*1024)
     
    1458extern iow_source_t thread_wsource;
    1559
     60/* This structure defines a single buffer or "slice" */
    1661struct buffer_t {
    17         char buffer[BUFFERSIZE];
    18         int len;
    19         enum { EMPTY = 0, FULL = 1 } state;
     62        char buffer[BUFFERSIZE];        /* The buffer itself */
     63        int len;                        /* The size of the buffer */
     64        enum { EMPTY = 0, FULL = 1 } state;     /* Is the buffer in use? */
    2065};
    2166
    2267struct state_t {
     68        /* The collection of buffers (or slices) */
    2369        struct buffer_t buffer[BUFFERS];
     70        /* The write offset into the current buffer */
    2471        off_t offset;
     72        /* The writing thread */
    2573        pthread_t consumer;
     74        /* The child writer */
    2675        iow_t *iow;
     76        /* Indicates that there is data in one of the buffers */
    2777        pthread_cond_t data_ready;
     78        /* Indicates that there is a free buffer to write into */
    2879        pthread_cond_t space_avail;
     80        /* The mutex for the write buffers */
    2981        pthread_mutex_t mutex;
     82        /* The index of the buffer to write into next */
    3083        int out_buffer;
     84        /* Indicates whether the main thread is concluding */
    3185        bool closing;
    3286};
     
    3690#define min(a,b) ((a)<(b) ? (a) : (b))
    3791
     92/* The writing thread */
    3893static void *thread_consumer(void *userdata)
    3994{
     
    4499        pthread_mutex_lock(&DATA(state)->mutex);
    45100        do {
     101                /* Wait for data that we can write */
    46102                while (DATA(state)->buffer[buffer].state == EMPTY) {
     103                        /* Unless, of course, the program is over! */
    47104                        if (DATA(state)->closing)
    48105                                break;
     
    50107                                        &DATA(state)->mutex);
    51108                }
    52                 /* Empty the buffer */
    53 
     109               
     110                /* Empty the buffer using the child writer */
    54111                pthread_mutex_unlock(&DATA(state)->mutex);
    55112                wandio_wwrite(
     
    59116                pthread_mutex_lock(&DATA(state)->mutex);
    60117
    61                 /* if we've not reached the end of the file keep going */
     118                /* If we've not reached the end of the file keep going */
    62119                running = ( DATA(state)->buffer[buffer].len > 0 );
    63120                DATA(state)->buffer[buffer].len = 0;
    64121                DATA(state)->buffer[buffer].state = EMPTY;
    65122
     123                /* Signal that we've freed up another buffer for the main
     124                 * thread to copy data into */
    66125                pthread_cond_signal(&DATA(state)->space_avail);
    67126
    68127
    69                 /* Flip buffers */
     128                /* Move on to the next buffer */
    70129                buffer=(buffer+1) % BUFFERS;
    71130
    72131        } while(running);
    73132
    74         fprintf(stderr,"Write thread leaving\n");
    75 
     133        /* If we reach here, it's all over so start tidying up */
    76134        wandio_wdestroy(DATA(state)->iow);
    77135
     
    102160        DATA(state)->closing = false;
    103161
     162        /* Start the writer thread */
    104163        pthread_create(&DATA(state)->consumer,NULL,thread_consumer,state);
    105164
     
    115174        pthread_mutex_lock(&DATA(state)->mutex);
    116175        while(len>0) {
     176
     177                /* Wait for there to be space available for us to write into */
    117178                while (OUTBUFFER(state).state == FULL) {
    118179                        pthread_cond_wait(&DATA(state)->space_avail,
     
    120181                }
    121182
     183                /* Copy out of our main buffer into the next available slice */
    122184                slice=min(
    123185                        (off_t)sizeof(OUTBUFFER(state).buffer)-DATA(state)->offset,
     
    140202                newbuffer = DATA(state)->out_buffer;
    141203
     204                /* If we've filled a buffer, move on to the next one and
     205                 * signal to the write thread that there is something for it
     206                 * to do */
    142207                if (DATA(state)->offset >= (off_t)sizeof(OUTBUFFER(state).buffer)) {
    143208                        OUTBUFFER(state).state = FULL;
  • lib/iow-zlib.c

    rdb03808 r22a9ccc  
     1/*
     2 * This file is part of libtrace
     3 *
     4 * Copyright (c) 2007,2008,2009,2010 The University of Waikato, Hamilton,
     5 * New Zealand.
     6 *
     7 * Authors: Daniel Lawson
     8 *          Perry Lorier
     9 *          Shane Alcock
     10 *         
     11 * All rights reserved.
     12 *
     13 * This code has been developed by the University of Waikato WAND
     14 * research group. For further information please see http://www.wand.net.nz/
     15 *
     16 * libtrace is free software; you can redistribute it and/or modify
     17 * it under the terms of the GNU General Public License as published by
     18 * the Free Software Foundation; either version 2 of the License, or
     19 * (at your option) any later version.
     20 *
     21 * libtrace is distributed in the hope that it will be useful,
     22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24 * GNU General Public License for more details.
     25 *
     26 * You should have received a copy of the GNU General Public License
     27 * along with libtrace; if not, write to the Free Software
     28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     29 *
     30 * $Id$
     31 *
     32 */
     33
     34
    135#include <zlib.h>
    236#include "wandio.h"
     
    640#include <stdlib.h>
    741#include <string.h>
     42
     43/* Libtrace IO module implementing a zlib writer */
    844
    945enum err_t {
Note: See TracChangeset for help on using the changeset viewer.