Skip to content

Latest commit

 

History

History
92 lines (74 loc) · 16.8 KB

MulleProxy.md

File metadata and controls

92 lines (74 loc) · 16.8 KB

MulleProxy

A thread-safe proxy implementation that provides locking and access control for target objects.

Base Class

NSProxy

Instance Variables

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

Methods

Initialization

Lock Operations

  • -lock - Acquires the recursive lock
  • -unlock - Releases the recursive lock
  • -tryLock - Attempts to acquire lock without blocking

Lock Sharing

Thread Access (TAO) Support

All marked with MULLE_OBJC_THREADSAFE_METHOD:

Class and Protocol Introspection

All marked with MULLE_OBJC_THREADSAFE_METHOD:

Method Introspection

All marked with MULLE_OBJC_THREADSAFE_METHOD:

Usage Example

// 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];

Important Notes

  1. Thread Safety

    • All methods are thread-safe
    • Uses recursive locking for method calls
    • Can share locks between proxies
  2. Implementation Details

    • Forwards all unknown methods to target
    • Automatically locks around forwarded calls
    • Caches access method IMPs for performance
  3. Exception Handling

    • Detects exceptions passing through proxy calls
    • Prevents potential deadlocks from exceptions
    • Raises internal inconsistency in debug builds