Skip to content

Commit

Permalink
Implement ffmpeg locks with dispatch semaphores
Browse files Browse the repository at this point in the history
  • Loading branch information
jblache committed Sep 11, 2011
1 parent 38c9fe9 commit f1f9932
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,30 @@ exit_cb(int fd, short what, void *arg)
static int
ffmpeg_lockmgr(void **mutex, enum AVLockOp op)
{
dispatch_semaphore_t dsem;

dsem = (dispatch_semaphore_t)*mutex;

switch (op)
{
case AV_LOCK_CREATE:
*mutex = malloc(sizeof(pthread_mutex_t));
if (!*mutex)
dsem = dispatch_semaphore_create(1);
if (!dsem)
return 1;

return !!pthread_mutex_init(*mutex, NULL);
*mutex = dsem;
return 0;

case AV_LOCK_OBTAIN:
return !!pthread_mutex_lock(*mutex);
dispatch_semaphore_wait(dsem, DISPATCH_TIME_FOREVER);
return 0;

case AV_LOCK_RELEASE:
return !!pthread_mutex_unlock(*mutex);
dispatch_semaphore_signal(dsem);
return 0;

case AV_LOCK_DESTROY:
pthread_mutex_destroy(*mutex);
free(*mutex);

dispatch_release(dsem);
return 0;
}

Expand Down

0 comments on commit f1f9932

Please sign in to comment.