Author: rfm
Date: Wed Oct  7 15:54:54 2015
New Revision: 39039

URL: http://svn.gna.org/viewcvs/gnustep?rev=39039&view=rev
Log:
add option for writing a whole block in one go

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

Modified: libs/performance/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/ChangeLog?rev=39039&r1=39038&r2=39039&view=diff
==============================================================================
--- libs/performance/trunk/ChangeLog    (original)
+++ libs/performance/trunk/ChangeLog    Wed Oct  7 15:54:54 2015
@@ -1,3 +1,8 @@
+2015-10-07 Richard Frith-Macdonald  <[email protected]>
+
+       * GSFIFO.m: Add method for writing a whole block of data to a FIFO
+       in one go.
+
 2015-07-29 Richard Frith-Macdonald  <[email protected]>
 
        * GSLinkedList.h:

Modified: libs/performance/trunk/GSFIFO.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSFIFO.h?rev=39039&r1=39038&r2=39039&view=diff
==============================================================================
--- libs/performance/trunk/GSFIFO.h     (original)
+++ libs/performance/trunk/GSFIFO.h     Wed Oct  7 15:54:54 2015
@@ -184,7 +184,7 @@
  * time intervals found boundaries of bands into which to categorise wait
  * time stats.  Any wait whose duration is less than the interval specified
  * in the Nth element is counted in the stat's for the Nth band.
- * If this is nil, a default set of bundaries is used.  If it is an empty
+ * If this is nil, a default set of boundaries is used.  If it is an empty
  * array then no time based stats are recorded.<br />
  * The name string is a unique identifier for the receiver and is used when
  * printing diagnostics and statistics.  If an instance with the same name
@@ -221,13 +221,23 @@
  */
 - (id) initWithName: (NSString*)n;
 
+/** Writes exactly count items from buf into the FIFO, blocking if
+ * necessary until there is space for the entire write.<br />
+ * Raises an exception if the FIFO is configured with a timeout and it is
+ * exceeded, or if the count is greater than the FIFO size, or if the
+ * FIFO was not configured for multi producer or multi consumer use.<br />
+ * If rtn is YES, the method treats the buffer as containing objects
+ * which are retained as they are added.
+ */
+- (void) putAll: (void**)buf count: (unsigned)count shouldRetain: (BOOL)rtn;
+
 /** Writes up to count items from buf into the FIFO.
  * If block is YES, this blocks if necessary until at least one item
  * can be written, and raises an exception if the FIFO is configured
  * with a timeout and it is exceeded.<br />
  * Returns the number of items actually written.
  */
-- (unsigned) put: (void**)buf  count: (unsigned)count  shouldBlock: 
(BOOL)block;
+- (unsigned) put: (void**)buf count: (unsigned)count shouldBlock: (BOOL)block;
 
 /** Writes up to count objects from buf into the FIFO, retaining each.<br />
  * If block is YES, this blocks if necessary until at least one object
@@ -295,16 +305,16 @@
  * <br /> Calling this method does <em>not</em> remove the object from the
  * queue.
  */
-- (NSObject*)peekObject;
+- (NSObject*) peekObject;
+
+/** Attempts to put an object (or nil) into the FIFO, returning YES
+ * on success or NO if the FIFO is full.<br />
+ * Implemented using -put:count:shouldBlock:
+ */
+- (BOOL) tryPut: (void*)item;
 
 /** 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:
- */
-- (BOOL) tryPut: (void*)item;
-
-/** Attempts to put an object (or nil) into the FIFO, returning YES
- * on success or NO if the FIFO is full.<br />
  * Implemented using -put:count:shouldBlock:
  */
 - (BOOL) tryPutObject: (NSObject*)item;

Modified: libs/performance/trunk/GSFIFO.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSFIFO.m?rev=39039&r1=39038&r2=39039&view=diff
==============================================================================
--- libs/performance/trunk/GSFIFO.m     (original)
+++ libs/performance/trunk/GSFIFO.m     Wed Oct  7 15:54:54 2015
@@ -361,6 +361,83 @@
   return index;
 }
 
+- (void) putAll: (void**)buf count: (unsigned)count shouldRetain: (BOOL)rtn
+{
+  NSTimeInterval       ti;
+  unsigned             index;
+  BOOL                 wasEmpty;
+
+  NSAssert(nil != condition, NSGenericException);
+  NSAssert(count <= _capacity, NSInvalidArgumentException);
+
+  [condition lock];
+  if (_head - _tail < count)
+    {
+      if (_head - _tail == _capacity)
+        {
+          _putTryFailure++;
+          fullCount++;
+        }
+
+      START
+      if (0 == timeout)
+       {
+         while (_head - _tail < count)
+           {
+             [condition wait];
+           }
+       }
+      else
+       {
+         NSDate        *d;
+
+         d = [[NSDateClass alloc]
+           initWithTimeIntervalSinceNow: timeout / 1000.0f];
+         while (_head - _tail < count)
+           {
+             if (NO == [condition waitUntilDate: d])
+               {
+                 [d release];
+                 ENDPUT
+                 [condition broadcast];
+                 [condition unlock];
+                 [NSException raise: NSGenericException
+                             format: @"Timeout waiting for space in FIFO"];
+               }
+           }
+         [d release];
+       }
+      ENDPUT
+    }
+  else
+    {
+      _putTrySuccess++;
+    }
+
+  if (_head - _tail == 0)
+    {
+      wasEmpty = YES;
+    }
+  else
+    {
+      wasEmpty = NO;
+    }
+  for (index = 0; index < count; index++)
+    {
+      _items[_head % _capacity] = buf[index];
+      _head++;
+      if (YES == rtn)
+        {
+          RETAIN((NSObject*)buf[index]);
+        }
+    }
+  if (YES == wasEmpty)
+    {
+      [condition broadcast];
+    }
+  [condition unlock];
+}
+
 - (void) dealloc
 {
   [classLock lock];

Modified: libs/performance/trunk/GSIOThreadPool.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSIOThreadPool.m?rev=39039&r1=39038&r2=39039&view=diff
==============================================================================
--- libs/performance/trunk/GSIOThreadPool.m     (original)
+++ libs/performance/trunk/GSIOThreadPool.m     Wed Oct  7 15:54:54 2015
@@ -279,7 +279,7 @@
     }
 #else
   [self release];
-  NSLog(@"WARNING, your OSX system is too old to use GSIOthreadPool");
+  NSLog(@"WARNING, your OSX system is too old to use GSIOThreadPool");
   return nil;
 #endif
   return self;


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

Reply via email to