Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

circ_buff.h

Go to the documentation of this file.
00001 #ifndef __CIRC_BUFF_H
00002 #define __CIRC_BUFF_H
00003 
00015 #define _GNU_SOURCE
00016 #include <string.h>
00017 #include <stdlib.h>
00018 #include <stdio.h> 
00019 #include <sys/time.h>
00020 #include <errno.h>
00021 #include <pthread.h>
00022 
00023 
00024 
00025 /*
00026 This is essentially just a struct that has a couple of accessor functions
00027 to use on it.  The struct contains a pointer to the address of the buffer
00028 and other essential items like the size of the buffer the offset of both
00029 the read point and the write point.  The read point is defined as the 
00030 starting point with which to read from the buffer.  The write point is the
00031 location to start writing when data gets put into the buffer.  Another
00032 item that is in the struct is how much data is in the buffer.  The struct
00033 */
00034 
00036 struct circ_buff {
00037    long buff_size;       
00038    long write_pnt;       
00039    long read_pnt;        
00040    long byte_count;      
00041    unsigned long long byte_id;         
00042    pthread_mutex_t circ_write_mut; 
00043    pthread_mutex_t circ_read_mut;   
00044    pthread_mutex_t circ_size_var_mut; 
00046    pthread_mutex_t circ_write_cond_mut; 
00049    pthread_cond_t circ_write_cond_var;  
00052    pthread_mutex_t circ_read_cond_mut;  
00055    pthread_cond_t circ_read_cond_var;  
00058    void *buff_ptr;     
00059 };
00060  
00061 typedef struct circ_buff circ_buff_t;
00062 
00063 
00064 int circ_buff_init(circ_buff_t **new_buff, long buff_size);
00065 
00066 void circ_buff_destroy(circ_buff_t *new_buff);
00067 
00068 int circ_buff_init_thread(circ_buff_t *new_buff, long *thread_read_pnt,
00069                                         unsigned long long *thread_byte_id,
00070                                 struct timespec *timeout);
00071 
00072 int circ_buff_wait_to_start(circ_buff_t *new_buff,
00073                                          unsigned long long thread_byte_id,
00074                                      struct timespec *timeout);
00075 
00076 int circ_buff_wait_for_read(circ_buff_t *new_buff, struct timespec *timeout);
00077 
00078 int circ_buff_wait_for_write(circ_buff_t *new_buff, struct timespec *timeout);
00079 
00080 int circ_buff_resize(circ_buff_t *new_buff, long new_size,
00081                                             struct timespec *timeout);
00082 
00083 long circ_buff_read(circ_buff_t *new_buff, void *read_data,
00084                                                 long bytes_to_read,
00085                                         struct timespec *timeout);
00086 
00087 long circ_buff_read_thread(circ_buff_t *new_buff, void *read_data,
00088                            long *thread_read_pnt,
00089                            unsigned long long *thread_byte_id,
00090                                            long read_size,
00091                            struct timespec *timeout);
00092 
00093 long circ_buff_write(circ_buff_t *new_buff, void * write_data,
00094                                 long bytes_to_write,
00095                         struct timespec *timeout);
00096 
00097 
00098 
00099 #endif

Generated on Thu Dec 16 23:07:31 2004 for alsad by doxygen 1.3.6