Add hb_threadsafe_set_t

This commit is contained in:
Behdad Esfahbod 2011-05-05 15:07:54 -04:00
parent b45f32ee4e
commit d37486d87b
2 changed files with 55 additions and 2 deletions

View File

@ -108,6 +108,60 @@ struct hb_static_mutex_t : hb_mutex_t
};
HB_END_DECLS
template <typename item_t>
struct hb_threadsafe_set_t
{
hb_set_t <item_t> set;
hb_static_mutex_t mutex;
template <typename T>
inline item_t *insert (T v)
{
hb_mutex_lock (&mutex);
item_t *item = set.insert (v);
hb_mutex_unlock (&mutex);
return item;
}
template <typename T>
inline void remove (T v)
{
hb_mutex_lock (&mutex);
set.remove (v);
hb_mutex_unlock (&mutex);
}
template <typename T>
inline item_t *find (T v)
{
hb_mutex_lock (&mutex);
item_t *item = set.find (v);
hb_mutex_unlock (&mutex);
return item;
}
template <typename T>
inline item_t *find_or_insert (T v) {
hb_mutex_lock (&mutex);
item_t *item = set.find_or_insert (v);
hb_mutex_unlock (&mutex);
return item;
}
void finish (void) {
hb_mutex_lock (&mutex);
set.finish ();
hb_mutex_unlock (&mutex);
}
};
HB_BEGIN_DECLS
HB_END_DECLS
#endif /* HB_MUTEX_PRIVATE_HH */

View File

@ -324,8 +324,6 @@ struct hb_set_t
{
hb_array_t <item_t> items;
public:
template <typename T>
inline item_t *insert (T v)
{
@ -370,6 +368,7 @@ struct hb_set_t
void finish (void) {
for (unsigned i = 0; i < items.len; i++)
items[i].finish ();
items.shrink (0);
}
};