diff options
| author | Michael Stapelberg <michael@stapelberg.de> | 2010-12-13 14:35:41 +0100 |
|---|---|---|
| committer | Michael Stapelberg <michael@stapelberg.de> | 2010-12-13 14:35:41 +0100 |
| commit | dca415e05225bcf11aaba0024217df736a1acc7c (patch) | |
| tree | abf651e325ffd38755495da722331bd334af548a /aufgabe4 | |
| parent | 66d0782972410b467bc347c35935e01122f9167b (diff) | |
| download | prozesskommunikation-dca415e05225bcf11aaba0024217df736a1acc7c.tar.gz prozesskommunikation-dca415e05225bcf11aaba0024217df736a1acc7c.tar.bz2 | |
Bugfix: Einträge korrekt anhängen, vorher lock() aufrufen (sonst race condition)
Diffstat (limited to 'aufgabe4')
| -rw-r--r-- | aufgabe4/queue.c | 14 |
1 files changed, 9 insertions, 5 deletions
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)); |
