From bdd2b7ce2cc661a661d6e92e6059d6be155868cf Mon Sep 17 00:00:00 2001 From: Richard Frith-MacDonald Date: Tue, 25 Oct 2011 11:18:36 +0000 Subject: [PATCH] improve configurability git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/performance/trunk@34057 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 ++++++++ GNUmakefile | 2 +- GSFIFO.h | 25 +++++++++++++++++++++++-- GSFIFO.m | 42 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 68 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd40f65..9980976 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-10-25 Richard Frith-Macdonald + + * 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 * GSCache.m: Try to fool clang/llvm to avoid useless warning/error. diff --git a/GNUmakefile b/GNUmakefile index cfd5e73..673ddeb 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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 diff --git a/GSFIFO.h b/GSFIFO.h index 749be74..6d06e4f 100644 --- a/GSFIFO.h +++ b/GSFIFO.h @@ -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.
+ * 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 @@ /** * Initialises the receiver with the specified capacity (buffer size).
+ * The capacity must lie in the range from one to a million, othewrwise + * the receiver is deallocated and this method returns nil.
* 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.
@@ -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.
* 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.
+ * 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.
+ * The GSFIFOCapacityNNN default specifies the capacity for the FIFO, and + * if missing a capacity of 1000 is assumed.
+ * The GSFIFOGranularityNNN integer is zero by default.
+ * The GSFIFOTimeoutNNN integer is zero by default.
+ * The GSFIFOSingleConsumerNNN boolean is NO by default.
+ * The GSFIFOSingleProducerNNN boolean is NO by default.
+ * The GSFIFOBoundariesNNN array is missing by default.
+ */ +- (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 diff --git a/GSFIFO.m b/GSFIFO.m index 55d1349..2bf2b68 100644 --- a/GSFIFO.m +++ b/GSFIFO.m @@ -27,6 +27,7 @@ #import #import #import +#import #import #import @@ -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;