summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-10-22 02:34:42 +0200
committerDudemanguy <random342@airmail.cc>2023-11-05 17:36:17 +0000
commit55ed50ba901e70adda09f1cf8c0de7cf80cabeb3 (patch)
tree2117e03f8d0046f45d21479b67d67a3ce35bca14 /common
parent174df99ffa53f1091589eaa4fa0c16cdd55a9326 (diff)
downloadmpv-55ed50ba901e70adda09f1cf8c0de7cf80cabeb3.tar.bz2
mpv-55ed50ba901e70adda09f1cf8c0de7cf80cabeb3.tar.xz
mp_thread: prefer tracking threads with id
This change essentially removes mp_thread_self() and instead add mp_thread_id to track threads and have ability to query current thread id during runtime. This will be useful for upcoming win32 implementation, where accessing thread handle is different than on pthreads. Greatly reduces complexity. Otherweis locked map of tid <-> handle is required which is completely unnecessary for all mpv use-cases. Note that this is the mp_thread_id, not to confuse with system tid. For example on threads-posix implementation it is simply pthread_t.
Diffstat (limited to 'common')
-rw-r--r--common/stats.c10
-rw-r--r--common/stats.h2
2 files changed, 6 insertions, 6 deletions
diff --git a/common/stats.c b/common/stats.c
index cb32ba48e9..fa86aac961 100644
--- a/common/stats.c
+++ b/common/stats.c
@@ -61,7 +61,7 @@ struct stat_entry {
int64_t val_th;
int64_t time_start_ns;
int64_t cpu_start_ns;
- mp_thread thread;
+ mp_thread_id thread_id;
};
#define IS_ACTIVE(ctx) \
@@ -181,7 +181,7 @@ void stats_global_query(struct mpv_global *global, struct mpv_node *out)
break;
}
case VAL_THREAD_CPU_TIME: {
- int64_t t = mp_thread_cpu_time_ns(e->thread);
+ int64_t t = mp_thread_cpu_time_ns(e->thread_id);
if (!e->cpu_start_ns)
e->cpu_start_ns = t;
double t_msec = MP_TIME_NS_TO_MS(t - e->cpu_start_ns);
@@ -273,7 +273,7 @@ void stats_time_start(struct stats_ctx *ctx, const char *name)
return;
mp_mutex_lock(&ctx->base->lock);
struct stat_entry *e = find_entry(ctx, name);
- e->cpu_start_ns = mp_thread_cpu_time_ns(mp_thread_self());
+ e->cpu_start_ns = mp_thread_cpu_time_ns(mp_thread_current_id());
e->time_start_ns = mp_time_ns();
mp_mutex_unlock(&ctx->base->lock);
}
@@ -288,7 +288,7 @@ void stats_time_end(struct stats_ctx *ctx, const char *name)
if (e->time_start_ns) {
e->type = VAL_TIME;
e->val_rt += mp_time_ns() - e->time_start_ns;
- e->val_th += mp_thread_cpu_time_ns(mp_thread_self()) - e->cpu_start_ns;
+ e->val_th += mp_thread_cpu_time_ns(mp_thread_current_id()) - e->cpu_start_ns;
e->time_start_ns = 0;
}
mp_mutex_unlock(&ctx->base->lock);
@@ -311,7 +311,7 @@ static void register_thread(struct stats_ctx *ctx, const char *name,
mp_mutex_lock(&ctx->base->lock);
struct stat_entry *e = find_entry(ctx, name);
e->type = type;
- e->thread = mp_thread_self();
+ e->thread_id = mp_thread_current_id();
mp_mutex_unlock(&ctx->base->lock);
}
diff --git a/common/stats.h b/common/stats.h
index 03b16769f0..c3e136e5b3 100644
--- a/common/stats.h
+++ b/common/stats.h
@@ -30,5 +30,5 @@ void stats_event(struct stats_ctx *ctx, const char *name);
// or stats_unregister_thread() is called, otherwise UB will occur.
void stats_register_thread_cputime(struct stats_ctx *ctx, const char *name);
-// Remove reference to mp_thread_self().
+// Remove reference to the current thread.
void stats_unregister_thread(struct stats_ctx *ctx, const char *name);