1 /* Copyright (C) 2006  Britton Leo Kerin, see copyright. */
2 
3 /* This header contains material concerned mainly with the threads and
4    shared data.  It is included in other files besides those
5    containing the thread functions.  */
6 
7 #include <pthread.h>
8 
9 /* Structure type for move_au thread function arguments. */
10 typedef struct {
11   /* These first three variables are things that are likely to be
12      needed by most any ring buffer designed to be accessed by
13      threads. */
14   int startup_order;		/* Indicates the order in which the
15                                    thread will first access the ring
16                                    buffer relative to the other
17                                    threads. 1 ==> 1st, 2 ==> 2nd,
18                                    etc. */
19   int ringbuf_segs;		/* Number of ring buffer segments. */
20   int seg_sz;		        /* Size of a ring buffer segment. */
21   /* These variables deal with the threads particular job (moving
22      audio data). */
23   int fd;			/* Audio device file descriptor.  */
24   int recorder;                 /* == 1 ==> record, == 2  ==> play. */
25   double byte_cnt;		/* Bytes to record or play. */
26   int sample_size;		/* size of a complete sample, in bytes */
27   boolean limit_set;		/* Has the user specified -t or -T? */
28 } move_au_th_arg_stt;
29 
30 /* Structure type for move_fd thread function arguments. */
31 typedef struct {
32   /* These first three variables are things that are likely to be
33      needed by most any ring buffer designed to be accessed by
34      threads. */
35   int startup_order;		/* Indicates the order in which the
36                                    thread will first access the ring
37                                    buffer relative to the other
38                                    threads. 1 ==> 1st, 2 ==> 2nd,
39                                    etc. */
40   int ringbuf_segs;		/* Number of ring buffer segments. */
41   int seg_sz;		        /* Size of a ring buffer segment. */
42   /* These variables deal with the threads particular job (moving
43      audio data). */
44   int fd;			/* Disk file file descriptot.  */
45   int recorder;                 /* == 1 ==> record, == 2  ==> play. */
46   double byte_cnt;		/* Bytes to record or play. */
47   boolean using_stdio;		/* Are we using stdio? */
48 } move_fd_th_arg_stt;
49 
50 /* See globals.c for descriptions of the roles of these globals. */
51 
52 /* Note that sig_th isn't used yet. */
53 extern pthread_t sig_th, move_au_th, move_fd_th;
54 extern pthread_attr_t sig_th_attr, move_au_attr, move_fd_attr;
55 extern struct sched_param move_au_param, move_fd_param;
56 
57 extern const int th_error;
58 extern const int th_success;
59 
60 extern unsigned char *ringbufp;
61 extern long *bytes_in_seg;
62 extern int *is_last_seg;
63 
64 extern int root_permissions_dropped;
65 extern pthread_cond_t root_permissions_dropped_cv;
66 extern pthread_mutex_t root_permissions_dropped_mutex;
67 
68 extern int startup_next;
69 extern pthread_cond_t startup_next_cv;
70 extern pthread_mutexattr_t startup_next_mutex_attr;
71 extern pthread_mutex_t startup_next_mutex;
72 
73 extern int wrap_ready;
74 extern pthread_cond_t wrap_ready_cv;
75 extern pthread_mutex_t wrap_ready_mutex;
76 
77 extern pthread_mutexattr_t *seg_mutex_attr;
78 extern pthread_mutex_t *seg_mutex;
79 
80 extern int shutdown_signal_seen;
81 extern pthread_mutex_t shutdown_signal_seen_mutex;
82 
83 extern const int MAGIC_EMPTY_SEG_SEQ_LENGTH;
84 
85 /* Prototypes for the thread functions themselves. */
86 void *move_au(move_au_th_arg_stt *th_arg);
87 void *move_fd(move_fd_th_arg_stt *th_arg);
88 
89