mirror of
https://github.com/gnustep/libs-performance.git
synced 2025-02-16 08:31:25 +00:00
add option for writing a whole block in one go
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/performance/trunk@39039 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
33be15ea6c
commit
16b09c5202
4 changed files with 100 additions and 8 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2015-10-07 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* GSFIFO.m: Add method for writing a whole block of data to a FIFO
|
||||||
|
in one go.
|
||||||
|
|
||||||
2015-07-29 Richard Frith-Macdonald <rfm@gnu.org>
|
2015-07-29 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* GSLinkedList.h:
|
* GSLinkedList.h:
|
||||||
|
|
20
GSFIFO.h
20
GSFIFO.h
|
@ -184,7 +184,7 @@
|
||||||
* time intervals found boundaries of bands into which to categorise wait
|
* time intervals found boundaries of bands into which to categorise wait
|
||||||
* time stats. Any wait whose duration is less than the interval specified
|
* 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.
|
* 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 />
|
* array then no time based stats are recorded.<br />
|
||||||
* The name string is a unique identifier for the receiver and is used when
|
* 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
|
* printing diagnostics and statistics. If an instance with the same name
|
||||||
|
@ -221,6 +221,16 @@
|
||||||
*/
|
*/
|
||||||
- (id) initWithName: (NSString*)n;
|
- (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.
|
/** Writes up to count items from buf into the FIFO.
|
||||||
* If block is YES, this blocks if necessary until at least one item
|
* 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
|
* can be written, and raises an exception if the FIFO is configured
|
||||||
|
@ -297,14 +307,14 @@
|
||||||
*/
|
*/
|
||||||
- (NSObject*) peekObject;
|
- (NSObject*) peekObject;
|
||||||
|
|
||||||
/** Attempts to retain an object while putting it into the FIFO,
|
/** Attempts to put an object (or nil) into the FIFO, returning YES
|
||||||
* returning YES on success or NO if the FIFO is full.<br />
|
* on success or NO if the FIFO is full.<br />
|
||||||
* Implemented using -put:count:shouldBlock:
|
* Implemented using -put:count:shouldBlock:
|
||||||
*/
|
*/
|
||||||
- (BOOL) tryPut: (void*)item;
|
- (BOOL) tryPut: (void*)item;
|
||||||
|
|
||||||
/** Attempts to put an object (or nil) into the FIFO, returning YES
|
/** Attempts to retain an object while putting it into the FIFO,
|
||||||
* on success or NO if the FIFO is full.<br />
|
* returning YES on success or NO if the FIFO is full.<br />
|
||||||
* Implemented using -put:count:shouldBlock:
|
* Implemented using -put:count:shouldBlock:
|
||||||
*/
|
*/
|
||||||
- (BOOL) tryPutObject: (NSObject*)item;
|
- (BOOL) tryPutObject: (NSObject*)item;
|
||||||
|
|
77
GSFIFO.m
77
GSFIFO.m
|
@ -361,6 +361,83 @@ stats(NSTimeInterval ti, uint32_t max, NSTimeInterval *bounds, uint64_t *bands)
|
||||||
return index;
|
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
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[classLock lock];
|
[classLock lock];
|
||||||
|
|
|
@ -279,7 +279,7 @@ best(NSMutableArray *a)
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
[self release];
|
[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;
|
return nil;
|
||||||
#endif
|
#endif
|
||||||
return self;
|
return self;
|
||||||
|
|
Loading…
Reference in a new issue