Imported Upstream version 1.1.11
[platform/upstream/cdrkit.git] / icedax / ringbuff.h
1 /*
2  * This file has been modified for the cdrkit suite.
3  *
4  * The behaviour and appearence of the program code below can differ to a major
5  * extent from the version distributed by the original author(s).
6  *
7  * For details, see Changelog file distributed with the cdrkit package. If you
8  * received this file from another source then ask the distributing person for
9  * a log of modifications.
10  *
11  */
12
13 /* @(#)ringbuff.h       1.5 01/10/20 Copyright 1998,1999,2000 Heiko Eissfeldt */
14 /* This file contains data structures that reside in the shared memory
15  * segment.
16  */
17
18
19 /* the linux semctl prototype is broken as is the definition
20    of union semun in sys/sem.h. */
21
22 #ifdef HAVE_UNION_SEMUN
23 #       define  my_semun        semun
24 #else
25 union my_semun {
26   int val;
27   struct semid_ds *pid;
28   unsigned short *array;
29 };
30 #endif
31
32 /* Ringbuffer structures.
33    Space for the ringbuffer is allocated page aligned
34          and contains the following
35
36         -------------------- start of page
37         header (once for the ring buffer) \\
38         space for page alignment          ||+- HEADER_SIZE
39 RB_BASE -+v                               ||
40         myringbuffer.offset               |/
41         -------------------- start of page/-- pagesize
42         myringbuffer.data (SEGMENT_SIZE)\
43         space for page alignment        |+- ENTRY_SIZE_PAGE_AL
44         myringbuffer.offset             /
45         -------------------- start of page
46         myringbuffer.data
47         space for page alignment
48         ...
49 */      
50 typedef struct {
51   int offset;
52   UINT4 data[CD_FRAMESAMPLES];
53 } myringbuff;
54
55 struct ringbuffheader {
56   myringbuff *p1;
57   myringbuff *p2;
58   volatile unsigned long total_read;
59   volatile unsigned long total_written;
60   volatile int child_waitstate;
61   volatile int parent_waitstate;
62   volatile int input_littleendian;
63   volatile int end_is_reached;
64   volatile unsigned long nSamplesToDo;
65   int offset;
66   UINT4 data[CD_FRAMESAMPLES];
67 };
68
69 extern myringbuff **he_fill_buffer;
70 extern myringbuff **last_buffer;
71 extern volatile unsigned long *total_segments_read;
72 extern volatile unsigned long *total_segments_written;
73 extern volatile int *child_waits;
74 extern volatile int *parent_waits;
75 extern volatile int *in_lendian;
76 extern volatile int *eorecording;
77
78 #define palign(x, a)    (((char *)(x)) + ((a) - 1 - (((unsigned)((x)-1))%(a))))
79 #define multpage(x, a)    ((((x) + (a) - 1) / (a)) * (a))
80
81 #define HEADER_SIZE multpage(offset_of(struct ringbuffheader, data), global.pagesize)
82 #define SEGMENT_SIZE (global.nsectors*CD_FRAMESIZE_RAW)
83 #define ENTRY_SIZE_PAGE_AL multpage(SEGMENT_SIZE + offset_of(myringbuff, data), global.pagesize)
84
85 #define RB_BASE ((myringbuff *)(((unsigned char *)he_fill_buffer) + HEADER_SIZE - offset_of(myringbuff, data)))
86
87 #define INC(a) (myringbuff *)(((char *)RB_BASE) + (((((char *) (a))-((char *)RB_BASE))/ENTRY_SIZE_PAGE_AL + 1) % total_buffers)*ENTRY_SIZE_PAGE_AL)
88
89
90 void set_total_buffers(unsigned int num_buffers, int mysem_id);
91 const myringbuff *get_previous_read_buffer(void);
92 const myringbuff *get_he_fill_buffer(void);
93 myringbuff *get_next_buffer(void);
94 myringbuff *get_oldest_buffer(void);
95 void define_buffer(void);
96 void drop_buffer(void);
97 void drop_all_buffers(void);