Skip to content

Commit

Permalink
Fix potential deadlock in SyphonClient
Browse files Browse the repository at this point in the history
Problem since eafbc08
  • Loading branch information
bangnoise committed Sep 28, 2016
1 parent 206242f commit e315503
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SyphonClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
int32_t _lock;
CGLContextObj _context;
SYPHON_IMAGE_UNIQUE_CLASS_NAME *_frame;
BOOL _frameValid;
int32_t _frameValid;
}
/*!
Returns a new client instance for the described server. You should check the isValid property after initialization to ensure a connection was made to the server.
Expand Down
9 changes: 4 additions & 5 deletions SyphonClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ - (void)receiveNewFrame

- (void)invalidateFrame
{
OSSpinLockLock(&_lock);
/*
Because releasing a SyphonImage causes a glDelete we postpone deletion until we can do work in the context
DO NOT take the lock here, it may already be locked and waiting for the SyphonClientConnectionManager lock
*/
_frameValid = NO;
OSSpinLockUnlock(&_lock);
OSAtomicTestAndClearBarrier(0, &_frameValid);
}

#pragma mark Rendering frames
Expand All @@ -154,11 +153,11 @@ - (SyphonImage *)newFrameImage
{
OSSpinLockLock(&_lock);
_lastFrameID = [(SyphonClientConnectionManager *)_connectionManager frameID];
if (_frameValid == NO)
if (_frameValid == 0)
{
[_frame release];
_frame = [(SyphonClientConnectionManager *)_connectionManager newFrameForContext:_context];
_frameValid = YES;
OSAtomicTestAndSetBarrier(0, &_frameValid);
}
OSSpinLockUnlock(&_lock);
return [_frame retain];
Expand Down

0 comments on commit e315503

Please sign in to comment.