[Asterisk-Dev] small patch for better readability in chan_zap.c
Florian Zumbiehl
florz at gmx.de
Sat Oct 23 06:50:35 MST 2004
Hi,
while reading through the source, it seemed to me that writing this
piece of code differently might be much more straightforward.
This is a diff against 1.0.1, however it shouldn't be difficult
to apply the changes to the current cvs version.
In order to keep the diff better readable, I didn't swap the two
functions, which will be necessary in order to call zap_queue_frame()
from wakeup_sub().
Cya, Florian
-------------- next part --------------
--- chan_zap.c.orig Sat Oct 23 15:13:39 2004
+++ chan_zap.c Sat Oct 23 15:36:16 2004
@@ -681,37 +681,19 @@
static void wakeup_sub(struct zt_pvt *p, int a)
{
struct ast_frame null = { AST_FRAME_NULL, };
- for (;;) {
- if (p->subs[a].owner) {
- if (ast_mutex_trylock(&p->subs[a].owner->lock)) {
- ast_mutex_unlock(&p->lock);
- usleep(1);
- ast_mutex_lock(&p->lock);
- } else {
- ast_queue_frame(p->subs[a].owner, &null);
- ast_mutex_unlock(&p->subs[a].owner->lock);
- break;
- }
- } else
- break;
- }
+ zap_queue_frame((p->subs)+a,&null);
}
static void zap_queue_frame(struct zt_pvt *p, struct ast_frame *f)
{
- for (;;) {
- if (p->owner) {
- if (ast_mutex_trylock(&p->owner->lock)) {
- ast_mutex_unlock(&p->lock);
- usleep(1);
- ast_mutex_lock(&p->lock);
- } else {
- ast_queue_frame(p->owner, f);
- ast_mutex_unlock(&p->owner->lock);
- break;
- }
- } else
- break;
+ if (p->owner) {
+ while(ast_mutex_trylock(&p->owner->lock))
+ ast_mutex_unlock(&p->lock);
+ usleep(1);
+ ast_mutex_lock(&p->lock);
+ }
+ ast_queue_frame(p->owner, f);
+ ast_mutex_unlock(&p->owner->lock);
}
}
More information about the asterisk-dev
mailing list