summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-06-06 19:24:30 +0200
committerwm4 <wm4@nowhere>2014-06-06 19:24:30 +0200
commit3b7402b51cc936e5c37eec226bbfc00d4fc3381a (patch)
treed887ed95b15daebf790fd0809c5b60d284e99675 /common
parent79e76abb4d87601b9e549bef1d90f577f107a6c2 (diff)
downloadmpv-3b7402b51cc936e5c37eec226bbfc00d4fc3381a.tar.bz2
mpv-3b7402b51cc936e5c37eec226bbfc00d4fc3381a.tar.xz
client API: call wakeup callback if there are new messages
Listening on messages currently uses polling (every time mpv_wait_event() has no new events, the message buffer is polled and a message event is possibly created). Improve this situation a bit, and call the user-supplied wakeup callback. This will increase the frequency with which the wakeup callback is called, but the client is already supposed to be able to deal with this situation. Also, as before, calling mpv_wait_event() from the wakeup callback is forbidden, so the client can't read new messages from the callback directly. The wakeup pipe is written either. Since the wakeup pipe is created lazily, we can't access the pipe handle without creating a race condition or a deadlock. (This is actually very silly, since in practice the race condition won't matter, but for now let's keep it clean.)
Diffstat (limited to 'common')
-rw-r--r--common/msg.c10
-rw-r--r--common/msg_control.h4
2 files changed, 12 insertions, 2 deletions
diff --git a/common/msg.c b/common/msg.c
index d2e728b585..fa8b235243 100644
--- a/common/msg.c
+++ b/common/msg.c
@@ -82,6 +82,8 @@ struct mp_log_buffer {
struct mp_log_root *root;
struct mp_ring *ring;
int level;
+ void (*wakeup_cb)(void *ctx);
+ void *wakeup_cb_ctx;
};
// Protects some (not all) state in mp_log_root
@@ -319,6 +321,8 @@ static void write_msg_to_buffers(struct mp_log *log, int lev, char *text)
};
}
mp_ring_write(buffer->ring, (unsigned char *)&entry, sizeof(entry));
+ if (buffer->wakeup_cb)
+ buffer->wakeup_cb(buffer->wakeup_cb_ctx);
}
}
}
@@ -459,7 +463,9 @@ void mp_msg_uninit(struct mpv_global *global)
}
struct mp_log_buffer *mp_msg_log_buffer_new(struct mpv_global *global,
- int size, int level)
+ int size, int level,
+ void (*wakeup_cb)(void *ctx),
+ void *wakeup_cb_ctx)
{
struct mp_log_root *root = global->log->root;
@@ -470,6 +476,8 @@ struct mp_log_buffer *mp_msg_log_buffer_new(struct mpv_global *global,
.root = root,
.level = level,
.ring = mp_ring_new(buffer, sizeof(void *) * size),
+ .wakeup_cb = wakeup_cb,
+ .wakeup_cb_ctx = wakeup_cb_ctx,
};
if (!buffer->ring)
abort();
diff --git a/common/msg_control.h b/common/msg_control.h
index 49eeee025c..755cd10e57 100644
--- a/common/msg_control.h
+++ b/common/msg_control.h
@@ -20,7 +20,9 @@ struct mp_log_buffer_entry {
struct mp_log_buffer;
struct mp_log_buffer *mp_msg_log_buffer_new(struct mpv_global *global,
- int size, int level);
+ int size, int level,
+ void (*wakeup_cb)(void *ctx),
+ void *wakeup_cb_ctx);
void mp_msg_log_buffer_destroy(struct mp_log_buffer *buffer);
struct mp_log_buffer_entry *mp_msg_log_buffer_read(struct mp_log_buffer *buffer);