Author: thebeing
Date: Tue May  5 09:57:34 2015
New Revision: 38474

URL: http://svn.gna.org/viewcvs/gnustep?rev=38474&view=rev
Log:
Add methods to peek at the top/front item in a FIFO without removing it.

Modified:
    libs/performance/trunk/ChangeLog
    libs/performance/trunk/GSFIFO.h
    libs/performance/trunk/GSFIFO.m

Modified: libs/performance/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/ChangeLog?rev=38474&r1=38473&r2=38474&view=diff
==============================================================================
--- libs/performance/trunk/ChangeLog    (original)
+++ libs/performance/trunk/ChangeLog    Tue May  5 09:57:34 2015
@@ -1,3 +1,8 @@
+2015-05-05 Niels Grewe <[email protected]>
+
+       * GSFIFO.[hm]: Add methods to peek at the top/front object in the
+       FIFO without removing it.
+
 2015-04-28 Niels Grewe <[email protected]>
 
        * GSFIFO.m: Use -autorelease rather than -release when returning

Modified: libs/performance/trunk/GSFIFO.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSFIFO.h?rev=38474&r1=38473&r2=38474&view=diff
==============================================================================
--- libs/performance/trunk/GSFIFO.h     (original)
+++ libs/performance/trunk/GSFIFO.h     Tue May  5 09:57:34 2015
@@ -257,6 +257,21 @@
  */
 - (NSObject*) tryGetObject;
 
+/**
+ * Checks the FIFO and returns a reference to the first available item 
+ * or NULL if the FIFO is empty. <br />Calling this method does
+ * <em>not</em> remove the item from the queue.
+ */
+- (void*) peek;
+
+/**
+ * Checks the FIFO and returns the an autoreleased reference to the first
+ * available object, or nil if the FIFO is empty (or contains a nil object).
+ * <br /> Calling this method does <em>not</em> remove the object from the
+ * queue.
+ */
+- (NSObject*)peekObject;
+
 /** Attempts to retain an object while putting it into the FIFO,
  * returning YES on success or NO if the FIFO is full.<br />
  * Implemented using -put:count:shouldBlock:

Modified: libs/performance/trunk/GSFIFO.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSFIFO.m?rev=38474&r1=38473&r2=38474&view=diff
==============================================================================
--- libs/performance/trunk/GSFIFO.m     (original)
+++ libs/performance/trunk/GSFIFO.m     Tue May  5 09:57:34 2015
@@ -201,6 +201,39 @@
   return index;
 }
 
+- (void*) _cooperatingPeek
+{
+  [condition lock];
+  if ((_head - _tail) == 0)
+    {
+      // We do not need to signal the condition because
+      // nothing about the qeuue did change
+      [condition unlock];
+      return NULL;;
+    }
+  void *ptr = _items[_tail % _capacity];
+  [condition unlock];
+  return ptr;
+}
+
+- (void*) peek
+{
+  if (condition != nil)
+    {
+      return [self _cooperatingPeek];
+    }
+  if (_head - _tail == 0)
+    {
+      return NULL;
+    }
+  return _items[_tail % _capacity];
+}
+
+- (NSObject*) peekObject
+{
+  return [[(id<NSObject>)[self peek] retain] autorelease];
+}
+
 - (unsigned) _cooperatingPut: (void**)buf
                       count: (unsigned)count
                 shouldBlock: (BOOL)block


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to