diff options
author | Wim Taymans <wim.taymans@gmail.com> | 2008-11-13 18:05:40 +0000 |
---|---|---|
committer | Wim Taymans <wim.taymans@gmail.com> | 2008-11-13 18:05:40 +0000 |
commit | 2488c97ebd49147c23b9de6751ada7d101f55daa (patch) | |
tree | 3f788a06902252d7f57f8ea975b59e26eafd44d4 /docs/random/wtay | |
parent | bb0cd4e7f1473d4f894409075f9305c6cb430040 (diff) |
docs/random/wtay/poll-timeout: Small tweaks.
Original commit message from CVS:
* docs/random/wtay/poll-timeout:
Small tweaks.
Diffstat (limited to 'docs/random/wtay')
-rw-r--r-- | docs/random/wtay/poll-timeout | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/docs/random/wtay/poll-timeout b/docs/random/wtay/poll-timeout index ef6e91bf07..e625bcbdde 100644 --- a/docs/random/wtay/poll-timeout +++ b/docs/random/wtay/poll-timeout @@ -76,12 +76,14 @@ waiting for id: /* we got unscheduled, see if it was because we timed out or some other * id got unscheduled */ if (ret != 0) { - lock - /* some other id got unlocked */ - /* wait until it reads the fd and signals us */ - while (waiters) - cond_wait () - unlock + if (g_atomic_int_get (&waiters) > 0) { + lock + /* some other id got unlocked */ + /* wait until it reads the fd and signals us */ + while (waiters) + cond_wait () + unlock + } } else { /* we timed out update the status. */ @@ -89,16 +91,18 @@ waiting for id: break; } } - else if (g_atomic_int_compare_and_exchange (&id->state, UNSCHEDULED, OK) { + else if (g_atomic_int_get (&id->state) == UNSCHEDULED) { /* id became unscheduled, read the fd and broadcast */ lock read (fd) - waiters-- + g_atomic_int_dec (&waiters); cond_broadcast () unlock - id->state = UNSCHEDULED; break; } + else { + g_assert_not_reached (); + } } return id->state; @@ -109,7 +113,7 @@ unschedule id: if (g_atomic_int_compare_and_exchange (&id->state, BUSY, UNSCHEDULED) { /* if it's busy waiting in poll, write to the fd */ lock - waiters++ + g_atomic_int_inc (&waiters) write (fd) unlock } |