From 4e9166f22d9e72100d11b5f7e0798d84ece4d2ac Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 20 May 2018 13:35:32 +0200 Subject: m_config: remove an unused function --- options/m_config.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'options/m_config.h') diff --git a/options/m_config.h b/options/m_config.h index 79f17b9bbe..56a4ae857e 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -203,10 +203,6 @@ void m_config_notify_change_co(struct m_config *config, // it means it works only on fields in MPContext.opts. void m_config_notify_change_opt_ptr(struct m_config *config, void *ptr); -bool m_config_is_in_group(struct m_config *config, - const struct m_sub_options *group, - struct m_config_option *co); - // Return all (visible) option names as NULL terminated string list. char **m_config_list_options(void *ta_parent, const struct m_config *config); -- cgit v1.2.3 From af4fe28af7e207bb46d5bdb7a0ee3cb97989033a Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 20 May 2018 13:43:54 +0200 Subject: m_config: remove outdated comment --- options/m_config.h | 1 - 1 file changed, 1 deletion(-) (limited to 'options/m_config.h') diff --git a/options/m_config.h b/options/m_config.h index 56a4ae857e..1f6f5157a3 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -113,7 +113,6 @@ typedef struct m_config { // contains default values for all options // options: list of options. Each option defines a member of the optstruct // and a corresponding option switch or sub-option field. -// suboptinit: if not NULL, initialize the suboption string (used for presets) // Note that the m_config object will keep pointers to defaults and options. struct m_config *m_config_new(void *talloc_ctx, struct mp_log *log, size_t size, const void *defaults, -- cgit v1.2.3 From 4cb264a3ff35cd1dcd8a41f87fb87791920d5156 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 20 May 2018 20:50:01 +0200 Subject: m_config: remove an old temporary hack Actually rewrite most of the option management code. This affects how options are allocated, and how thread-safe access to them is done. One thing that is nicer is that creating m_config_cache does not need to ridiculously recreate and store the entire option list again. Instead, option metadata and option storage are now separated. m_config contains the metadata, and m_config_data all or parts of the actual option values. (m_config_cache simply uses the metadata part of m_config, which is immutable after creation.) The mentioned hack was introduced in commit 1a2319f3e4cc4, and is the global state around g_group_mutex. Although it was "benign" global state, it's good that it's finally removed. --- options/m_config.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'options/m_config.h') diff --git a/options/m_config.h b/options/m_config.h index 1f6f5157a3..2c4531ff86 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -43,8 +43,7 @@ struct m_config_option { bool is_set_from_config : 1; // Set by a config file bool is_set_locally : 1; // Has a backup entry bool warning_was_printed : 1; - int16_t shadow_offset; // Offset into m_config_shadow.data - int16_t group; // Index into m_config.groups + int16_t group_index; // Index into m_config.groups const char *name; // Full name (ie option-subopt) const struct m_option *opt; // Option description void *data; // Raw value of the option @@ -94,14 +93,17 @@ typedef struct m_config { void *optstruct; // struct mpopts or other - int shadow_size; - - // List of m_sub_options instances. + // Private. List of m_sub_options instances. // Index 0 is the top-level and is always present. + // Immutable after init. + // Invariant: a parent is always at a lower index than any of its children. struct m_config_group *groups; int num_groups; - // Thread-safe shadow memory; only set for the main m_config. + // Private. Non-NULL if data was allocated. m_config_option.data uses it. + struct m_config_data *data; + + // Private. Thread-safe shadow memory; only set for the main m_config. struct m_config_shadow *shadow; } m_config_t; @@ -264,14 +266,13 @@ struct mpv_node m_config_get_profiles(struct m_config *config); // the cache itself is allowed. struct m_config_cache { // The struct as indicated by m_config_cache_alloc's group parameter. + // (Internally the same as data->gdata[0]->udata.) void *opts; // Internal. - struct m_config_shadow *shadow; - struct m_config *shadow_config; - long long ts; - int group; - bool in_list; + struct m_config_shadow *shadow; // real data + struct m_config_data *data; // copy for the cache user + bool in_list; // registered as listener with root config // --- Implicitly synchronized by setting/unsetting wakeup_cb. struct mp_dispatch_queue *wakeup_dispatch_queue; void (*wakeup_dispatch_cb)(void *ctx); @@ -320,6 +321,7 @@ bool m_config_cache_update(struct m_config_cache *cache); // Like m_config_cache_alloc(), but return the struct (m_config_cache->opts) // directly, with no way to update the config. Basically this returns a copy // with a snapshot of the current option values. +// group==NULL is a special case, and always returns the root group. void *mp_get_config_group(void *ta_parent, struct mpv_global *global, const struct m_sub_options *group); -- cgit v1.2.3 From 3f061dd62912728bf152c06e7c27b43a3cef312d Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 21 May 2018 00:11:48 +0200 Subject: m_config: remove unused fields --- options/m_config.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'options/m_config.h') diff --git a/options/m_config.h b/options/m_config.h index 2c4531ff86..8a8dba8461 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -60,11 +60,6 @@ typedef struct m_config { struct m_config_option *opts; // all options, even suboptions int num_opts; - // Creation parameters - size_t size; - const void *defaults; - const struct m_option *options; - // List of defined profiles. struct m_profile *profiles; // Depth when recursively including profiles. -- cgit v1.2.3 From 816ad035191970decb17086f5c011edffc257b6c Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 21 May 2018 13:45:06 +0200 Subject: m_config: remove extra default_data field Just wastes memory (a few KB, because there are so many options). --- options/m_config.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'options/m_config.h') diff --git a/options/m_config.h b/options/m_config.h index 8a8dba8461..19da75e83c 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -47,7 +47,6 @@ struct m_config_option { const char *name; // Full name (ie option-subopt) const struct m_option *opt; // Option description void *data; // Raw value of the option - const void *default_data; // Raw default value }; // Config object @@ -179,6 +178,8 @@ struct m_config_option *m_config_get_co(const struct m_config *config, int m_config_get_co_count(struct m_config *config); struct m_config_option *m_config_get_co_index(struct m_config *config, int index); +const void *m_config_get_co_default(const struct m_config *config, + struct m_config_option *co); // Return the n-th option by position. n==0 is the first option. If there are // less than (n + 1) options, return NULL. -- cgit v1.2.3 From fe6b2f9103450679a07da44bdad31707b597cd20 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 21 May 2018 15:21:09 +0200 Subject: m_config: add a special define to access main config Passing NULL to mp_get_config_group() returns the main option struct. This is just a dumb hack to deal with inconsistencies caused by legacy things (as I'll claim), and will probably be changed in the future. So before littering the whole code base with hard to find NULL parameters, require using callers an easy to find separate define. --- options/m_config.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'options/m_config.h') diff --git a/options/m_config.h b/options/m_config.h index 19da75e83c..40cd367613 100644 --- a/options/m_config.h +++ b/options/m_config.h @@ -278,15 +278,17 @@ struct m_config_cache { void *wakeup_cb_ctx; }; +#define GLOBAL_CONFIG NULL + // Create a mirror copy from the global options. // Keep in mind that a m_config_cache object is not thread-safe; it merely // provides thread-safe access to the global options. All API functions for // the same m_config_cache object must synchronized, unless otherwise noted. // ta_parent: parent for the returned allocation // global: option data source -// group: the option group to return. This can be NULL for the global option -// struct (MPOpts), or m_sub_options used in a certain OPT_SUBSTRUCT() -// item. +// group: the option group to return. This can be GLOBAL_CONFIG for the global +// option struct (MPOpts), or m_sub_options used in a certain +// OPT_SUBSTRUCT() item. struct m_config_cache *m_config_cache_alloc(void *ta_parent, struct mpv_global *global, const struct m_sub_options *group); @@ -317,7 +319,7 @@ bool m_config_cache_update(struct m_config_cache *cache); // Like m_config_cache_alloc(), but return the struct (m_config_cache->opts) // directly, with no way to update the config. Basically this returns a copy // with a snapshot of the current option values. -// group==NULL is a special case, and always returns the root group. +// group==GLOBAL_CONFIG is a special case, and always returns the root group. void *mp_get_config_group(void *ta_parent, struct mpv_global *global, const struct m_sub_options *group); -- cgit v1.2.3