2010-01-23 17:00:13 +00:00
|
|
|
/* GSPThread.h
|
|
|
|
Copyright (C) 2010 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Niels Grewe <niels.grewe@halbordnung.de>
|
|
|
|
|
|
|
|
This file is part of the GNUstep Base Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2019-12-09 23:36:00 +00:00
|
|
|
Lesser General Public License for more details.
|
2010-01-23 17:00:13 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02111 USA.
|
|
|
|
*/
|
|
|
|
#ifndef _GSPThread_h_
|
|
|
|
#define _GSPThread_h_
|
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
2018-03-26 13:49:13 +00:00
|
|
|
#import "Foundation/NSLock.h"
|
|
|
|
|
|
|
|
@class GSStackTrace;
|
|
|
|
@class NSArray;
|
|
|
|
@class NSMapTable;
|
|
|
|
|
2010-01-23 17:00:13 +00:00
|
|
|
/*
|
|
|
|
* Macro to initialize recursive mutexes in a portable way. Adopted from
|
|
|
|
* libobjc2 (lock.h).
|
|
|
|
*/
|
2010-06-12 07:19:26 +00:00
|
|
|
# ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
|
|
|
|
# define GS_INIT_RECURSIVE_MUTEX(x) \
|
|
|
|
x = (pthread_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
|
|
|
|
# elif defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
|
|
|
|
# define GS_INIT_RECURSIVE_MUTEX(x) \
|
|
|
|
x = (pthread_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER
|
|
|
|
# else
|
|
|
|
# define GS_INIT_RECURSIVE_MUTEX(x) GSPThreadInitRecursiveMutex(&(x))
|
2010-01-23 17:00:13 +00:00
|
|
|
|
|
|
|
static inline void GSPThreadInitRecursiveMutex(pthread_mutex_t *x)
|
|
|
|
{
|
2010-06-12 07:19:26 +00:00
|
|
|
pthread_mutexattr_t recursiveAttributes;
|
|
|
|
pthread_mutexattr_init(&recursiveAttributes);
|
|
|
|
pthread_mutexattr_settype(&recursiveAttributes, PTHREAD_MUTEX_RECURSIVE);
|
|
|
|
pthread_mutex_init(x, &recursiveAttributes);
|
|
|
|
pthread_mutexattr_destroy(&recursiveAttributes);
|
2010-01-23 17:00:13 +00:00
|
|
|
}
|
2010-06-12 07:19:26 +00:00
|
|
|
# endif // PTHREAD_RECURSIVE_MUTEX_INITIALIZER(_NP)
|
2010-01-23 17:00:13 +00:00
|
|
|
|
2018-03-26 13:49:13 +00:00
|
|
|
|
|
|
|
/* Class to obtain/encapsulate a stack trace for exception reporting and/or
|
|
|
|
* lock tracing.
|
|
|
|
*/
|
|
|
|
@interface GSStackTrace : NSObject
|
|
|
|
{
|
|
|
|
NSArray *symbols;
|
|
|
|
NSArray *addresses;
|
|
|
|
@public
|
|
|
|
NSUInteger recursion; // Recursion count for lock trace
|
2018-04-04 11:58:06 +00:00
|
|
|
NSUInteger *returns; // The return addresses on the stack
|
2018-03-26 13:49:13 +00:00
|
|
|
int numReturns; // Number of return addresses
|
|
|
|
}
|
2018-04-04 11:58:06 +00:00
|
|
|
- (NSArray*) addresses; // Return addresses from last trace
|
|
|
|
- (NSArray*) symbols; // Return symbols from last trace
|
|
|
|
- (void) trace; // Populate with new stack trace
|
2018-03-26 13:49:13 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
/* Versions of the lock classes where the locking is never traced
|
|
|
|
*/
|
2018-04-04 11:58:06 +00:00
|
|
|
@interface GSUntracedCondition : NSCondition
|
|
|
|
@end
|
|
|
|
@interface GSUntracedConditionLock : NSConditionLock
|
|
|
|
@end
|
2018-03-26 13:49:13 +00:00
|
|
|
@interface GSUntracedLock : NSLock
|
|
|
|
@end
|
|
|
|
@interface GSUntracedRecursiveLock : NSRecursiveLock
|
|
|
|
@end
|
|
|
|
|
2018-04-04 11:58:06 +00:00
|
|
|
/* Versions of the lock classes where the locking is traced
|
|
|
|
*/
|
|
|
|
@interface GSTracedCondition : NSCondition
|
|
|
|
{
|
|
|
|
GSStackTrace *stack;
|
|
|
|
}
|
|
|
|
- (GSStackTrace*) stack;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface GSTracedConditionLock : NSConditionLock
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface GSTracedLock : NSLock
|
|
|
|
{
|
|
|
|
GSStackTrace *stack;
|
|
|
|
}
|
|
|
|
- (GSStackTrace*) stack;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface GSTracedRecursiveLock : NSRecursiveLock
|
|
|
|
{
|
|
|
|
GSStackTrace *stack;
|
|
|
|
}
|
|
|
|
- (GSStackTrace*) stack;
|
|
|
|
@end
|
|
|
|
|
2010-01-23 17:00:13 +00:00
|
|
|
#endif // _GSPThread_h_
|