Move object mutext into the user-data array

We are not using it for anything lse it seems.
This commit is contained in:
Behdad Esfahbod 2012-12-04 00:35:54 +02:00
parent a190011477
commit 7babfe5a79
2 changed files with 12 additions and 24 deletions

View File

@ -363,8 +363,7 @@ bool
hb_user_data_array_t::set (hb_user_data_key_t *key,
void * data,
hb_destroy_func_t destroy,
hb_bool_t replace,
hb_mutex_t &lock)
hb_bool_t replace)
{
if (!key)
return false;
@ -382,20 +381,13 @@ hb_user_data_array_t::set (hb_user_data_key_t *key,
}
void *
hb_user_data_array_t::get (hb_user_data_key_t *key,
hb_mutex_t &lock)
hb_user_data_array_t::get (hb_user_data_key_t *key)
{
hb_user_data_item_t item = {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 */

View File

@ -65,7 +65,7 @@ struct hb_reference_count_t
/* 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
{
/* TODO Add tracing. */
@ -81,20 +81,19 @@ struct hb_user_data_array_t
void finish (void) { if (destroy) destroy (data); }
};
hb_mutex_t lock;
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,
void * data,
hb_destroy_func_t destroy,
hb_bool_t replace,
hb_mutex_t &lock);
hb_bool_t replace);
HB_INTERNAL void *get (hb_user_data_key_t *key,
hb_mutex_t &lock);
HB_INTERNAL void *get (hb_user_data_key_t *key);
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
{
hb_reference_count_t ref_count;
hb_mutex_t mutex;
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) {
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) {
ref_count.init (1);
mutex.init ();
user_data.init ();
}
@ -140,8 +137,7 @@ struct hb_object_header_t
return false;
ref_count.finish (); /* Do this before user_data */
user_data.finish (mutex);
mutex.finish ();
user_data.finish ();
return true;
}
@ -153,14 +149,14 @@ struct hb_object_header_t
if (unlikely (!this || this->is_inert ()))
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) {
if (unlikely (!this || this->is_inert ()))
return NULL;
return user_data.get (key, mutex);
return user_data.get (key);
}
inline void trace (const char *function) const {