-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfeedback.c
108 lines (93 loc) · 2.9 KB
/
feedback.c
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
98
99
100
101
102
103
104
105
106
107
108
/*
*
* postfish
*
* Copyright (C) 2002-2005 Monty and Xiph.Org
*
* Postfish is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* Postfish is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Postfish; see the file COPYING. If not, write to the
* Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
*/
#include "postfish.h"
#include "feedback.h"
static pthread_mutex_t feedback_mutex;
static pthread_mutexattr_t feedback_mutex_attr;
void feedback_init() {
pthread_mutexattr_init(&feedback_mutex_attr);
pthread_mutexattr_settype(&feedback_mutex_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&feedback_mutex, &feedback_mutex_attr);
}
feedback_generic *feedback_new(feedback_generic_pool *pool,
feedback_generic *(*constructor)(void)){
feedback_generic *ret;
pthread_mutex_lock(&feedback_mutex);
if(pool->feedback_pool){
ret=pool->feedback_pool;
pool->feedback_pool=pool->feedback_pool->next;
pthread_mutex_unlock(&feedback_mutex);
return ret;
}
pthread_mutex_unlock(&feedback_mutex);
ret=constructor();
return ret;
}
void feedback_push(feedback_generic_pool *pool,
feedback_generic *f){
f->next=NULL;
pthread_mutex_lock(&feedback_mutex);
if(!pool->feedback_list_tail){
pool->feedback_list_tail=f;
pool->feedback_list_head=f;
}else{
pool->feedback_list_head->next=f;
pool->feedback_list_head=f;
}
pthread_mutex_unlock(&feedback_mutex);
}
feedback_generic *feedback_pull(feedback_generic_pool *pool){
feedback_generic *f;
pthread_mutex_lock(&feedback_mutex);
if(pool->feedback_list_tail){
f=pool->feedback_list_tail;
pool->feedback_list_tail=pool->feedback_list_tail->next;
if(!pool->feedback_list_tail)pool->feedback_list_head=0;
}else{
pthread_mutex_unlock(&feedback_mutex);
return 0;
}
pthread_mutex_unlock(&feedback_mutex);
return(f);
}
void feedback_old(feedback_generic_pool *pool,
feedback_generic *f){
pthread_mutex_lock(&feedback_mutex);
f->next=pool->feedback_pool;
pool->feedback_pool=f;
pthread_mutex_unlock(&feedback_mutex);
}
/* are there multiple feedback outputs waiting or just one (a metric
of 'are we behind?') */
int feedback_deep(feedback_generic_pool *pool){
if(pool){
pthread_mutex_lock(&feedback_mutex);
if(pool->feedback_list_tail)
if(pool->feedback_list_tail->next){
pthread_mutex_unlock(&feedback_mutex);
return 1;
}
pthread_mutex_unlock(&feedback_mutex);
}
return 0;
}