Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
8b718937
Commit
8b718937
authored
7 years ago
by
Alexandre Abadie
Browse files
Options
Downloads
Patches
Plain Diff
tests/pthread_tls: some cleanup
parent
c1a08451
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/pthread_tls/main.c
+32
-14
32 additions, 14 deletions
tests/pthread_tls/main.c
with
32 additions
and
14 deletions
tests/pthread_tls/main.c
+
32
−
14
View file @
8b718937
...
@@ -30,7 +30,8 @@ void *run(void *parameter)
...
@@ -30,7 +30,8 @@ void *run(void *parameter)
(
void
)
parameter
;
(
void
)
parameter
;
printf
(
"
\n
-= TEST 1 - create %d tls with sequencial values 0...%d =-
\n
"
,
NUMBER_OF_TLS
,
NUMBER_OF_TLS
-
1
);
printf
(
"
\n
-= TEST 1 - create %d tls with sequencial values 0...%d =-
\n
"
,
NUMBER_OF_TLS
,
NUMBER_OF_TLS
-
1
);
for
(
int
i
=
0
;
i
<
NUMBER_OF_TLS
;
++
i
)
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_TLS
;
++
i
)
{
aTLS_values
[
i
]
=
i
;
aTLS_values
[
i
]
=
i
;
...
@@ -44,11 +45,12 @@ void *run(void *parameter)
...
@@ -44,11 +45,12 @@ void *run(void *parameter)
aTLS_values
[
i
]
++
;
aTLS_values
[
i
]
++
;
}
}
printf
(
"pick deliberate storage (key[3]:%d) and change the value
\n
"
,
(
int
)
aKeys
[
3
]);
printf
(
"pick deliberate storage (key[3]:%d) and change the value
\n
"
,
(
int
)
aKeys
[
3
]);
void
*
val
=
pthread_getspecific
(
aKeys
[
3
]);
void
*
val
=
pthread_getspecific
(
aKeys
[
3
]);
*
((
int
*
)
val
)
=
42
;
*
((
int
*
)
val
)
=
42
;
p
rintf
(
"show tls values:
\n
"
);
p
uts
(
"show tls values:"
);
for
(
int
i
=
0
;
i
<
NUMBER_OF_TLS
;
++
i
)
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_TLS
;
++
i
)
{
void
*
val
=
pthread_getspecific
(
aKeys
[
i
]);
void
*
val
=
pthread_getspecific
(
aKeys
[
i
]);
...
@@ -56,10 +58,11 @@ void *run(void *parameter)
...
@@ -56,10 +58,11 @@ void *run(void *parameter)
printf
(
"key[%d]: %d, val: %d
\n
"
,
i
,
(
int
)
aKeys
[
i
],
x
);
printf
(
"key[%d]: %d, val: %d
\n
"
,
i
,
(
int
)
aKeys
[
i
],
x
);
}
}
printf
(
"
\n
-= TEST 2 - delete deliberate key (key[5]:%d) =-
\n
"
,
(
int
)
aKeys
[
5
]);
printf
(
"
\n
-= TEST 2 - delete deliberate key (key[5]:%d) =-
\n
"
,
(
int
)
aKeys
[
5
]);
pthread_key_delete
(
aKeys
[
5
]);
pthread_key_delete
(
aKeys
[
5
]);
p
rintf
(
"show tls values:
\n
"
);
p
uts
(
"show tls values:"
);
for
(
int
i
=
0
;
i
<
NUMBER_OF_TLS
;
++
i
)
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_TLS
;
++
i
)
{
void
*
val
=
pthread_getspecific
(
aKeys
[
i
]);
void
*
val
=
pthread_getspecific
(
aKeys
[
i
]);
...
@@ -70,7 +73,8 @@ void *run(void *parameter)
...
@@ -70,7 +73,8 @@ void *run(void *parameter)
}
}
}
}
printf
(
"
\n
-= TEST 3 - create new tls =-
\n
"
);
puts
(
""
);
puts
(
"-= TEST 3 - create new tls =-"
);
int
new_val
=
99
;
int
new_val
=
99
;
pthread_key_t
new_key
;
pthread_key_t
new_key
;
pthread_key_create
(
&
new_key
,
NULL
);
pthread_key_create
(
&
new_key
,
NULL
);
...
@@ -88,7 +92,8 @@ void *run(void *parameter)
...
@@ -88,7 +92,8 @@ void *run(void *parameter)
}
}
}
}
printf
(
"
\n
-= TEST 4 - delete all keys =-
\n
"
);
puts
(
""
);
puts
(
"-= TEST 4 - delete all keys =-"
);
for
(
int
i
=
0
;
i
<
NUMBER_OF_TLS
;
++
i
)
{
for
(
int
i
=
0
;
i
<
NUMBER_OF_TLS
;
++
i
)
{
pthread_key_delete
(
aKeys
[
i
]);
pthread_key_delete
(
aKeys
[
i
]);
...
@@ -105,17 +110,22 @@ void *run(void *parameter)
...
@@ -105,17 +110,22 @@ void *run(void *parameter)
}
}
}
}
printf
(
"
\n
-= TEST 5 - try delete non-existing key =-
\n
"
);
puts
(
""
);
printf
(
"try to delete returns: %d
\n
"
,
pthread_key_delete
((
pthread_key_t
)
99
));
puts
(
"-= TEST 5 - try delete non-existing key =-"
);
printf
(
"try to delete returns: %d
\n
"
,
pthread_key_delete
((
pthread_key_t
)
99
));
puts
(
""
);
puts
(
"-= TEST 6 - add key and delete without a tls =-"
);
printf
(
"
\n
-= TEST 6 - add key and delete without a tls =-
\n
"
);
pthread_key_create
(
&
new_key
,
NULL
);
pthread_key_create
(
&
new_key
,
NULL
);
printf
(
"crated key: %d
\n
"
,
(
int
)
new_key
);
printf
(
"cr
e
ated key: %d
\n
"
,
(
int
)
new_key
);
printf
(
"try to delete returns: %d
\n
"
,
pthread_key_delete
(
new_key
));
printf
(
"try to delete returns: %d
\n
"
,
pthread_key_delete
(
new_key
));
printf
(
"
\n
-= TEST 7 - add key without tls =-
\n
"
);
puts
(
""
);
puts
(
"-= TEST 7 - add key without tls =-"
);
pthread_key_create
(
&
new_key
,
NULL
);
pthread_key_create
(
&
new_key
,
NULL
);
printf
(
"crated key: %d
\n
"
,
(
int
)
new_key
);
printf
(
"cr
e
ated key: %d
\n
"
,
(
int
)
new_key
);
void
*
test_7_val
=
pthread_getspecific
(
new_key
);
void
*
test_7_val
=
pthread_getspecific
(
new_key
);
printf
(
"test_7_val: %p
\n
"
,
test_7_val
);
printf
(
"test_7_val: %p
\n
"
,
test_7_val
);
...
@@ -125,6 +135,7 @@ void *run(void *parameter)
...
@@ -125,6 +135,7 @@ void *run(void *parameter)
int
main
(
void
)
int
main
(
void
)
{
{
puts
(
"START"
);
pthread_t
th_id
;
pthread_t
th_id
;
pthread_attr_t
th_attr
;
pthread_attr_t
th_attr
;
...
@@ -133,6 +144,13 @@ int main(void)
...
@@ -133,6 +144,13 @@ int main(void)
size_t
res
;
size_t
res
;
pthread_join
(
th_id
,
(
void
**
)
&
res
);
pthread_join
(
th_id
,
(
void
**
)
&
res
);
puts
(
"
\n
tls tests finished."
);
puts
(
"tls tests finished."
);
if
(
res
==
0
)
{
puts
(
"SUCCESS"
);
}
else
{
puts
(
"FAILURE"
);
}
return
0
;
return
0
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment