summaryrefslogtreecommitdiffstats
path: root/video/out/cocoa_common.m
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-10-21 04:55:41 +0200
committerDudemanguy <random342@airmail.cc>2023-11-05 17:36:17 +0000
commit174df99ffa53f1091589eaa4fa0c16cdd55a9326 (patch)
tree3a60d45615f18beed98a9b08267c28ed7e05dd5f /video/out/cocoa_common.m
parent3a8b107f6216b38a151d5ca1e9d4f2727e3418f5 (diff)
downloadmpv-174df99ffa53f1091589eaa4fa0c16cdd55a9326.tar.bz2
mpv-174df99ffa53f1091589eaa4fa0c16cdd55a9326.tar.xz
ALL: use new mp_thread abstraction
Diffstat (limited to 'video/out/cocoa_common.m')
-rw-r--r--video/out/cocoa_common.m100
1 files changed, 50 insertions, 50 deletions
diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m
index d670a7c1c3..1449da8c75 100644
--- a/video/out/cocoa_common.m
+++ b/video/out/cocoa_common.m
@@ -92,17 +92,17 @@ struct vo_cocoa_state {
uint32_t old_dwidth;
uint32_t old_dheight;
- pthread_mutex_t anim_lock;
- pthread_cond_t anim_wakeup;
+ mp_mutex anim_lock;
+ mp_cond anim_wakeup;
bool is_animating;
CVDisplayLinkRef link;
- pthread_mutex_t sync_lock;
- pthread_cond_t sync_wakeup;
+ mp_mutex sync_lock;
+ mp_cond sync_wakeup;
uint64_t sync_counter;
- pthread_mutex_t lock;
- pthread_cond_t wakeup;
+ mp_mutex lock;
+ mp_cond wakeup;
// --- The following members are protected by the lock.
// If the VO and main threads are both blocked, locking is optional
@@ -137,9 +137,9 @@ static void queue_new_video_size(struct vo *vo, int w, int h)
static void flag_events(struct vo *vo, int events)
{
struct vo_cocoa_state *s = vo->cocoa;
- pthread_mutex_lock(&s->lock);
+ mp_mutex_lock(&s->lock);
s->pending_events |= events;
- pthread_mutex_unlock(&s->lock);
+ mp_mutex_unlock(&s->lock);
if (events)
vo_wakeup(vo);
}
@@ -301,26 +301,26 @@ static void vo_cocoa_update_screen_info(struct vo *vo)
static void vo_cocoa_anim_lock(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
- pthread_mutex_lock(&s->anim_lock);
+ mp_mutex_lock(&s->anim_lock);
s->is_animating = true;
- pthread_mutex_unlock(&s->anim_lock);
+ mp_mutex_unlock(&s->anim_lock);
}
static void vo_cocoa_anim_unlock(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
- pthread_mutex_lock(&s->anim_lock);
+ mp_mutex_lock(&s->anim_lock);
s->is_animating = false;
- pthread_cond_signal(&s->anim_wakeup);
- pthread_mutex_unlock(&s->anim_lock);
+ mp_cond_signal(&s->anim_wakeup);
+ mp_mutex_unlock(&s->anim_lock);
}
static void vo_cocoa_signal_swap(struct vo_cocoa_state *s)
{
- pthread_mutex_lock(&s->sync_lock);
+ mp_mutex_lock(&s->sync_lock);
s->sync_counter += 1;
- pthread_cond_signal(&s->sync_wakeup);
- pthread_mutex_unlock(&s->sync_lock);
+ mp_cond_signal(&s->sync_wakeup);
+ mp_mutex_unlock(&s->sync_lock);
}
static void vo_cocoa_start_displaylink(struct vo_cocoa_state *s)
@@ -380,12 +380,12 @@ void vo_cocoa_init(struct vo *vo)
.cursor_visibility_wanted = true,
.fullscreen = 0,
};
- pthread_mutex_init(&s->lock, NULL);
- pthread_cond_init(&s->wakeup, NULL);
- pthread_mutex_init(&s->sync_lock, NULL);
- pthread_cond_init(&s->sync_wakeup, NULL);
- pthread_mutex_init(&s->anim_lock, NULL);
- pthread_cond_init(&s->anim_wakeup, NULL);
+ mp_mutex_init(&s->lock);
+ mp_cond_init(&s->wakeup);
+ mp_mutex_init(&s->sync_lock);
+ mp_cond_init(&s->sync_wakeup);
+ mp_mutex_init(&s->anim_lock);
+ mp_cond_init(&s->anim_wakeup);
vo->cocoa = s;
vo_cocoa_update_screen_info(vo);
vo_cocoa_init_displaylink(vo);
@@ -427,15 +427,15 @@ void vo_cocoa_uninit(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
- pthread_mutex_lock(&s->lock);
+ mp_mutex_lock(&s->lock);
s->vo_ready = false;
- pthread_cond_signal(&s->wakeup);
- pthread_mutex_unlock(&s->lock);
+ mp_cond_signal(&s->wakeup);
+ mp_mutex_unlock(&s->lock);
- pthread_mutex_lock(&s->anim_lock);
+ mp_mutex_lock(&s->anim_lock);
while(s->is_animating)
- pthread_cond_wait(&s->anim_wakeup, &s->anim_lock);
- pthread_mutex_unlock(&s->anim_lock);
+ mp_cond_wait(&s->anim_wakeup, &s->anim_lock);
+ mp_mutex_unlock(&s->anim_lock);
// close window beforehand to prevent undefined behavior when in fullscreen
// that resets the desktop to space 1
@@ -466,12 +466,12 @@ void vo_cocoa_uninit(struct vo *vo)
[s->view removeFromSuperview];
[s->view release];
- pthread_cond_destroy(&s->anim_wakeup);
- pthread_mutex_destroy(&s->anim_lock);
- pthread_cond_destroy(&s->sync_wakeup);
- pthread_mutex_destroy(&s->sync_lock);
- pthread_cond_destroy(&s->wakeup);
- pthread_mutex_destroy(&s->lock);
+ mp_cond_destroy(&s->anim_wakeup);
+ mp_mutex_destroy(&s->anim_lock);
+ mp_cond_destroy(&s->sync_wakeup);
+ mp_mutex_destroy(&s->sync_lock);
+ mp_cond_destroy(&s->wakeup);
+ mp_mutex_destroy(&s->lock);
talloc_free(s);
});
}
@@ -764,13 +764,13 @@ static void resize_event(struct vo *vo)
struct vo_cocoa_state *s = vo->cocoa;
NSRect frame = [s->video frameInPixels];
- pthread_mutex_lock(&s->lock);
+ mp_mutex_lock(&s->lock);
s->vo_dwidth = frame.size.width;
s->vo_dheight = frame.size.height;
s->pending_events |= VO_EVENT_RESIZE | VO_EVENT_EXPOSE;
// Live-resizing: make sure at least one frame will be drawn
s->frame_w = s->frame_h = 0;
- pthread_mutex_unlock(&s->lock);
+ mp_mutex_unlock(&s->lock);
[s->nsgl_ctx update];
@@ -783,17 +783,17 @@ static void vo_cocoa_resize_redraw(struct vo *vo, int width, int height)
resize_event(vo);
- pthread_mutex_lock(&s->lock);
+ mp_mutex_lock(&s->lock);
// Wait until a new frame with the new size was rendered. For some reason,
// Cocoa requires this to be done before drawRect() returns.
- struct timespec e = mp_time_ns_to_realtime(mp_time_ns_add(mp_time_ns(), 0.1));
+ int64_t e = mp_time_ns_add(mp_time_ns(), 0.1);
while (s->frame_w != width && s->frame_h != height && s->vo_ready) {
- if (pthread_cond_timedwait(&s->wakeup, &s->lock, &e))
+ if (mp_cond_timedwait_until(&s->wakeup, &s->lock, e))
break;
}
- pthread_mutex_unlock(&s->lock);
+ mp_mutex_unlock(&s->lock);
}
void vo_cocoa_swap_buffers(struct vo *vo)
@@ -801,38 +801,38 @@ void vo_cocoa_swap_buffers(struct vo *vo)
struct vo_cocoa_state *s = vo->cocoa;
// Don't swap a frame with wrong size
- pthread_mutex_lock(&s->lock);
+ mp_mutex_lock(&s->lock);
bool skip = s->pending_events & VO_EVENT_RESIZE;
- pthread_mutex_unlock(&s->lock);
+ mp_mutex_unlock(&s->lock);
if (skip)
return;
- pthread_mutex_lock(&s->sync_lock);
+ mp_mutex_lock(&s->sync_lock);
uint64_t old_counter = s->sync_counter;
while(CVDisplayLinkIsRunning(s->link) && old_counter == s->sync_counter) {
- pthread_cond_wait(&s->sync_wakeup, &s->sync_lock);
+ mp_cond_wait(&s->sync_wakeup, &s->sync_lock);
}
- pthread_mutex_unlock(&s->sync_lock);
+ mp_mutex_unlock(&s->sync_lock);
- pthread_mutex_lock(&s->lock);
+ mp_mutex_lock(&s->lock);
s->frame_w = vo->dwidth;
s->frame_h = vo->dheight;
- pthread_cond_signal(&s->wakeup);
- pthread_mutex_unlock(&s->lock);
+ mp_cond_signal(&s->wakeup);
+ mp_mutex_unlock(&s->lock);
}
static int vo_cocoa_check_events(struct vo *vo)
{
struct vo_cocoa_state *s = vo->cocoa;
- pthread_mutex_lock(&s->lock);
+ mp_mutex_lock(&s->lock);
int events = s->pending_events;
s->pending_events = 0;
if (events & VO_EVENT_RESIZE) {
vo->dwidth = s->vo_dwidth;
vo->dheight = s->vo_dheight;
}
- pthread_mutex_unlock(&s->lock);
+ mp_mutex_unlock(&s->lock);
return events;
}