Add hb_object_lock/unlock()
This commit is contained in:
parent
6a5661f1e6
commit
2cf301968c
@ -103,7 +103,7 @@ 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 lock;
|
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_MUTEX_INIT, HB_USER_DATA_ARRAY_INIT}
|
||||||
@ -119,7 +119,7 @@ struct hb_object_header_t
|
|||||||
|
|
||||||
inline void init (void) {
|
inline void init (void) {
|
||||||
ref_count.init (1);
|
ref_count.init (1);
|
||||||
lock.init ();
|
mutex.init ();
|
||||||
user_data.init ();
|
user_data.init ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,12 +140,20 @@ 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 (lock);
|
user_data.finish (mutex);
|
||||||
lock.finish ();
|
mutex.finish ();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void lock (void) {
|
||||||
|
mutex.lock ();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void unlock (void) {
|
||||||
|
mutex.unlock ();
|
||||||
|
}
|
||||||
|
|
||||||
inline bool set_user_data (hb_user_data_key_t *key,
|
inline bool set_user_data (hb_user_data_key_t *key,
|
||||||
void * data,
|
void * data,
|
||||||
hb_destroy_func_t destroy_func,
|
hb_destroy_func_t destroy_func,
|
||||||
@ -153,14 +161,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, lock);
|
return user_data.set (key, data, destroy_func, replace, mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
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, lock);
|
return user_data.get (key, mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void trace (const char *function) const {
|
inline void trace (const char *function) const {
|
||||||
@ -211,6 +219,18 @@ static inline bool hb_object_destroy (Type *obj)
|
|||||||
return obj->header.destroy ();
|
return obj->header.destroy ();
|
||||||
}
|
}
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
|
static inline void hb_object_lock (Type *obj)
|
||||||
|
{
|
||||||
|
hb_object_trace (obj, HB_FUNC);
|
||||||
|
return obj->header.lock ();
|
||||||
|
}
|
||||||
|
template <typename Type>
|
||||||
|
static inline void hb_object_unlock (Type *obj)
|
||||||
|
{
|
||||||
|
hb_object_trace (obj, HB_FUNC);
|
||||||
|
return obj->header.unlock ();
|
||||||
|
}
|
||||||
|
template <typename Type>
|
||||||
static inline bool hb_object_set_user_data (Type *obj,
|
static inline bool hb_object_set_user_data (Type *obj,
|
||||||
hb_user_data_key_t *key,
|
hb_user_data_key_t *key,
|
||||||
void * data,
|
void * data,
|
||||||
|
Loading…
Reference in New Issue
Block a user