Last active
January 14, 2025 13:11
-
-
Save AdityaDeshmane/0d3a92c0454a915abda7 to your computer and use it in GitHub Desktop.
iOS : NSCondition Lock Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(sqlite3 *) getConnection | |
{ | |
@try | |
{ | |
[connMutex lock]; | |
while (bInUse == YES) | |
{ | |
[connMutex wait]; | |
} | |
bInUse = YES; | |
return _database; | |
} | |
@catch(NSException *e) | |
{ | |
return NULL; | |
} | |
@finally | |
{ | |
[connMutex unlock]; | |
} | |
return NULL; | |
} | |
-(void) releaseConnection | |
{ | |
@try | |
{ | |
[connMutex lock]; | |
if(bInUse == YES) | |
{ | |
bInUse = NO; | |
[connMutex signal]; | |
} | |
} | |
@catch(NSException *e) | |
{ | |
return; | |
} | |
@finally | |
{ | |
[connMutex unlock]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment