Add hb_threadsafe_set_t

pull/1/head
Behdad Esfahbod 14 years ago
parent b45f32ee4e
commit d37486d87b
  1. 54
      src/hb-mutex-private.hh
  2. 3
      src/hb-private.hh

@ -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 */

@ -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);
}
};

Loading…
Cancel
Save