Skip to content

Commit

Permalink
Fixed ESRunLoop deadlock on state accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
EverythingSolution committed Nov 13, 2011
1 parent 06aa7e8 commit 5c711d8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions ESNetworking/ESRunLoopOperation.m
@@ -1,5 +1,5 @@
#import "ESRunLoopOperation.h"
#import <libkern/OSAtomic.h>
//#import <libkern/OSAtomic.h>

@interface ESRunLoopOperation ()
// read/write versions of public properties
Expand All @@ -9,7 +9,7 @@ @interface ESRunLoopOperation ()

@implementation ESRunLoopOperation
{
OSSpinLock stateLock;
NSRecursiveLock *lock;
}

@synthesize runLoopThread=_runLoopThread;
Expand All @@ -25,8 +25,8 @@ - (id)init
NSAssert((_state == kESOperationStateInited), @"Operation initialized with invalid state: %d", _state);
if (_state != kESOperationStateInited)
self = nil;
stateLock = OS_SPINLOCK_INIT;
}
lock = [[NSRecursiveLock alloc] init];
}
return self;
}

Expand Down Expand Up @@ -69,9 +69,9 @@ - (NSSet *)actualRunLoopModes
- (ESOperationState)state
{
ESOperationState state;
OSSpinLockLock(&stateLock);
[lock lock];
state = _state;
OSSpinLockUnlock(&stateLock);
[lock unlock];
return state;
}

Expand All @@ -80,7 +80,7 @@ - (void)setState:(ESOperationState)newState
{
// any thread

OSSpinLockLock(&stateLock);
[lock lock];

ESOperationState oldState;

Expand Down Expand Up @@ -109,7 +109,7 @@ - (void)setState:(ESOperationState)newState
if ((newState == kESOperationStateExecuting) || (oldState == kESOperationStateExecuting))
[self didChangeValueForKey:@"isExecuting"];

OSSpinLockUnlock(&stateLock);
[lock unlock];
}

- (void)startOnRunLoopThread
Expand Down

0 comments on commit 5c711d8

Please sign in to comment.