Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
libfastcommon
提交
556b7337
L
libfastcommon
项目概览
阿啄debugIT
/
libfastcommon
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libfastcommon
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
556b7337
编写于
9月 14, 2020
作者:
Y
YuQing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add file src/fc_atomic.h
上级
23d8adf0
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
101 addition
and
68 deletion
+101
-68
src/Makefile.in
src/Makefile.in
+1
-1
src/common_blocked_queue.c
src/common_blocked_queue.c
+15
-28
src/common_blocked_queue.h
src/common_blocked_queue.h
+4
-5
src/common_define.h
src/common_define.h
+6
-0
src/fc_atomic.h
src/fc_atomic.h
+20
-0
src/fc_queue.c
src/fc_queue.c
+15
-26
src/fc_queue.h
src/fc_queue.h
+5
-6
src/ini_file_reader.c
src/ini_file_reader.c
+1
-1
src/ioevent_loop.c
src/ioevent_loop.c
+1
-1
src/pthread_func.c
src/pthread_func.c
+30
-0
src/pthread_func.h
src/pthread_func.h
+3
-0
未找到文件。
src/Makefile.in
浏览文件 @
556b7337
...
...
@@ -43,7 +43,7 @@ HEADER_FILES = common_define.h hash.h chain.h logger.h base64.h \
char_convert_loader.h common_blocked_queue.h
\
multi_socket_client.h skiplist_set.h uniq_skiplist.h
\
fc_list.h json_parser.h buffered_file_writer.h server_id_func.h
\
fc_queue.h fc_memory.h shared_buffer.h thread_pool.h
fc_queue.h fc_memory.h shared_buffer.h thread_pool.h
fc_atomic.h
ALL_OBJS
=
$(FAST_STATIC_OBJS)
$(FAST_SHARED_OBJS)
...
...
src/common_blocked_queue.c
浏览文件 @
556b7337
...
...
@@ -14,23 +14,11 @@ int common_blocked_queue_init_ex(struct common_blocked_queue *queue,
const
int64_t
alloc_elements_limit
=
0
;
int
result
;
if
((
result
=
init_pthread_lock
(
&
queue
->
lock
))
!=
0
)
if
((
result
=
init_pthread_lock
_cond_pair
(
&
queue
->
lc_pair
))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"init_pthread_lock fail, errno: %d, error info: %s"
,
__LINE__
,
result
,
STRERROR
(
result
));
return
result
;
}
if
((
result
=
pthread_cond_init
(
&
queue
->
cond
,
NULL
))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"pthread_cond_init fail, "
"errno: %d, error info: %s"
,
__LINE__
,
result
,
STRERROR
(
result
));
return
result
;
}
if
((
result
=
fast_mblock_init_ex1
(
&
queue
->
mblock
,
"queue_node"
,
sizeof
(
struct
common_blocked_node
),
alloc_elements_once
,
alloc_elements_limit
,
...
...
@@ -47,8 +35,7 @@ int common_blocked_queue_init_ex(struct common_blocked_queue *queue,
void
common_blocked_queue_destroy
(
struct
common_blocked_queue
*
queue
)
{
pthread_cond_destroy
(
&
queue
->
cond
);
pthread_mutex_destroy
(
&
queue
->
lock
);
destroy_pthread_lock_cond_pair
(
&
queue
->
lc_pair
);
fast_mblock_destroy
(
&
queue
->
mblock
);
}
...
...
@@ -58,7 +45,7 @@ int common_blocked_queue_push_ex(struct common_blocked_queue *queue,
int
result
;
struct
common_blocked_node
*
node
;
if
((
result
=
pthread_mutex_lock
(
&
(
queue
->
lock
)))
!=
0
)
if
((
result
=
pthread_mutex_lock
(
&
(
queue
->
l
c_pair
.
l
ock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
\
"call pthread_mutex_lock fail, "
\
...
...
@@ -71,7 +58,7 @@ int common_blocked_queue_push_ex(struct common_blocked_queue *queue,
&
queue
->
mblock
);
if
(
node
==
NULL
)
{
pthread_mutex_unlock
(
&
(
queue
->
lock
));
pthread_mutex_unlock
(
&
(
queue
->
l
c_pair
.
l
ock
));
return
ENOMEM
;
}
...
...
@@ -89,7 +76,7 @@ int common_blocked_queue_push_ex(struct common_blocked_queue *queue,
}
queue
->
tail
=
node
;
if
((
result
=
pthread_mutex_unlock
(
&
(
queue
->
lock
)))
!=
0
)
if
((
result
=
pthread_mutex_unlock
(
&
(
queue
->
l
c_pair
.
l
ock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
\
"call pthread_mutex_unlock fail, "
\
...
...
@@ -115,14 +102,14 @@ void common_blocked_queue_return_nodes(struct common_blocked_queue *queue,
last
=
last
->
next
;
}
pthread_mutex_lock
(
&
(
queue
->
lock
));
pthread_mutex_lock
(
&
(
queue
->
l
c_pair
.
l
ock
));
last
->
next
=
queue
->
head
;
queue
->
head
=
node
;
if
(
queue
->
tail
==
NULL
)
{
queue
->
tail
=
last
;
}
pthread_mutex_unlock
(
&
(
queue
->
lock
));
pthread_mutex_unlock
(
&
(
queue
->
l
c_pair
.
l
ock
));
}
void
*
common_blocked_queue_pop_ex
(
struct
common_blocked_queue
*
queue
,
...
...
@@ -132,7 +119,7 @@ void *common_blocked_queue_pop_ex(struct common_blocked_queue *queue,
void
*
data
;
int
result
;
if
((
result
=
pthread_mutex_lock
(
&
(
queue
->
lock
)))
!=
0
)
if
((
result
=
pthread_mutex_lock
(
&
(
queue
->
l
c_pair
.
l
ock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
\
"call pthread_mutex_lock fail, "
\
...
...
@@ -151,7 +138,7 @@ void *common_blocked_queue_pop_ex(struct common_blocked_queue *queue,
break
;
}
pthread_cond_wait
(
&
(
queue
->
cond
),
&
(
queue
->
lock
));
pthread_cond_wait
(
&
(
queue
->
lc_pair
.
cond
),
&
(
queue
->
lc_pair
.
lock
));
node
=
queue
->
head
;
}
...
...
@@ -172,7 +159,7 @@ void *common_blocked_queue_pop_ex(struct common_blocked_queue *queue,
}
}
while
(
0
);
if
((
result
=
pthread_mutex_unlock
(
&
(
queue
->
lock
)))
!=
0
)
if
((
result
=
pthread_mutex_unlock
(
&
(
queue
->
l
c_pair
.
l
ock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
\
"call pthread_mutex_unlock fail, "
\
...
...
@@ -189,7 +176,7 @@ struct common_blocked_node *common_blocked_queue_pop_all_nodes_ex(
struct
common_blocked_node
*
node
;
int
result
;
if
((
result
=
pthread_mutex_lock
(
&
(
queue
->
lock
)))
!=
0
)
if
((
result
=
pthread_mutex_lock
(
&
(
queue
->
l
c_pair
.
l
ock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"call pthread_mutex_lock fail, "
...
...
@@ -202,13 +189,13 @@ struct common_blocked_node *common_blocked_queue_pop_all_nodes_ex(
{
if
(
blocked
)
{
pthread_cond_wait
(
&
(
queue
->
cond
),
&
(
queue
->
lock
));
pthread_cond_wait
(
&
(
queue
->
lc_pair
.
cond
),
&
(
queue
->
lc_pair
.
lock
));
}
}
node
=
queue
->
head
;
queue
->
head
=
queue
->
tail
=
NULL
;
if
((
result
=
pthread_mutex_unlock
(
&
(
queue
->
lock
)))
!=
0
)
if
((
result
=
pthread_mutex_unlock
(
&
(
queue
->
l
c_pair
.
l
ock
)))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"call pthread_mutex_unlock fail, "
...
...
@@ -224,11 +211,11 @@ void common_blocked_queue_free_all_nodes(struct common_blocked_queue *queue,
{
struct
common_blocked_node
*
deleted
;
pthread_mutex_lock
(
&
(
queue
->
lock
));
pthread_mutex_lock
(
&
(
queue
->
l
c_pair
.
l
ock
));
while
(
node
!=
NULL
)
{
deleted
=
node
;
node
=
node
->
next
;
fast_mblock_free_object
(
&
queue
->
mblock
,
deleted
);
}
pthread_mutex_unlock
(
&
(
queue
->
lock
));
pthread_mutex_unlock
(
&
(
queue
->
l
c_pair
.
l
ock
));
}
src/common_blocked_queue.h
浏览文件 @
556b7337
...
...
@@ -29,8 +29,7 @@ struct common_blocked_queue
struct
common_blocked_node
*
head
;
struct
common_blocked_node
*
tail
;
struct
fast_mblock_man
mblock
;
pthread_mutex_t
lock
;
pthread_cond_t
cond
;
pthread_lock_cond_pair_t
lc_pair
;
};
#ifdef __cplusplus
...
...
@@ -48,7 +47,7 @@ void common_blocked_queue_destroy(struct common_blocked_queue *queue);
static
inline
void
common_blocked_queue_terminate
(
struct
common_blocked_queue
*
queue
)
{
pthread_cond_signal
(
&
(
queue
->
cond
));
pthread_cond_signal
(
&
(
queue
->
lc_pair
.
cond
));
}
static
inline
void
common_blocked_queue_terminate_all
(
...
...
@@ -57,7 +56,7 @@ static inline void common_blocked_queue_terminate_all(
int
i
;
for
(
i
=
0
;
i
<
count
;
i
++
)
{
pthread_cond_signal
(
&
(
queue
->
cond
));
pthread_cond_signal
(
&
(
queue
->
lc_pair
.
cond
));
}
}
...
...
@@ -75,7 +74,7 @@ static inline int common_blocked_queue_push(struct common_blocked_queue
{
if
(
notify
)
{
pthread_cond_signal
(
&
(
queue
->
cond
));
pthread_cond_signal
(
&
(
queue
->
lc_pair
.
cond
));
}
}
...
...
src/common_define.h
浏览文件 @
556b7337
...
...
@@ -204,6 +204,12 @@ typedef struct
int
count
;
}
key_value_array_t
;
typedef
struct
{
pthread_mutex_t
lock
;
pthread_cond_t
cond
;
}
pthread_lock_cond_pair_t
;
typedef
void
(
*
FreeDataFunc
)(
void
*
ptr
);
typedef
int
(
*
CompareFunc
)(
void
*
p1
,
void
*
p2
);
typedef
void
*
(
*
MallocFunc
)(
size_t
size
);
...
...
src/fc_atomic.h
0 → 100644
浏览文件 @
556b7337
#ifndef _FC_ATOMIC_H
#define _FC_ATOMIC_H
#ifdef __cplusplus
extern
"C"
{
#endif
#define FC_ATOMIC_CAS(var, old_value, new_value) \
do { \
if (__sync_bool_compare_and_swap(&var, old_value, new_value)) { \
break; \
} \
old_value = __sync_add_and_fetch(&var, 0); \
} while (new_value != old_value)
#ifdef __cplusplus
}
#endif
#endif
src/fc_queue.c
浏览文件 @
556b7337
...
...
@@ -15,21 +15,11 @@ int fc_queue_init(struct fc_queue *queue, const int next_ptr_offset)
{
int
result
;
if
((
result
=
init_pthread_lock
(
&
queue
->
lock
))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"init_pthread_lock fail, errno: %d, error info: %s"
,
__LINE__
,
result
,
STRERROR
(
result
));
if
((
result
=
init_pthread_lock_cond_pair
(
&
queue
->
lc_pair
))
!=
0
)
{
return
result
;
}
if
((
result
=
pthread_cond_init
(
&
queue
->
cond
,
NULL
))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"pthread_cond_init fail, "
"errno: %d, error info: %s"
,
__LINE__
,
result
,
STRERROR
(
result
));
return
result
;
}
queue
->
head
=
NULL
;
queue
->
tail
=
NULL
;
queue
->
next_ptr_offset
=
next_ptr_offset
;
...
...
@@ -38,13 +28,12 @@ int fc_queue_init(struct fc_queue *queue, const int next_ptr_offset)
void
fc_queue_destroy
(
struct
fc_queue
*
queue
)
{
pthread_cond_destroy
(
&
queue
->
cond
);
pthread_mutex_destroy
(
&
queue
->
lock
);
destroy_pthread_lock_cond_pair
(
&
queue
->
lc_pair
);
}
void
fc_queue_push_ex
(
struct
fc_queue
*
queue
,
void
*
data
,
bool
*
notify
)
{
PTHREAD_MUTEX_LOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_LOCK
(
&
queue
->
l
c_pair
.
l
ock
);
FC_QUEUE_NEXT_PTR
(
queue
,
data
)
=
NULL
;
if
(
queue
->
tail
==
NULL
)
{
queue
->
head
=
data
;
...
...
@@ -55,14 +44,14 @@ void fc_queue_push_ex(struct fc_queue *queue, void *data, bool *notify)
}
queue
->
tail
=
data
;
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
l
c_pair
.
l
ock
);
}
void
*
fc_queue_pop_ex
(
struct
fc_queue
*
queue
,
const
bool
blocked
)
{
void
*
data
;
PTHREAD_MUTEX_LOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_LOCK
(
&
queue
->
l
c_pair
.
l
ock
);
do
{
data
=
queue
->
head
;
if
(
data
==
NULL
)
{
...
...
@@ -70,7 +59,7 @@ void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked)
break
;
}
pthread_cond_wait
(
&
queue
->
cond
,
&
queue
->
lock
);
pthread_cond_wait
(
&
queue
->
lc_pair
.
cond
,
&
queue
->
lc_pair
.
lock
);
data
=
queue
->
head
;
}
...
...
@@ -82,7 +71,7 @@ void *fc_queue_pop_ex(struct fc_queue *queue, const bool blocked)
}
}
while
(
0
);
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
l
c_pair
.
l
ock
);
return
data
;
}
...
...
@@ -90,7 +79,7 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked)
{
void
*
data
;
PTHREAD_MUTEX_LOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_LOCK
(
&
queue
->
l
c_pair
.
l
ock
);
do
{
data
=
queue
->
head
;
if
(
data
==
NULL
)
{
...
...
@@ -98,7 +87,7 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked)
break
;
}
pthread_cond_wait
(
&
queue
->
cond
,
&
queue
->
lock
);
pthread_cond_wait
(
&
queue
->
lc_pair
.
cond
,
&
queue
->
lc_pair
.
lock
);
data
=
queue
->
head
;
}
...
...
@@ -107,7 +96,7 @@ void *fc_queue_pop_all_ex(struct fc_queue *queue, const bool blocked)
}
}
while
(
0
);
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
l
c_pair
.
l
ock
);
return
data
;
}
...
...
@@ -119,7 +108,7 @@ void fc_queue_push_queue_to_head_ex(struct fc_queue *queue,
return
;
}
PTHREAD_MUTEX_LOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_LOCK
(
&
queue
->
l
c_pair
.
l
ock
);
FC_QUEUE_NEXT_PTR
(
queue
,
qinfo
->
tail
)
=
queue
->
head
;
queue
->
head
=
qinfo
->
head
;
if
(
queue
->
tail
==
NULL
)
{
...
...
@@ -128,13 +117,13 @@ void fc_queue_push_queue_to_head_ex(struct fc_queue *queue,
}
else
{
*
notify
=
false
;
}
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
l
c_pair
.
l
ock
);
}
void
fc_queue_pop_to_queue
(
struct
fc_queue
*
queue
,
struct
fc_queue_info
*
qinfo
)
{
PTHREAD_MUTEX_LOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_LOCK
(
&
queue
->
l
c_pair
.
l
ock
);
if
(
queue
->
head
!=
NULL
)
{
qinfo
->
head
=
queue
->
head
;
qinfo
->
tail
=
queue
->
tail
;
...
...
@@ -142,5 +131,5 @@ void fc_queue_pop_to_queue(struct fc_queue *queue,
}
else
{
qinfo
->
head
=
qinfo
->
tail
=
NULL
;
}
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
lock
);
PTHREAD_MUTEX_UNLOCK
(
&
queue
->
l
c_pair
.
l
ock
);
}
src/fc_queue.h
浏览文件 @
556b7337
...
...
@@ -20,8 +20,7 @@ struct fc_queue
{
void
*
head
;
void
*
tail
;
pthread_mutex_t
lock
;
pthread_cond_t
cond
;
pthread_lock_cond_pair_t
lc_pair
;
int
next_ptr_offset
;
};
...
...
@@ -35,7 +34,7 @@ void fc_queue_destroy(struct fc_queue *queue);
static
inline
void
fc_queue_terminate
(
struct
fc_queue
*
queue
)
{
pthread_cond_signal
(
&
queue
->
cond
);
pthread_cond_signal
(
&
queue
->
lc_pair
.
cond
);
}
static
inline
void
fc_queue_terminate_all
(
...
...
@@ -43,7 +42,7 @@ static inline void fc_queue_terminate_all(
{
int
i
;
for
(
i
=
0
;
i
<
count
;
i
++
)
{
pthread_cond_signal
(
&
(
queue
->
cond
));
pthread_cond_signal
(
&
(
queue
->
lc_pair
.
cond
));
}
}
...
...
@@ -56,7 +55,7 @@ static inline void fc_queue_push(struct fc_queue *queue, void *data)
fc_queue_push_ex
(
queue
,
data
,
&
notify
);
if
(
notify
)
{
pthread_cond_signal
(
&
(
queue
->
cond
));
pthread_cond_signal
(
&
(
queue
->
lc_pair
.
cond
));
}
}
...
...
@@ -70,7 +69,7 @@ static inline void fc_queue_push_queue_to_head(struct fc_queue *queue,
fc_queue_push_queue_to_head_ex
(
queue
,
qinfo
,
&
notify
);
if
(
notify
)
{
pthread_cond_signal
(
&
(
queue
->
cond
));
pthread_cond_signal
(
&
(
queue
->
lc_pair
.
cond
));
}
}
...
...
src/ini_file_reader.c
浏览文件 @
556b7337
...
...
@@ -116,7 +116,7 @@ static SetDirectiveVars *iniGetVars(IniContext *pContext);
#define RETRY_FETCH_GLOBAL(szSectionName, bRetryGlobal) \
((szSectionName != NULL && szSectionName != '\0') && bRetryGlobal)
((szSectionName != NULL &&
*
szSectionName != '\0') && bRetryGlobal)
static
void
iniDoSetAnnotations
(
AnnotationEntry
*
src
,
const
int
src_count
,
AnnotationEntry
*
dest
,
int
*
dest_count
)
...
...
src/ioevent_loop.c
浏览文件 @
556b7337
...
...
@@ -89,7 +89,7 @@ int ioevent_loop(struct nio_thread_data *pThreadData,
int
count
;
memset
(
&
ev_notify
,
0
,
sizeof
(
ev_notify
));
ev_notify
.
fd
=
pThreadData
->
pipe_fds
[
0
]
;
ev_notify
.
fd
=
FC_NOTIFY_READ_FD
(
pThreadData
)
;
ev_notify
.
callback
=
recv_notify_callback
;
ev_notify
.
timer
.
data
=
pThreadData
;
if
(
ioevent_attach
(
&
pThreadData
->
ev_puller
,
...
...
src/pthread_func.c
浏览文件 @
556b7337
...
...
@@ -257,3 +257,33 @@ int fc_create_thread(pthread_t *tid, void *(*start_func)(void *),
pthread_attr_destroy
(
&
thread_attr
);
return
result
;
}
int
init_pthread_lock_cond_pair
(
pthread_lock_cond_pair_t
*
lcp
)
{
int
result
;
if
((
result
=
init_pthread_lock
(
&
lcp
->
lock
))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"init_pthread_lock fail, errno: %d, error info: %s"
,
__LINE__
,
result
,
STRERROR
(
result
));
return
result
;
}
if
((
result
=
pthread_cond_init
(
&
lcp
->
cond
,
NULL
))
!=
0
)
{
logError
(
"file: "
__FILE__
", line: %d, "
"pthread_cond_init fail, "
"errno: %d, error info: %s"
,
__LINE__
,
result
,
STRERROR
(
result
));
return
result
;
}
return
0
;
}
void
destroy_pthread_lock_cond_pair
(
pthread_lock_cond_pair_t
*
lcp
)
{
pthread_cond_destroy
(
&
lcp
->
cond
);
pthread_mutex_destroy
(
&
lcp
->
lock
);
}
src/pthread_func.h
浏览文件 @
556b7337
...
...
@@ -24,6 +24,9 @@ extern "C" {
int
init_pthread_lock
(
pthread_mutex_t
*
pthread_lock
);
int
init_pthread_attr
(
pthread_attr_t
*
pattr
,
const
int
stack_size
);
int
init_pthread_lock_cond_pair
(
pthread_lock_cond_pair_t
*
lcp
);
void
destroy_pthread_lock_cond_pair
(
pthread_lock_cond_pair_t
*
lcp
);
#define PTHREAD_MUTEX_LOCK(lock) \
do { \
int lock_res; \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录