Move object mutext into the user-data array
We are not using it for anything lse it seems.
This commit is contained in:
parent
a190011477
commit
7babfe5a79
|
@ -363,8 +363,7 @@ bool
|
||||||
hb_user_data_array_t::set (hb_user_data_key_t *key,
|
hb_user_data_array_t::set (hb_user_data_key_t *key,
|
||||||
void * data,
|
void * data,
|
||||||
hb_destroy_func_t destroy,
|
hb_destroy_func_t destroy,
|
||||||
hb_bool_t replace,
|
hb_bool_t replace)
|
||||||
hb_mutex_t &lock)
|
|
||||||
{
|
{
|
||||||
if (!key)
|
if (!key)
|
||||||
return false;
|
return false;
|
||||||
|
@ -382,20 +381,13 @@ hb_user_data_array_t::set (hb_user_data_key_t *key,
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
hb_user_data_array_t::get (hb_user_data_key_t *key,
|
hb_user_data_array_t::get (hb_user_data_key_t *key)
|
||||||
hb_mutex_t &lock)
|
|
||||||
{
|
{
|
||||||
hb_user_data_item_t item = {NULL };
|
hb_user_data_item_t item = {NULL };
|
||||||
|
|
||||||
return items.find (key, &item, lock) ? item.data : NULL;
|
return items.find (key, &item, lock) ? item.data : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
hb_user_data_array_t::finish (hb_mutex_t &lock)
|
|
||||||
{
|
|
||||||
items.finish (lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* hb_version */
|
/* hb_version */
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ struct hb_reference_count_t
|
||||||
|
|
||||||
/* user_data */
|
/* user_data */
|
||||||
|
|
||||||
#define HB_USER_DATA_ARRAY_INIT {HB_LOCKABLE_SET_INIT}
|
#define HB_USER_DATA_ARRAY_INIT {HB_MUTEX_INIT, HB_LOCKABLE_SET_INIT}
|
||||||
struct hb_user_data_array_t
|
struct hb_user_data_array_t
|
||||||
{
|
{
|
||||||
/* TODO Add tracing. */
|
/* TODO Add tracing. */
|
||||||
|
@ -81,20 +81,19 @@ struct hb_user_data_array_t
|
||||||
void finish (void) { if (destroy) destroy (data); }
|
void finish (void) { if (destroy) destroy (data); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
hb_mutex_t lock;
|
||||||
hb_lockable_set_t<hb_user_data_item_t, hb_mutex_t> items;
|
hb_lockable_set_t<hb_user_data_item_t, hb_mutex_t> items;
|
||||||
|
|
||||||
inline void init (void) { items.init (); }
|
inline void init (void) { lock.init (); items.init (); }
|
||||||
|
|
||||||
HB_INTERNAL bool set (hb_user_data_key_t *key,
|
HB_INTERNAL bool set (hb_user_data_key_t *key,
|
||||||
void * data,
|
void * data,
|
||||||
hb_destroy_func_t destroy,
|
hb_destroy_func_t destroy,
|
||||||
hb_bool_t replace,
|
hb_bool_t replace);
|
||||||
hb_mutex_t &lock);
|
|
||||||
|
|
||||||
HB_INTERNAL void *get (hb_user_data_key_t *key,
|
HB_INTERNAL void *get (hb_user_data_key_t *key);
|
||||||
hb_mutex_t &lock);
|
|
||||||
|
|
||||||
HB_INTERNAL void finish (hb_mutex_t &lock);
|
inline void finish (void) { items.finish (lock); lock.finish (); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,10 +102,9 @@ struct hb_user_data_array_t
|
||||||
struct hb_object_header_t
|
struct hb_object_header_t
|
||||||
{
|
{
|
||||||
hb_reference_count_t ref_count;
|
hb_reference_count_t ref_count;
|
||||||
hb_mutex_t mutex;
|
|
||||||
hb_user_data_array_t user_data;
|
hb_user_data_array_t user_data;
|
||||||
|
|
||||||
#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_MUTEX_INIT, HB_USER_DATA_ARRAY_INIT}
|
#define HB_OBJECT_HEADER_STATIC {HB_REFERENCE_COUNT_INVALID, HB_USER_DATA_ARRAY_INIT}
|
||||||
|
|
||||||
static inline void *create (unsigned int size) {
|
static inline void *create (unsigned int size) {
|
||||||
hb_object_header_t *obj = (hb_object_header_t *) calloc (1, size);
|
hb_object_header_t *obj = (hb_object_header_t *) calloc (1, size);
|
||||||
|
@ -119,7 +117,6 @@ struct hb_object_header_t
|
||||||
|
|
||||||
inline void init (void) {
|
inline void init (void) {
|
||||||
ref_count.init (1);
|
ref_count.init (1);
|
||||||
mutex.init ();
|
|
||||||
user_data.init ();
|
user_data.init ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +137,7 @@ struct hb_object_header_t
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ref_count.finish (); /* Do this before user_data */
|
ref_count.finish (); /* Do this before user_data */
|
||||||
user_data.finish (mutex);
|
user_data.finish ();
|
||||||
mutex.finish ();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -153,14 +149,14 @@ struct hb_object_header_t
|
||||||
if (unlikely (!this || this->is_inert ()))
|
if (unlikely (!this || this->is_inert ()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return user_data.set (key, data, destroy_func, replace, mutex);
|
return user_data.set (key, data, destroy_func, replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void *get_user_data (hb_user_data_key_t *key) {
|
inline void *get_user_data (hb_user_data_key_t *key) {
|
||||||
if (unlikely (!this || this->is_inert ()))
|
if (unlikely (!this || this->is_inert ()))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return user_data.get (key, mutex);
|
return user_data.get (key);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void trace (const char *function) const {
|
inline void trace (const char *function) const {
|
||||||
|
|
Loading…
Reference in New Issue