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
00027
00028
00029
00030
00031
00032
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