docs/random/wtay/poll-timeout: Some pseudo code for how we could implement clock...
authorWim Taymans <wim.taymans@gmail.com>
Tue, 11 Nov 2008 14:50:24 +0000 (14:50 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Tue, 11 Nov 2008 14:50:24 +0000 (14:50 +0000)
Original commit message from CVS:
* docs/random/wtay/poll-timeout:
Some pseudo code for how we could implement clock timeouts with GstPoll.

ChangeLog
docs/random/wtay/poll-timeout [new file with mode: 0644]

index c070ce0..7d2b68f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-11-11  Wim Taymans  <wim.taymans@collabora.co.uk>
+
+       * docs/random/wtay/poll-timeout:
+       Some pseudo code for how we could implement clock timeouts with GstPoll.
+
 2008-11-10  Thomas Vander Stichele  <thomas at apestaart dot org>
 
        * plugins/elements/gstfilesink.c:
diff --git a/docs/random/wtay/poll-timeout b/docs/random/wtay/poll-timeout
new file mode 100644 (file)
index 0000000..30f3828
--- /dev/null
@@ -0,0 +1,51 @@
+create clock id:
+
+  id->state = OK;
+
+
+waiting for id:
+
+   lock
+   /* once unscheduled, the id cannot be used anymore */
+   while (id->state != unscheduled) {
+     id->state = busy;
+     unlock
+
+     ret = gstpoll (timeout);
+
+     lock
+     if (id->state == unscheduled) {
+       /* id became unscheduled, read the fd and broadcast */
+       read (fd)
+       cond_broadcast ()
+     }
+     else {
+       if (ret != 0) {
+         /* some other id got unlocked */ 
+        /* mark ourselves as EARLY, we release the lock and we could be
+         * unscheduled ourselves but we don't want the unscheduling thread
+         * to write on the fd */
+        id->state = EARLY;
+        /* wait until it reads the fd and signals us */
+         cond_wait ()
+       }
+       else {
+         /* we timed out */
+        id->state = OK | EARLY;
+       }
+     }
+   }
+   unlock
+   return id->state;
+
+
+unschedule id:
+
+   lock
+   /* when it leaves the poll, it'll detect the unscheduled. */
+   id->state = unscheduled;
+   /* if it's busy waiting in poll, write to the fd */
+   if (id->state == busy) {
+     write (fd)
+   }
+   unlock