only initialise lock on systems where symbol support is available.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@24487 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2007-02-07 08:46:07 +00:00
parent 6abab0a73f
commit f9c1ccddf1
3 changed files with 32 additions and 36 deletions

View file

@ -1,3 +1,8 @@
2007-02-07 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSException.m: Only initialise modLock where stack module
symbol handling is supported (fix bug #18938)
2007-02-06 Richard Frith-Macdonald <rfm@gnu.org> 2007-02-06 Richard Frith-Macdonald <rfm@gnu.org>
* Documentation/manual/manual.texi: fix format errors * Documentation/manual/manual.texi: fix format errors

View file

@ -416,16 +416,16 @@ static void find_address (bfd *abfd, asection *section,
@end @end
static id GSLoadModule(NSString *fileName); static NSRecursiveLock *modLock = nil;
static NSMutableDictionary *stackModules = nil;
/* // initialize stack trace info
* This method automatically load the current process + GNUstep base & gui. static id
* Only call this when protected by modLock!! GSLoadModule(NSString *fileName)
*/
static NSMutableDictionary *
GSGetStackModules()
{ {
static NSMutableDictionary *stackModules = nil; GSBinaryFileInfo *module = nil;
[modLock lock];
if (stackModules == nil) if (stackModules == nil)
{ {
@ -453,25 +453,10 @@ GSGetStackModules()
} }
} }
} }
return stackModules;
}
static NSRecursiveLock *modLock = nil;
// initialize stack trace info
static id
GSLoadModule(NSString *fileName)
{
GSBinaryFileInfo *module = nil;
if ([fileName length] > 0) if ([fileName length] > 0)
{ {
NSMutableDictionary *modules; module = [stackModules objectForKey: fileName];
[modLock lock];
modules = GSGetStackModules();
module = [modules objectForKey: fileName];
[modLock unlock];
if (module == nil); if (module == nil);
{ {
module = [GSBinaryFileInfo infoWithBinaryFile: fileName]; module = [GSBinaryFileInfo infoWithBinaryFile: fileName];
@ -479,18 +464,18 @@ GSLoadModule(NSString *fileName)
{ {
module = (id)[NSNull null]; module = (id)[NSNull null];
} }
[modLock lock]; if ([stackModules objectForKey: fileName] == nil)
if ([modules objectForKey: fileName] == nil)
{ {
[modules setObject: module forKey: fileName]; [stackModules setObject: module forKey: fileName];
} }
else else
{ {
module = [modules objectForKey: fileName]; module = [stackModules objectForKey: fileName];
} }
[modLock unlock];
} }
} }
[modLock unlock];
if (module == (id)[NSNull null]) if (module == (id)[NSNull null])
{ {
module = nil; module = nil;
@ -503,8 +488,9 @@ GSListModules()
{ {
NSArray *result; NSArray *result;
GSLoadModule(nil); // initialise
[modLock lock]; [modLock lock];
result = [GSGetStackModules() allValues]; result = [stackModules allValues];
[modLock unlock]; [modLock unlock];
return result; return result;
} }
@ -720,6 +706,7 @@ _NSFoundationUncaughtExceptionHandler (NSException *exception)
@implementation NSException @implementation NSException
#if defined(STACKSYMBOLS)
+ (void) initialize + (void) initialize
{ {
if (modLock == nil) if (modLock == nil)
@ -727,6 +714,7 @@ _NSFoundationUncaughtExceptionHandler (NSException *exception)
modLock = [NSRecursiveLock new]; modLock = [NSRecursiveLock new];
} }
} }
#endif /* STACKSYMBOLS */
+ (NSException*) exceptionWithName: (NSString*)name + (NSException*) exceptionWithName: (NSString*)name
reason: (NSString*)reason reason: (NSString*)reason

View file

@ -25,6 +25,7 @@
#define MAX_ITER 10000.0 /* Max number of iterations. */ #define MAX_ITER 10000.0 /* Max number of iterations. */
FILE *file; FILE *file;
int counter;
@interface SingleThread : NSObject @interface SingleThread : NSObject
{ {
@ -51,19 +52,17 @@ FILE *file;
NS_DURING NS_DURING
n = 1+(int)((MAX_ITER*rand())/(RAND_MAX+1.0)); n = 1+(int)((MAX_ITER*rand())/(RAND_MAX+1.0));
fflush(stdout);
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
{ {
fprintf(file, "%d ", i); fprintf(file, "%d ", i);
fflush(file); fflush(file);
} }
fflush(stdout);
[NSException raise: @"Some exception" format: @"thread %d", ident]; [NSException raise: @"Some exception" format: @"thread %d", ident];
NS_HANDLER NS_HANDLER
printf("%s: %s for thread %d\n", [[localException name] cString], NSLog(@"%@ for thread %d\n", localException, ident);
[[localException reason] cString], ident);
NS_ENDHANDLER NS_ENDHANDLER
DESTROY(pool); DESTROY(pool);
counter--;
[NSThread exit]; [NSThread exit];
} }
@ -80,6 +79,9 @@ int main()
printf("but the exception associated with each thread must match.\n"); printf("but the exception associated with each thread must match.\n");
file = fopen("/dev/null", "w"); file = fopen("/dev/null", "w");
srand(10); srand(10);
counter = N;
for (i = 0; i < N; i++) for (i = 0; i < N; i++)
threads[i] = [[SingleThread alloc] initWithInt: i]; threads[i] = [[SingleThread alloc] initWithInt: i];
NS_DURING NS_DURING
@ -88,13 +90,14 @@ int main()
toTarget: threads[i] withObject: nil]; toTarget: threads[i] withObject: nil];
// Hopefully this will end after all the other threads end. // Hopefully this will end after all the other threads end.
for (i = 0; i < N*MAX_ITER; i++) for (i = 0; i < N*MAX_ITER && counter > 0; i++)
{ {
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
fprintf(file, "%d", i); fprintf(file, "%d", i);
fflush(file); fflush(file);
} }
NS_HANDLER NS_HANDLER
printf("There's a runaway exception! Something is wrong!\n"); fprintf(stderr, "There's a runaway exception! Something is wrong!\n");
NS_ENDHANDLER NS_ENDHANDLER
fclose(file); fclose(file);
DESTROY(pool); DESTROY(pool);