~ubuntu-branches/ubuntu/lucid/mpg123/lucid

« back to all changes in this revision

Viewing changes to src/xfermem.h

Tags: upstream-0.60
ImportĀ upstreamĀ versionĀ 0.60

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        xfermem: unidirectional fast pipe
 
3
 
 
4
        copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
 
5
        see COPYING and AUTHORS files in distribution or http://mpg123.de
 
6
        initially written by Oliver Fromme
 
7
        old timestamp: Sat Mar 29 04:41:34 MET 1997
 
8
 
 
9
        This is a stand-alone module which implements a unidirectional,
 
10
        fast pipe using mmap().  Its primary use is to transfer large
 
11
        amounts of data from a parent process to its child process,
 
12
        with a buffer in between which decouples blocking conditions
 
13
        on both sides.  Control information is transferred between the
 
14
        processes through a socketpair.  See xftest.c for an example on
 
15
        how to use this module.
 
16
 
 
17
        note: xftest not there anymore
 
18
*/
 
19
 
 
20
#ifndef _XFERMEM_H_
 
21
#define _XFERMEM_H_
 
22
 
 
23
#ifndef TRUE
 
24
#define FALSE 0
 
25
#define TRUE  1
 
26
#endif
 
27
 
 
28
typedef struct {
 
29
        int freeindex;  /* [W] next free index */
 
30
        int readindex;  /* [R] next index to read */
 
31
        int fd[2];
 
32
        int wakeme[2];
 
33
        byte *data;
 
34
        byte *metadata;
 
35
        int size;
 
36
        int metasize;
 
37
        int buf[3];
 
38
} txfermem;
 
39
/*
 
40
 *   [W] -- May be written to by the writing process only!
 
41
 *   [R] -- May be written to by the reading process only!
 
42
 *   All other entries are initialized once.
 
43
 */
 
44
 
 
45
void xfermem_init (txfermem **xf, int bufsize, int msize,int skipbuf);
 
46
void xfermem_init_writer (txfermem *xf);
 
47
void xfermem_init_reader (txfermem *xf);
 
48
 
 
49
int  xfermem_write (txfermem *xf, byte *data, int count);
 
50
int  xfermem_read  (txfermem *xf, byte *data, int count);
 
51
 
 
52
int xfermem_get_freespace (txfermem *xf);
 
53
int xfermem_get_usedspace (txfermem *xf);
 
54
#define XF_CMD_WAKEUP_INFO  0x04
 
55
#define XF_CMD_WAKEUP    0x02
 
56
#define XF_CMD_TERMINATE 0x03
 
57
#define XF_WRITER 0
 
58
#define XF_READER 1
 
59
int xfermem_getcmd (int fd, int block);
 
60
int xfermem_putcmd (int fd, byte cmd);
 
61
int xfermem_block (int fd, txfermem *xf);
 
62
 
 
63
void xfermem_done (txfermem *xf);
 
64
#define xfermem_done_writer xfermem_init_reader
 
65
#define xfermem_done_reader xfermem_init_writer
 
66
 
 
67
 
 
68
#endif