Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
relibc
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
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
redox-os
relibc
Commits
84e5b412
Verified
Commit
84e5b412
authored
1 year ago
by
Jacob Lorentzon
Browse files
Options
Downloads
Patches
Plain Diff
Improve once test.
parent
d8bc60e0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!380
Replace pthreads-emb with a native implementation
Pipeline
#12082
failed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/pthread/once.c
+23
-38
23 additions, 38 deletions
tests/pthread/once.c
with
23 additions
and
38 deletions
tests/pthread/once.c
+
23
−
38
View file @
84e5b412
...
@@ -6,29 +6,26 @@
...
@@ -6,29 +6,26 @@
#include
<unistd.h>
#include
<unistd.h>
#include
"common.h"
#include
"common.h"
#include
"../test_helpers.h"
struct
once_data
{
_Thread_local
size_t
this_thread_count
=
0
;
size_t
count
;
};
_Thread_local
struct
once_data
once_data
=
{
0
};
#define COUNT 1024
#define COUNT 1024
#define THREADS 4
#define THREADS 4
void
constructor
()
{
static
void
constructor
(
void
)
{
once_data
.
count
+=
1
;
this_thread_count
++
;
}
}
struct
arg
{
struct
arg
{
pthread_barrier_t
*
barrier
;
pthread_barrier_t
*
barrier
;
pthread_once_t
*
onces
;
pthread_once_t
*
onces
;
int
status
;
size_t
count
;
size_t
count
;
size_t
index
;
size_t
index
;
};
};
void
*
routine
(
void
*
arg_raw
)
{
void
*
routine
(
void
*
arg_raw
)
{
int
status
;
struct
arg
*
arg
=
arg_raw
;
struct
arg
*
arg
=
arg_raw
;
if
(
arg
->
index
==
THREADS
-
1
)
{
if
(
arg
->
index
==
THREADS
-
1
)
{
...
@@ -37,21 +34,21 @@ void *routine(void *arg_raw) {
...
@@ -37,21 +34,21 @@ void *routine(void *arg_raw) {
printf
(
"spawned %zu
\n
"
,
arg
->
index
);
printf
(
"spawned %zu
\n
"
,
arg
->
index
);
}
}
int
wait_
status
=
pthread_barrier_wait
(
arg
->
barrier
);
status
=
pthread_barrier_wait
(
arg
->
barrier
);
printf
(
"waited %zu leader=%s
\n
"
,
arg
->
index
,
(
wait_
status
==
PTHREAD_BARRIER_SERIAL_THREAD
)
?
"true"
:
"false"
);
printf
(
"waited %zu leader=%s
\n
"
,
arg
->
index
,
(
status
==
PTHREAD_BARRIER_SERIAL_THREAD
)
?
"true"
:
"false"
);
if
(
wait_status
!=
PTHREAD_BARRIER_SERIAL_THREAD
&&
wait_status
!=
0
)
{
if
(
status
!=
PTHREAD_BARRIER_SERIAL_THREAD
)
{
ERROR_IF
(
pthread_barrier_wait
,
status
,
!=
0
);
return
NULL
;
return
NULL
;
}
}
for
(
size_t
i
=
0
;
i
<
COUNT
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
COUNT
;
i
++
)
{
if
((
arg
->
status
=
pthread_once
(
&
arg
->
onces
[
i
],
constructor
))
!=
0
)
{
status
=
pthread_once
(
&
arg
->
onces
[
i
],
constructor
);
return
NULL
;
ERROR_IF
(
pthread_once
,
status
,
!=
0
);
}
}
}
arg
->
count
=
once_data
.
count
;
arg
->
count
=
this_thread_
count
;
return
NULL
;
return
NULL
;
}
}
...
@@ -71,44 +68,32 @@ int main(void) {
...
@@ -71,44 +68,32 @@ int main(void) {
printf
(
"Barrier at %p, onces at %p
\n
"
,
&
barrier
,
onces
);
printf
(
"Barrier at %p, onces at %p
\n
"
,
&
barrier
,
onces
);
if
((
status
=
pthread_barrier_init
(
&
barrier
,
NULL
,
THREADS
))
!=
0
)
{
status
=
pthread_barrier_init
(
&
barrier
,
NULL
,
THREADS
);
return
fail
(
status
,
"barrier init"
);
ERROR_IF
(
pthread_barrier_init
,
status
,
!=
0
);
}
pthread_t
threads
[
THREADS
];
pthread_t
threads
[
THREADS
];
struct
arg
args
[
THREADS
];
struct
arg
args
[
THREADS
];
threads
[
0
]
=
pthread_self
();
for
(
size_t
i
=
0
;
i
<
THREADS
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
THREADS
;
i
++
)
{
args
[
i
]
=
(
struct
arg
){
.
barrier
=
&
barrier
,
.
onces
=
onces
,
.
status
=
0
,
.
count
=
0
,
.
index
=
i
};
args
[
i
]
=
(
struct
arg
){
.
barrier
=
&
barrier
,
.
onces
=
onces
,
.
count
=
0
,
.
index
=
i
};
printf
(
"spawning %zu
\n
"
,
i
);
printf
(
"spawning %zu
\n
"
,
i
);
if
(
i
==
0
)
{
status
=
pthread_create
(
&
threads
[
i
],
NULL
,
routine
,
&
args
[
i
]);
continue
;
ERROR_IF
(
pthread_create
,
status
,
!=
0
);
}
if
((
status
=
pthread_create
(
&
threads
[
i
],
NULL
,
routine
,
&
args
[
i
]))
!=
0
)
{
return
fail
(
status
,
"thread create"
);
}
}
}
routine
(
&
args
[
0
]);
size_t
total_count
=
0
;
size_t
total_count
=
0
;
for
(
size_t
i
=
0
;
i
<
THREADS
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
THREADS
;
i
++
)
{
if
(
i
!=
0
)
{
status
=
pthread_join
(
threads
[
i
],
NULL
);
if
((
status
=
pthread_join
(
threads
[
i
],
NULL
))
!=
0
)
{
ERROR_IF
(
pthread_join
,
status
,
!=
0
);
return
fail
(
status
,
"join"
);
}
}
if
(
args
[
i
].
status
!=
0
)
{
return
fail
(
args
[
i
].
status
,
"thread"
);
}
total_count
+=
args
[
i
].
count
;
total_count
+=
args
[
i
].
count
;
}
}
status
=
pthread_barrier_destroy
(
&
barrier
);
ERROR_IF
(
pthread_barrier_destroy
,
status
,
!=
0
);
assert
(
total_count
==
COUNT
);
assert
(
total_count
==
COUNT
);
return
EXIT_SUCCESS
;
return
EXIT_SUCCESS
;
...
...
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