Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Harfbuzz
提交
7f3d5c81
T
Third Party Harfbuzz
项目概览
OpenHarmony
/
Third Party Harfbuzz
大约 1 年 前同步成功
通知
0
Star
18
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Harfbuzz
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7f3d5c81
编写于
8月 06, 2009
作者:
B
Behdad Esfahbod
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[HB] Fix blob to use a actual mutex
上级
a794ebf4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
106 addition
and
43 deletion
+106
-43
src/hb-blob.c
src/hb-blob.c
+91
-34
src/hb-object-private.h
src/hb-object-private.h
+2
-2
src/hb-private.h
src/hb-private.h
+13
-7
未找到文件。
src/hb-blob.c
浏览文件 @
7f3d5c81
...
...
@@ -36,24 +36,31 @@
struct
_hb_blob_t
{
hb_reference_count_t
ref_count
;
hb_reference_count_t
lock
;
const
char
*
data
;
unsigned
int
length
;
hb_mutex_t
lock
;
/* the rest are protected by lock */
unsigned
int
lock_count
;
hb_memory_mode_t
mode
;
const
char
*
data
;
hb_destroy_func_t
destroy
;
void
*
user_data
;
};
static
hb_blob_t
_hb_blob_nil
=
{
HB_REFERENCE_COUNT_INVALID
,
/* ref_count */
HB_REFERENCE_COUNT_INVALID
,
/* lock */
NULL
,
/* data */
0
,
/* length */
HB_MUTEX_INIT
,
/* lock */
0
,
/* lock_count */
HB_MEMORY_MODE_READONLY_NEVER_DUPLICATE
,
/* mode */
NULL
,
/* data */
NULL
,
/* destroy */
NULL
/* user_data */
};
...
...
@@ -90,7 +97,8 @@ hb_blob_create (const char *data,
return
&
_hb_blob_nil
;
}
HB_REFERENCE_COUNT_INIT
(
blob
->
lock
,
0
);
hb_mutex_init
(
blob
->
lock
);
blob
->
lock_count
=
0
;
blob
->
data
=
data
;
blob
->
length
=
length
;
...
...
@@ -125,7 +133,10 @@ hb_blob_create_sub_blob (hb_blob_t *parent,
blob
->
data
=
pdata
+
offset
;
blob
->
length
=
MIN
(
length
,
parent
->
length
-
offset
);
hb_mutex_lock
(
parent
->
lock
);
blob
->
mode
=
parent
->
mode
;
hb_mutex_unlock
(
parent
->
lock
);
blob
->
destroy
=
(
hb_destroy_func_t
)
_hb_blob_unlock_and_destroy
;
blob
->
user_data
=
hb_blob_reference
(
parent
);
...
...
@@ -170,53 +181,80 @@ hb_blob_get_length (hb_blob_t *blob)
const
char
*
hb_blob_lock
(
hb_blob_t
*
blob
)
{
if
(
!
HB_OBJECT_IS_INERT
(
blob
))
(
void
)
hb_reference_count_inc
(
blob
->
lock
);
if
(
HB_OBJECT_IS_INERT
(
blob
))
return
NULL
;
hb_mutex_lock
(
blob
->
lock
);
blob
->
lock_count
++
;
#if HB_DEBUG
fprintf
(
stderr
,
"%p %s (%d) -> %p
\n
"
,
blob
,
__FUNCTION__
,
HB_REFERENCE_COUNT_GET_VALUE
(
blob
->
lock
)
,
blob
->
data
);
fprintf
(
stderr
,
"%p %s (%d) -> %p
\n
"
,
blob
,
__FUNCTION__
,
blob
->
lock_count
,
blob
->
data
);
#endif
hb_mutex_unlock
(
blob
->
lock
);
return
blob
->
data
;
}
void
hb_blob_unlock
(
hb_blob_t
*
blob
)
{
if
(
!
HB_OBJECT_IS_INERT
(
blob
))
{
int
old_lock
=
hb_reference_count_dec
(
blob
->
lock
)
;
assert
(
old_lock
>
0
);
}
if
(
HB_OBJECT_IS_INERT
(
blob
))
return
;
hb_mutex_lock
(
blob
->
lock
);
assert
(
blob
->
lock_count
>
0
);
blob
->
lock_count
--
;
#if HB_DEBUG
fprintf
(
stderr
,
"%p %s (%d) -> %p
\n
"
,
blob
,
__FUNCTION__
,
HB_REFERENCE_COUNT_GET_VALUE
(
blob
->
lock
),
blob
->
data
);
fprintf
(
stderr
,
"%p %s (%d) -> %p
\n
"
,
blob
,
__FUNCTION__
,
hb_atomic_int_get
(
blob
->
lock_count
),
blob
->
data
);
#endif
hb_mutex_unlock
(
blob
->
lock
);
}
hb_bool_t
hb_blob_is_writeable
(
hb_blob_t
*
blob
)
{
return
blob
->
mode
==
HB_MEMORY_MODE_WRITEABLE
;
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_WRITEABLE
;
}
hb_bool_t
hb_blob_try_writeable_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_WRITEABLE
)
{
unsigned
int
pagesize
,
mask
,
length
;
const
char
*
addr
;
#if HB_DEBUG
fprintf
(
stderr
,
"%p %s: making writeable
\n
"
,
blob
,
__FUNCTION__
);
fprintf
(
stderr
,
"%p %s: making writeable
\n
"
,
blob
,
__FUNCTION__
);
#endif
pagesize
=
(
unsigned
int
)
sysconf
(
_SC_PAGE_SIZE
);
if
((
unsigned
int
)
-
1
==
pagesize
)
{
#if HB_DEBUG
fprintf
(
stderr
,
"%p %s: %s
\n
"
,
blob
,
__FUNCTION__
,
strerror
(
errno
));
fprintf
(
stderr
,
"%p %s: %s
\n
"
,
blob
,
__FUNCTION__
,
strerror
(
errno
));
#endif
return
FALSE
;
goto
done
;
}
#if HB_DEBUG
fprintf
(
stderr
,
"%p %s: pagesize is %u
\n
"
,
blob
,
__FUNCTION__
,
pagesize
);
...
...
@@ -232,12 +270,13 @@ hb_blob_try_writeable_inplace (hb_blob_t *blob)
#endif
if
(
-
1
==
mprotect
((
void
*
)
addr
,
length
,
PROT_READ
|
PROT_WRITE
))
{
#if HB_DEBUG
fprintf
(
stderr
,
"%p %s: %s
\n
"
,
blob
,
__FUNCTION__
,
strerror
(
errno
));
fprintf
(
stderr
,
"%p %s: %s
\n
"
,
blob
,
__FUNCTION__
,
strerror
(
errno
));
#endif
return
FALSE
;
goto
done
;
}
blob
->
mode
=
HB_MEMORY_MODE_WRITEABLE
;
#if HB_DEBUG
fprintf
(
stderr
,
"%p %s: successfully made [%p..%p] (%d bytes) writeable
\n
"
,
blob
,
__FUNCTION__
,
...
...
@@ -245,25 +284,38 @@ hb_blob_try_writeable_inplace (hb_blob_t *blob)
#endif
}
return
blob
->
mode
==
HB_MEMORY_MODE_WRITEABLE
;
done:
mode
=
blob
->
mode
;
hb_mutex_unlock
(
blob
->
lock
);
return
mode
==
HB_MEMORY_MODE_WRITEABLE
;
}
hb_bool_t
hb_blob_try_writeable
(
hb_blob_t
*
blob
)
{
if
(
blob
->
mode
==
HB_MEMORY_MODE_READONLY_NEVER_DUPLICATE
)
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_NEVER_DUPLICATE
)
goto
done
;
if
(
blob
->
mode
==
HB_MEMORY_MODE_READONLY
)
{
char
*
new_data
;
#if HB_DEBUG
fprintf
(
stderr
,
"%p %s (%d) -> %p
\n
"
,
blob
,
__FUNCTION__
,
HB_REFERENCE_COUNT_GET_VALUE
(
blob
->
lock
)
,
blob
->
data
);
fprintf
(
stderr
,
"%p %s (%d) -> %p
\n
"
,
blob
,
__FUNCTION__
,
blob
->
lock_count
,
blob
->
data
);
#endif
if
(
HB_REFERENCE_COUNT_HAS_REFERENCE
(
blob
->
lock
))
return
FALSE
;
if
(
blob
->
lock_count
)
goto
done
;
new_data
=
malloc
(
blob
->
length
);
if
(
new_data
)
{
...
...
@@ -274,11 +326,16 @@ hb_blob_try_writeable (hb_blob_t *blob)
blob
->
data
=
new_data
;
blob
->
mode
=
HB_MEMORY_MODE_WRITEABLE
;
_hb_blob_destroy_user_data
(
blob
);
return
TRUE
;
}
else
return
FALSE
;
}
}
return
hb_blob_try_writeable_inplace
(
blob
);
done:
mode
=
blob
->
mode
;
hb_mutex_unlock
(
blob
->
lock
);
if
(
blob
->
mode
==
HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITEABLE
)
return
hb_blob_try_writeable_inplace
(
blob
);
return
mode
==
HB_MEMORY_MODE_WRITEABLE
;
}
src/hb-object-private.h
浏览文件 @
7f3d5c81
...
...
@@ -36,8 +36,8 @@ typedef struct {
hb_atomic_int_t
ref_count
;
}
hb_reference_count_t
;
#define hb_reference_count_inc(RC) hb_atomic_fetch_and_add ((RC).ref_count, 1)
#define hb_reference_count_dec(RC) hb_atomic_fetch_and_add ((RC).ref_count, -1)
#define hb_reference_count_inc(RC) hb_atomic_
int_
fetch_and_add ((RC).ref_count, 1)
#define hb_reference_count_dec(RC) hb_atomic_
int_
fetch_and_add ((RC).ref_count, -1)
#define HB_REFERENCE_COUNT_INIT(RC, VALUE) ((RC).ref_count = (VALUE))
...
...
src/hb-private.h
浏览文件 @
7f3d5c81
...
...
@@ -51,8 +51,6 @@
#define hb_be_uint16(v) ((uint16_t) hb_be_int16 ((uint16_t) v))
#define hb_be_uint32(v) ((uint32_t) hb_be_int32 ((uint32_t) v))
typedef
int
hb_atomic_int_t
;
/* We need external help for these */
#if HAVE_GLIB
...
...
@@ -60,12 +58,20 @@ typedef int hb_atomic_int_t;
#include <glib.h>
/* Macros to convert to/from BigEndian */
#define hb_be_int16(v) GINT16_FROM_BE (v)
#define hb_be_int32(v) GINT32_FROM_BE (v)
#define hb_be_int16(v)
GINT16_FROM_BE (v)
#define hb_be_int32(v)
GINT32_FROM_BE (v)
#define hb_atomic_fetch_and_add(AI, V) g_atomic_int_exchange_and_add (&(AI), V)
#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI))
#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), V)
typedef
int
hb_atomic_int_t
;
#define hb_atomic_int_fetch_and_add(AI, V) g_atomic_int_exchange_and_add (&(AI), V)
#define hb_atomic_int_get(AI) g_atomic_int_get (&(AI))
#define hb_atomic_int_set(AI, V) g_atomic_int_set (&(AI), V)
typedef
GStaticMutex
hb_mutex_t
;
#define HB_MUTEX_INIT G_STATIC_MUTEX_INIT
#define hb_mutex_init(M) g_static_mutex_init (&M)
#define hb_mutex_lock(M) g_static_mutex_lock (&M)
#define hb_mutex_trylock(M) g_static_mutex_trylock (&M)
#define hb_mutex_unlock(M) g_static_mutex_unlock (&M)
#else
#error "Could not find any system to define platform macros, see hb-private.h"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录