File: ringbuff.h

package info (click to toggle)
cdrkit 9:1.1.11-3
  • links: PTS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, stretch
  • size: 7,464 kB
  • sloc: ansic: 107,182; perl: 968; sh: 481; makefile: 229; sed: 4
file content (97 lines) | stat: -rw-r--r-- 3,023 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
 * This file has been modified for the cdrkit suite.
 *
 * The behaviour and appearence of the program code below can differ to a major
 * extent from the version distributed by the original author(s).
 *
 * For details, see Changelog file distributed with the cdrkit package. If you
 * received this file from another source then ask the distributing person for
 * a log of modifications.
 *
 */

/* @(#)ringbuff.h	1.5 01/10/20 Copyright 1998,1999,2000 Heiko Eissfeldt */
/* This file contains data structures that reside in the shared memory
 * segment.
 */


/* the linux semctl prototype is broken as is the definition
   of union semun in sys/sem.h. */

#ifdef HAVE_UNION_SEMUN
#	define	my_semun	semun
#else
union my_semun {
  int val;
  struct semid_ds *pid;
  unsigned short *array;
};
#endif

/* Ringbuffer structures.
   Space for the ringbuffer is allocated page aligned
	 and contains the following

	-------------------- start of page
	header (once for the ring buffer) \\
	space for page alignment	  ||+- HEADER_SIZE
RB_BASE -+v				  ||
	myringbuffer.offset		  |/
	-------------------- start of page/-- pagesize
	myringbuffer.data (SEGMENT_SIZE)\
	space for page alignment	|+- ENTRY_SIZE_PAGE_AL
	myringbuffer.offset		/
	-------------------- start of page
	myringbuffer.data
	space for page alignment
	...
*/	
typedef struct {
  int offset;
  UINT4 data[CD_FRAMESAMPLES];
} myringbuff;

struct ringbuffheader {
  myringbuff *p1;
  myringbuff *p2;
  volatile unsigned long total_read;
  volatile unsigned long total_written;
  volatile int child_waitstate;
  volatile int parent_waitstate;
  volatile int input_littleendian;
  volatile int end_is_reached;
  volatile unsigned long nSamplesToDo;
  int offset;
  UINT4 data[CD_FRAMESAMPLES];
};

extern myringbuff **he_fill_buffer;
extern myringbuff **last_buffer;
extern volatile unsigned long *total_segments_read;
extern volatile unsigned long *total_segments_written;
extern volatile int *child_waits;
extern volatile int *parent_waits;
extern volatile int *in_lendian;
extern volatile int *eorecording;

#define palign(x, a)    (((char *)(x)) + ((a) - 1 - (((unsigned)((x)-1))%(a))))
#define multpage(x, a)    ((((x) + (a) - 1) / (a)) * (a))

#define HEADER_SIZE multpage(offset_of(struct ringbuffheader, data), global.pagesize)
#define SEGMENT_SIZE (global.nsectors*CD_FRAMESIZE_RAW)
#define ENTRY_SIZE_PAGE_AL multpage(SEGMENT_SIZE + offset_of(myringbuff, data), global.pagesize)

#define RB_BASE ((myringbuff *)(((unsigned char *)he_fill_buffer) + HEADER_SIZE - offset_of(myringbuff, data)))

#define INC(a) (myringbuff *)(((char *)RB_BASE) + (((((char *) (a))-((char *)RB_BASE))/ENTRY_SIZE_PAGE_AL + 1) % total_buffers)*ENTRY_SIZE_PAGE_AL)


void set_total_buffers(unsigned int num_buffers, int mysem_id);
const myringbuff *get_previous_read_buffer(void);
const myringbuff *get_he_fill_buffer(void);
myringbuff *get_next_buffer(void);
myringbuff *get_oldest_buffer(void);
void define_buffer(void);
void drop_buffer(void);
void drop_all_buffers(void);