A thread-safe proxy implementation that provides locking and access control for target objects.
NSProxy
NSRecursiveLock *__lock; // Recursive lock for thread safety
id __target; // The proxied object
IMP __gain_imp; // Cached method for gaining access
IMP __relinquish_imp; // Cached method for relinquishing access
NSUInteger __taoStrategy; // Thread access strategy
+proxyWithObject:
- Creates and returns an autoreleased proxy with lock+locklessProxyWithObject:
- Creates proxy without lock-initWithObject:
- Initializes proxy with lock-initNoLockWithObject:
- Initializes proxy without lock-lock
- Acquires the recursive lock-unlock
- Releases the recursive lock-tryLock
- Attempts to acquire lock without blocking-didShareRecursiveLock:
- Called after lock sharing to update thread affinity-shareRecursiveLock:
- Shares lock with another lock-shareRecursiveLockWithObject:
- Shares lock with a MulleObject-shareRecursiveLockWithProxy:
- Shares lock with another proxyAll marked with MULLE_OBJC_THREADSAFE_METHOD
: - -mulleIsThreadSafe
- Returns YES - -mulleIsAccessible
- Returns YES - -mulleIsAccessibleByThread:
- Returns YES - -mulleTAOStrategy
- Returns MulleObjCTAOKnownThreadSafe - -mulleRelinquishAccess
- Retains self - -mulleGainAccess
- Autoreleases self - -mulleGainAccessWithTAOStrategy:
- Autoreleases self - -mulleRelinquishAccessWithTAOStrategy:
- Retains self
All marked with MULLE_OBJC_THREADSAFE_METHOD
: - -class
- Returns target’s class - -superclass
- Returns target’s superclass - -isKindOfClass:
- Forwards to target - -isMemberOfClass:
- Forwards to target - -mulleContainsProtocol:
- Forwards to target - -conformsToProtocol:
- Forwards to target
All marked with MULLE_OBJC_THREADSAFE_METHOD
: - -methodForSelector:
- Forwards to target - -respondsToSelector:
- Forwards to target - -methodSignatureForSelector:
- Forwards to target
// Create proxy with lock
id target = [MyObject new];
MulleProxy *proxy = [MulleProxy proxyWithObject:target];
// Use proxy - automatically locks/unlocks around method calls
[proxy doSomething];
// Share lock between proxies
MulleProxy *proxy2 = [MulleProxy proxyWithObject:target2];
[proxy2 shareRecursiveLockWithProxy:proxy];