Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
阿啄debugIT
libfastcommon
提交
3d748375
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,发现更多精彩内容 >>
提交
3d748375
编写于
11月 30, 2020
作者:
Y
YuQing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add tests/test_data_visible.c
上级
93e6cec0
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
163 addition
and
1 deletion
+163
-1
src/tests/Makefile
src/tests/Makefile
+1
-1
src/tests/test_data_visible.c
src/tests/test_data_visible.c
+162
-0
未找到文件。
src/tests/Makefile
浏览文件 @
3d748375
...
...
@@ -9,7 +9,7 @@ ALL_PRGS = test_allocator test_skiplist test_multi_skiplist test_mblock test_blo
test_logger test_skiplist_set test_crc32 test_thourands_seperator test_sched_thread
\
test_json_parser test_pthread_lock test_uniq_skiplist test_split_string
\
test_server_id_func test_pipe test_atomic test_file_write_hole test_file_lock
\
test_thread_pool
test_thread_pool
test_data_visible
all
:
$(ALL_PRGS)
.c
:
...
...
src/tests/test_data_visible.c
0 → 100644
浏览文件 @
3d748375
/*
* Copyright (c) 2020 YuQing <384681@qq.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the Lesser GNU General Public License, version 3
* or later ("LGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the Lesser GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <inttypes.h>
#include <sys/time.h>
#include "fastcommon/logger.h"
#include "fastcommon/fc_queue.h"
#include "fastcommon/shared_func.h"
#include "fastcommon/pthread_func.h"
typedef
struct
fs_api_slice_entry
{
int
data
;
volatile
int
v
;
struct
fs_api_slice_entry
*
next
;
}
FSAPISliceEntry
;
static
bool
continue_flag
=
true
;
static
struct
fast_mblock_man
allocator
;
static
struct
fc_queue
queue
;
static
void
*
thread_func
(
void
*
arg
)
{
FSAPISliceEntry
*
slice
;
int
value
;
printf
(
"file: "
__FILE__
", line: %d, "
"thread enter ...
\n
"
,
__LINE__
);
while
(
continue_flag
)
{
slice
=
(
FSAPISliceEntry
*
)
fc_queue_pop
(
&
queue
);
if
(
slice
!=
NULL
)
{
value
=
__sync_fetch_and_add
(
&
slice
->
v
,
0
);
if
(
slice
->
data
!=
value
)
{
printf
(
"data: %d != value: %d
\n
"
,
slice
->
data
,
value
);
}
fast_mblock_free_object
(
&
allocator
,
slice
);
}
}
printf
(
"file: "
__FILE__
", line: %d, "
"thread done!
\n
"
,
__LINE__
);
return
NULL
;
}
static
void
sigQuitHandler
(
int
sig
)
{
if
(
continue_flag
)
{
continue_flag
=
false
;
printf
(
"file: "
__FILE__
", line: %d, "
"catch signal %d, program exiting...
\n
"
,
__LINE__
,
sig
);
}
}
static
void
sigHupHandler
(
int
sig
)
{
printf
(
"file: "
__FILE__
", line: %d, "
"catch signal %d
\n
"
,
__LINE__
,
sig
);
}
static
int
setup_signal_handler
()
{
struct
sigaction
act
;
memset
(
&
act
,
0
,
sizeof
(
act
));
sigemptyset
(
&
act
.
sa_mask
);
signal
(
SIGHUP
,
sigHupHandler
);
/*
act.sa_handler = sigHupHandler;
if(sigaction(SIGHUP, &act, NULL) < 0) {
fprintf(stderr, "file: "__FILE__", line: %d, "
"call sigaction fail, errno: %d, error info: %s\n",
__LINE__, errno, strerror(errno));
return errno;
}
*/
act
.
sa_handler
=
sigQuitHandler
;
if
(
sigaction
(
SIGINT
,
&
act
,
NULL
)
<
0
||
sigaction
(
SIGTERM
,
&
act
,
NULL
)
<
0
||
sigaction
(
SIGQUIT
,
&
act
,
NULL
)
<
0
)
{
fprintf
(
stderr
,
"file: "
__FILE__
", line: %d, "
"call sigaction fail, errno: %d, error info: %s
\n
"
,
__LINE__
,
errno
,
strerror
(
errno
));
return
errno
;
}
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
result
;
int
i
;
int
total
;
pthread_t
tid
;
FSAPISliceEntry
*
slice
;
pthread_mutex_t
lock
;
log_init
();
if
((
result
=
setup_signal_handler
())
!=
0
)
{
return
result
;
}
if
((
result
=
fast_mblock_init_ex1
(
&
allocator
,
"slice_entry"
,
sizeof
(
FSAPISliceEntry
),
1024
,
1024
,
NULL
,
NULL
,
true
))
!=
0
)
{
return
result
;
}
allocator
.
exceed_log_level
=
LOG_NOTHING
;
if
((
result
=
init_pthread_lock
(
&
lock
))
!=
0
)
{
return
result
;
}
if
((
result
=
fc_queue_init
(
&
queue
,
(
long
)
(
&
((
FSAPISliceEntry
*
)
NULL
)
->
next
)))
!=
0
)
{
return
result
;
}
if
((
result
=
pthread_create
(
&
tid
,
NULL
,
thread_func
,
NULL
))
!=
0
)
{
return
result
;
}
total
=
0
;
i
=
0
;
while
(
continue_flag
&&
i
++
<
100
*
1000
*
1000
)
{
slice
=
(
FSAPISliceEntry
*
)
fast_mblock_alloc_object
(
&
allocator
);
if
(
slice
!=
NULL
)
{
slice
->
data
=
__sync_add_and_fetch
(
&
slice
->
v
,
1
);
fc_queue_push
(
&
queue
,
slice
);
total
++
;
}
}
continue_flag
=
false
;
fc_sleep_ms
(
1000
);
printf
(
"file: "
__FILE__
", line: %d, "
"total count: %d.
\n
"
,
__LINE__
,
total
);
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录