From dca415e05225bcf11aaba0024217df736a1acc7c Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 13 Dec 2010 14:35:41 +0100 Subject: Bugfix: Einträge korrekt anhängen, vorher lock() aufrufen (sonst race condition) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aufgabe4/queue.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'aufgabe4/queue.c') diff --git a/aufgabe4/queue.c b/aufgabe4/queue.c index 373bcd3..e376331 100644 --- a/aufgabe4/queue.c +++ b/aufgabe4/queue.c @@ -99,12 +99,16 @@ struct msg *queue_write(uint8_t dir, uint8_t data) { msg.dir = dir; msg.data = data; - uint8_t next; - if (shmheader->cur == 255) - next = 0; - else next = shmheader->cur + 1; - lock(); + uint8_t next = shmheader->cur; + struct msg *nextmsg = shmdata + (shmheader->cur * sizeof(struct msg)); + while (nextmsg->dir != D_INVALID) { + if (next == 255) + next = 0; + else next++; + nextmsg = shmdata + (next * sizeof(struct msg)); + } + struct msg *curmsg = shmdata + (shmheader->cur * sizeof(struct msg)); struct msg *nextmsg = shmdata + (next * sizeof(struct msg)); memcpy(nextmsg, &msg, sizeof(struct msg)); -- cgit v1.2.3-70-g09d2