improve configurability

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/performance/trunk@34057 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-10-25 11:18:36 +00:00
parent 8a5867051c
commit bdd2b7ce2c
4 changed files with 68 additions and 9 deletions

View file

@ -1,3 +1,11 @@
2011-10-25 Richard Frith-Macdonald <rfm@gnu.org>
* GSFIFO.h:
* GSFIFO.m:
Add new method to create a named FIFO and configure it from the
defaults system.
* GNUmakefile: bump version to 0.3.2
2011-08-29 Richard Frith-Macdonald <rfm@gnu.org>
* GSCache.m: Try to fool clang/llvm to avoid useless warning/error.

View file

@ -21,7 +21,7 @@ include $(GNUSTEP_MAKEFILES)/common.make
-include config.make
PACKAGE_NAME = Performance
PACKAGE_VERSION = 0.3.1
PACKAGE_VERSION = 0.3.2
Performance_INTERFACE_VERSION=0.3
SVN_BASE_URL = svn+ssh://svn.gna.org/svn/gnustep/libs
SVN_MODULE_NAME = performance

View file

@ -57,6 +57,9 @@
* cases it may make sense to have multiple consumers and/or producers.
* In these cases, some locking is required and the use of the inline
* functions is not allowed (you must call the -get and -put: methods.<br />
* It is recommended that you create FIFOs using the -initWithName: method
* so that you can easily use the NSUserDefaults system to adjust their
* configurations to tests/tweak performance.
*/
@interface GSFIFO : NSObject
{
@ -119,6 +122,8 @@
/** <init/>
* Initialises the receiver with the specified capacity (buffer size).<br />
* The capacity must lie in the range from one to a million, othewrwise
* the receiver is deallocated and this method returns nil.<br />
* If the granularity value is non-zero, it is treated as the maximum time
* in milliseconds for which a -get or -put: operation will pause between
* successive attempts.<br />
@ -134,7 +139,8 @@
* If this is nil, a default set of bundaries 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.
* printing diagnostics and statistics. If an instance with the same name
* already exists, the receiveris deallocated and an exception is raised.
*/
- (id) initWithCapacity: (uint32_t)c
granularity: (uint16_t)g
@ -145,11 +151,26 @@
name: (NSString*)n;
/** Initialises the receiver as a multi-producer, multi-consumer FIFO with
* no timeout and with default stats gathering enabled.
* no timeout and with default stats gathering enabled.<br />
* However, these values (including the supplied capacity) may be overridden
* as specified in -initWithName:
*/
- (id) initWithCapacity: (uint32_t)c
name: (NSString*)n;
/** Initialises the receiver using the specified name and obtaining other
* details from the NSUserDefaults system using defaults keys where 'NNN'
* is the supplied name.<br />
* The GSFIFOCapacityNNN default specifies the capacity for the FIFO, and
* if missing a capacity of 1000 is assumed.<br />
* The GSFIFOGranularityNNN integer is zero by default.<br />
* The GSFIFOTimeoutNNN integer is zero by default.<br />
* The GSFIFOSingleConsumerNNN boolean is NO by default.<br />
* The GSFIFOSingleProducerNNN boolean is NO by default.<br />
* The GSFIFOBoundariesNNN array is missing by default.<br />
*/
- (id) initWithName: (NSString*)n;
/** 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

View file

@ -27,6 +27,7 @@
#import <Foundation/NSMapTable.h>
#import <Foundation/NSString.h>
#import <Foundation/NSThread.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSValue.h>
#import <Foundation/NSZone.h>
@ -407,7 +408,7 @@ stats(NSTimeInterval ti, uint32_t max, NSTimeInterval *bounds, uint64_t *bands)
boundaries: (NSArray*)a
name: (NSString*)n
{
if (c < 1)
if (c < 1 || c > 1000000)
{
[self release];
return nil;
@ -480,15 +481,44 @@ stats(NSTimeInterval ti, uint32_t max, NSTimeInterval *bounds, uint64_t *bands)
- (id) initWithCapacity: (uint32_t)c
name: (NSString*)n
{
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSString *key;
uint16_t g;
uint16_t t;
BOOL mc;
BOOL mp;
NSArray *b;
key = [NSString stringWithFormat: @"GSFIFOCapacity%@", n];
if ([defs integerForKey: key] > 0)
{
c = [defs integerForKey: key];
}
key = [NSString stringWithFormat: @"GSFIFOGranularity%@", n];
g = [defs integerForKey: key];
key = [NSString stringWithFormat: @"GSFIFOTimeout%@", n];
t = [defs integerForKey: key];
key = [NSString stringWithFormat: @"GSFIFOSingleConsumer%@", n];
mc = (YES == [defs boolForKey: key]) ? NO : YES;
key = [NSString stringWithFormat: @"GSFIFOSingleProducer%@", n];
mp = (YES == [defs boolForKey: key]) ? NO : YES;
key = [NSString stringWithFormat: @"GSFIFOBoundaries%@", n];
b = [defs arrayForKey: key];
return [self initWithCapacity: c
granularity: 0
timeout: 0
multiProducer: YES
multiConsumer: YES
boundaries: nil
granularity: g
timeout: t
multiProducer: mp
multiConsumer: mc
boundaries: b
name: n];
}
- (id) initWithName: (NSString*)n
{
return [self initWithCapacity: 10000 name: n];
}
- (unsigned) put: (void**)buf count: (unsigned)count shouldBlock: (BOOL)block
{
NSTimeInterval sum;