Esempio n. 1
0
void
hb_unicode_funcs_make_immutable (hb_unicode_funcs_t *ufuncs)
{
  if (HB_OBJECT_IS_INERT (ufuncs))
    return;

  ufuncs->immutable = TRUE;
}
Esempio n. 2
0
hb_bool_t
hb_blob_is_writable (hb_blob_t *blob)
{
  hb_memory_mode_t mode;

  if (HB_OBJECT_IS_INERT (blob))
    return FALSE;

  hb_mutex_lock (blob->lock);

  mode = blob->mode;

  hb_mutex_unlock (blob->lock);

  return mode == HB_MEMORY_MODE_WRITABLE;
}
Esempio n. 3
0
void
hb_blob_unlock (hb_blob_t *blob)
{
  if (HB_OBJECT_IS_INERT (blob))
    return;

  hb_mutex_lock (blob->lock);

  (void) (HB_DEBUG_BLOB &&
    fprintf (stderr, "%p %s (%d) -> %p\n", blob, __FUNCTION__,
	     blob->lock_count, blob->data));

  assert (blob->lock_count > 0);
  blob->lock_count--;

  hb_mutex_unlock (blob->lock);
}
Esempio n. 4
0
const char *
hb_blob_lock (hb_blob_t *blob)
{
  if (HB_OBJECT_IS_INERT (blob))
    return NULL;

  hb_mutex_lock (blob->lock);

  (void) (HB_DEBUG_BLOB &&
    fprintf (stderr, "%p %s (%d) -> %p\n", blob, __FUNCTION__,
	     blob->lock_count, blob->data));

  blob->lock_count++;

  hb_mutex_unlock (blob->lock);

  return blob->data;
}
Esempio n. 5
0
hb_bool_t
hb_blob_try_writable (hb_blob_t *blob)
{
  hb_memory_mode_t mode;

  if (HB_OBJECT_IS_INERT (blob))
    return FALSE;

  hb_mutex_lock (blob->lock);

  if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE)
    try_writable_inplace_locked (blob);

  if (blob->mode == HB_MEMORY_MODE_READONLY)
  {
    char *new_data;

    (void) (HB_DEBUG_BLOB &&
      fprintf (stderr, "%p %s (%d) -> %p\n", blob, __FUNCTION__,
	       blob->lock_count, blob->data));

    if (blob->lock_count)
      goto done;

    new_data = malloc (blob->length);
    if (new_data) {
      (void) (HB_DEBUG_BLOB &&
	fprintf (stderr, "%p %s: dupped successfully -> %p\n", blob, __FUNCTION__, blob->data));
      memcpy (new_data, blob->data, blob->length);
      _hb_blob_destroy_user_data (blob);
      blob->mode = HB_MEMORY_MODE_WRITABLE;
      blob->data = new_data;
      blob->destroy = free;
      blob->user_data = new_data;
    }
  }

done:
  mode = blob->mode;

  hb_mutex_unlock (blob->lock);

  return mode == HB_MEMORY_MODE_WRITABLE;
}
Esempio n. 6
0
hb_bool_t
hb_blob_try_writable_inplace (hb_blob_t *blob)
{
  hb_memory_mode_t mode;

  if (HB_OBJECT_IS_INERT (blob))
    return FALSE;

  hb_mutex_lock (blob->lock);

  if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE)
    try_writable_inplace_locked (blob);

  mode = blob->mode;

  hb_mutex_unlock (blob->lock);

  return mode == HB_MEMORY_MODE_WRITABLE;
}