5 * Copyright (C) 2002-2005 Monty and Xiph.Org
7 * Postfish is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * Postfish is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Postfish; see the file COPYING. If not, write to the
19 * Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 static pthread_mutex_t feedback_mutex
=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
;
29 feedback_generic
*feedback_new(feedback_generic_pool
*pool
,
30 feedback_generic
*(*constructor
)(void)){
31 feedback_generic
*ret
;
33 pthread_mutex_lock(&feedback_mutex
);
34 if(pool
->feedback_pool
){
35 ret
=pool
->feedback_pool
;
36 pool
->feedback_pool
=pool
->feedback_pool
->next
;
37 pthread_mutex_unlock(&feedback_mutex
);
40 pthread_mutex_unlock(&feedback_mutex
);
46 void feedback_push(feedback_generic_pool
*pool
,
50 pthread_mutex_lock(&feedback_mutex
);
51 if(!pool
->feedback_list_tail
){
52 pool
->feedback_list_tail
=f
;
53 pool
->feedback_list_head
=f
;
55 pool
->feedback_list_head
->next
=f
;
56 pool
->feedback_list_head
=f
;
58 pthread_mutex_unlock(&feedback_mutex
);
61 feedback_generic
*feedback_pull(feedback_generic_pool
*pool
){
64 pthread_mutex_lock(&feedback_mutex
);
65 if(pool
->feedback_list_tail
){
67 f
=pool
->feedback_list_tail
;
68 pool
->feedback_list_tail
=pool
->feedback_list_tail
->next
;
69 if(!pool
->feedback_list_tail
)pool
->feedback_list_head
=0;
72 pthread_mutex_unlock(&feedback_mutex
);
75 pthread_mutex_unlock(&feedback_mutex
);
79 void feedback_old(feedback_generic_pool
*pool
,
82 pthread_mutex_lock(&feedback_mutex
);
83 f
->next
=pool
->feedback_pool
;
84 pool
->feedback_pool
=f
;
85 pthread_mutex_unlock(&feedback_mutex
);
88 /* are there multiple feedback outputs waiting or just one (a metric
89 of 'are we behind?') */
90 int feedback_deep(feedback_generic_pool
*pool
){
92 pthread_mutex_lock(&feedback_mutex
);
93 if(pool
->feedback_list_tail
)
94 if(pool
->feedback_list_tail
->next
){
95 pthread_mutex_unlock(&feedback_mutex
);
98 pthread_mutex_unlock(&feedback_mutex
);