question about the espeakup code
Tyler Littlefield
tyler at tysdomain.com
Thu Oct 21 23:27:12 EDT 2010
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello,
I have a quick problem.
Perhaps I am missing something, but:
a queue is a fifo: so: All elements added to it are added to the back,
and the first element is the one that is removed.
Now, looking at this code:
static void queue_add(struct queue_entry_t *entry)
{
pthread_mutex_lock(&queue_guard);
assert(entry);
entry->next = NULL; //this is good
if (!last)
last = entry;
//wouldn't last be entry regardless of whether it was NULL?
if (!first) {
first = entry;
//also good.
} else {
first->next = entry;
//shouldn't that be last->next? and probably not in this else clause.
Also: last should equal entry.
first = first->next;
//you have affectively just popped off the top queue and tossed it into
mem-leak space
}
pthread_mutex_unlock(&queue_guard);
pthread_cond_signal(&runner_awake);
}
Iam probably missing something, or there was another intent, so in that
case feel free to yell or whatever works. But in the case that I'm not,
I wanted to point that out.
Here is the code revised, for what it's worth, in case this is a bug:
static void queue_add(struct queue_entry_t *entry)
{
pthread_mutex_lock(&queue_guard);
assert(entry);
entry->next = NULL;
if (!first)
first = entry;
if (!last) {
last->next = entry;
last = entry;
//moves the next pointer of the last node to point to the new entry,
then sets the new entry as the last node.
} else {
//last is null, just set it to point to entry
last = entry;
}
pthread_mutex_unlock(&queue_guard);
pthread_cond_signal(&runner_awake);
}
Again, my appologies if this is wrong.
- --
Thanks,
Tyler Littlefield
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iQEcBAEBAgAGBQJMwQSQAAoJELDPyrppriJPT9kIAKfifpgdhoC7yPIXlQcNjk68
c8RPGUR4keIFQtVSbz+3F1x/DKkJ4oqVEdoacVQgzJdHai4pNwQy8P+lI6Oru7je
16hNvfdzYB/JKTbxbeeL2YSufEjxy5XzLGIv6PxevzbFJaFl90hdOOdmO1gh9Shf
KsibQP1Z+dHGjG8K6Vr22r8oTn+ciJEZ7Y97JKiYRMVqyJAwkuZRu2KKAesxFzo6
xFTl7hSmdxXCSnJwpPXcStVjwTN7T4f90rPhX14uKMoVuWfJrlppZek0HuQNDGIn
nVxK8uYZWaBKniGS4Y3aT7k/7bnuU2U0mBJDAf8sBX47xssGROx0bBVBGkBIEoY=
=es8k
-----END PGP SIGNATURE-----
More information about the Speakup
mailing list