parent
a4b1900913
commit
b81bd42951
|
@ -113,7 +113,7 @@ hb_blob_create (const char *data,
|
||||||
return &_hb_blob_nil;
|
return &_hb_blob_nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_mutex_init (blob->lock);
|
hb_mutex_init (&blob->lock);
|
||||||
blob->lock_count = 0;
|
blob->lock_count = 0;
|
||||||
|
|
||||||
blob->data = data;
|
blob->data = data;
|
||||||
|
@ -147,13 +147,13 @@ hb_blob_create_sub_blob (hb_blob_t *parent,
|
||||||
|
|
||||||
pdata = hb_blob_lock (parent);
|
pdata = hb_blob_lock (parent);
|
||||||
|
|
||||||
hb_mutex_lock (parent->lock);
|
hb_mutex_lock (&parent->lock);
|
||||||
blob = hb_blob_create (pdata + offset,
|
blob = hb_blob_create (pdata + offset,
|
||||||
MIN (length, parent->length - offset),
|
MIN (length, parent->length - offset),
|
||||||
parent->mode,
|
parent->mode,
|
||||||
hb_blob_reference (parent),
|
hb_blob_reference (parent),
|
||||||
(hb_destroy_func_t) _hb_blob_unlock_and_destroy);
|
(hb_destroy_func_t) _hb_blob_unlock_and_destroy);
|
||||||
hb_mutex_unlock (parent->lock);
|
hb_mutex_unlock (&parent->lock);
|
||||||
|
|
||||||
return blob;
|
return blob;
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ hb_blob_destroy (hb_blob_t *blob)
|
||||||
if (!hb_object_destroy (blob)) return;
|
if (!hb_object_destroy (blob)) return;
|
||||||
|
|
||||||
_hb_blob_destroy_user_data (blob);
|
_hb_blob_destroy_user_data (blob);
|
||||||
hb_mutex_free (blob->lock);
|
hb_mutex_free (&blob->lock);
|
||||||
|
|
||||||
free (blob);
|
free (blob);
|
||||||
}
|
}
|
||||||
|
@ -210,7 +210,7 @@ hb_blob_lock (hb_blob_t *blob)
|
||||||
if (hb_object_is_inert (blob))
|
if (hb_object_is_inert (blob))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
hb_mutex_lock (blob->lock);
|
hb_mutex_lock (&blob->lock);
|
||||||
|
|
||||||
(void) (HB_DEBUG_BLOB &&
|
(void) (HB_DEBUG_BLOB &&
|
||||||
fprintf (stderr, "%p %s (%d) -> %p\n", blob, HB_FUNC,
|
fprintf (stderr, "%p %s (%d) -> %p\n", blob, HB_FUNC,
|
||||||
|
@ -218,7 +218,7 @@ hb_blob_lock (hb_blob_t *blob)
|
||||||
|
|
||||||
blob->lock_count++;
|
blob->lock_count++;
|
||||||
|
|
||||||
hb_mutex_unlock (blob->lock);
|
hb_mutex_unlock (&blob->lock);
|
||||||
|
|
||||||
return blob->data;
|
return blob->data;
|
||||||
}
|
}
|
||||||
|
@ -229,7 +229,7 @@ hb_blob_unlock (hb_blob_t *blob)
|
||||||
if (hb_object_is_inert (blob))
|
if (hb_object_is_inert (blob))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hb_mutex_lock (blob->lock);
|
hb_mutex_lock (&blob->lock);
|
||||||
|
|
||||||
(void) (HB_DEBUG_BLOB &&
|
(void) (HB_DEBUG_BLOB &&
|
||||||
fprintf (stderr, "%p %s (%d) -> %p\n", blob, HB_FUNC,
|
fprintf (stderr, "%p %s (%d) -> %p\n", blob, HB_FUNC,
|
||||||
|
@ -238,7 +238,7 @@ hb_blob_unlock (hb_blob_t *blob)
|
||||||
assert (blob->lock_count > 0);
|
assert (blob->lock_count > 0);
|
||||||
blob->lock_count--;
|
blob->lock_count--;
|
||||||
|
|
||||||
hb_mutex_unlock (blob->lock);
|
hb_mutex_unlock (&blob->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
hb_bool_t
|
hb_bool_t
|
||||||
|
@ -249,11 +249,11 @@ hb_blob_is_writable (hb_blob_t *blob)
|
||||||
if (hb_object_is_inert (blob))
|
if (hb_object_is_inert (blob))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
hb_mutex_lock (blob->lock);
|
hb_mutex_lock (&blob->lock);
|
||||||
|
|
||||||
mode = blob->mode;
|
mode = blob->mode;
|
||||||
|
|
||||||
hb_mutex_unlock (blob->lock);
|
hb_mutex_unlock (&blob->lock);
|
||||||
|
|
||||||
return mode == HB_MEMORY_MODE_WRITABLE;
|
return mode == HB_MEMORY_MODE_WRITABLE;
|
||||||
}
|
}
|
||||||
|
@ -331,14 +331,14 @@ hb_blob_try_writable_inplace (hb_blob_t *blob)
|
||||||
if (hb_object_is_inert (blob))
|
if (hb_object_is_inert (blob))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
hb_mutex_lock (blob->lock);
|
hb_mutex_lock (&blob->lock);
|
||||||
|
|
||||||
if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE)
|
if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE)
|
||||||
try_writable_inplace_locked (blob);
|
try_writable_inplace_locked (blob);
|
||||||
|
|
||||||
mode = blob->mode;
|
mode = blob->mode;
|
||||||
|
|
||||||
hb_mutex_unlock (blob->lock);
|
hb_mutex_unlock (&blob->lock);
|
||||||
|
|
||||||
return mode == HB_MEMORY_MODE_WRITABLE;
|
return mode == HB_MEMORY_MODE_WRITABLE;
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ hb_blob_try_writable (hb_blob_t *blob)
|
||||||
if (hb_object_is_inert (blob))
|
if (hb_object_is_inert (blob))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
hb_mutex_lock (blob->lock);
|
hb_mutex_lock (&blob->lock);
|
||||||
|
|
||||||
if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE)
|
if (blob->mode == HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE)
|
||||||
try_writable_inplace_locked (blob);
|
try_writable_inplace_locked (blob);
|
||||||
|
@ -383,7 +383,7 @@ hb_blob_try_writable (hb_blob_t *blob)
|
||||||
done:
|
done:
|
||||||
mode = blob->mode;
|
mode = blob->mode;
|
||||||
|
|
||||||
hb_mutex_unlock (blob->lock);
|
hb_mutex_unlock (&blob->lock);
|
||||||
|
|
||||||
return mode == HB_MEMORY_MODE_WRITABLE;
|
return mode == HB_MEMORY_MODE_WRITABLE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,11 +52,11 @@ typedef volatile int hb_atomic_int_t;
|
||||||
|
|
||||||
typedef GStaticMutex hb_mutex_t;
|
typedef GStaticMutex hb_mutex_t;
|
||||||
#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT
|
#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT
|
||||||
#define hb_mutex_init(M) g_static_mutex_init (&(M))
|
#define hb_mutex_init(M) g_static_mutex_init (M)
|
||||||
#define hb_mutex_lock(M) g_static_mutex_lock (&(M))
|
#define hb_mutex_lock(M) g_static_mutex_lock (M)
|
||||||
#define hb_mutex_trylock(M) g_static_mutex_trylock (&(M))
|
#define hb_mutex_trylock(M) g_static_mutex_trylock (M)
|
||||||
#define hb_mutex_unlock(M) g_static_mutex_unlock (&(M))
|
#define hb_mutex_unlock(M) g_static_mutex_unlock (M)
|
||||||
#define hb_mutex_free(M) g_static_mutex_free (&(M))
|
#define hb_mutex_free(M) g_static_mutex_free (M)
|
||||||
|
|
||||||
|
|
||||||
#elif defined(_MSC_VER)
|
#elif defined(_MSC_VER)
|
||||||
|
@ -72,11 +72,11 @@ typedef long hb_atomic_int_t;
|
||||||
|
|
||||||
typedef CRITICAL_SECTION hb_mutex_t;
|
typedef CRITICAL_SECTION hb_mutex_t;
|
||||||
#define HB_MUTEX_INIT { NULL, 0, 0, NULL, NULL, 0 }
|
#define HB_MUTEX_INIT { NULL, 0, 0, NULL, NULL, 0 }
|
||||||
#define hb_mutex_init(M) InitializeCriticalSection (&(M))
|
#define hb_mutex_init(M) InitializeCriticalSection (M)
|
||||||
#define hb_mutex_lock(M) EnterCriticalSection (&(M))
|
#define hb_mutex_lock(M) EnterCriticalSection (M)
|
||||||
#define hb_mutex_trylock(M) TryEnterCriticalSection (&(M))
|
#define hb_mutex_trylock(M) TryEnterCriticalSection (M)
|
||||||
#define hb_mutex_unlock(M) LeaveCriticalSection (&(M))
|
#define hb_mutex_unlock(M) LeaveCriticalSection (M)
|
||||||
#define hb_mutex_free(M) DeleteCriticalSection (&(M))
|
#define hb_mutex_free(M) DeleteCriticalSection (M)
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -90,11 +90,11 @@ typedef volatile int hb_atomic_int_t;
|
||||||
|
|
||||||
typedef volatile int hb_mutex_t;
|
typedef volatile int hb_mutex_t;
|
||||||
#define HB_MUTEX_INIT 0
|
#define HB_MUTEX_INIT 0
|
||||||
#define hb_mutex_init(M) ((void) ((M) = 0))
|
#define hb_mutex_init(M) ((void) (*(M) = 0))
|
||||||
#define hb_mutex_lock(M) ((void) ((M) = 1))
|
#define hb_mutex_lock(M) ((void) (*(M) = 1))
|
||||||
#define hb_mutex_trylock(M) ((M) = 1, 1)
|
#define hb_mutex_trylock(M) (*(M) = 1, 1)
|
||||||
#define hb_mutex_unlock(M) ((void) ((M) = 0))
|
#define hb_mutex_unlock(M) ((void) (*(M) = 0))
|
||||||
#define hb_mutex_free(M) ((void) ((M) = 2))
|
#define hb_mutex_free(M) ((void) (*(M) = 2))
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -103,7 +103,7 @@ typedef volatile int hb_mutex_t;
|
||||||
struct hb_static_mutex_t : hb_mutex_t
|
struct hb_static_mutex_t : hb_mutex_t
|
||||||
{
|
{
|
||||||
hb_static_mutex_t (void) {
|
hb_static_mutex_t (void) {
|
||||||
hb_mutex_init (*this);
|
hb_mutex_init (this);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue