Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bbguimaraes
codex
Commits
a39cabc2
Commit
a39cabc2
authored
Oct 06, 2021
by
bbguimaraes
Browse files
wip
parent
0e1fff5c
Changes
3
Hide whitespace changes
Inline
Side-by-side
thread/thread3.c
View file @
a39cabc2
...
...
@@ -25,20 +25,20 @@ static const u64 sleep_dur_ns = 1000 * 1000;
static
bool
queue3_push
(
struct
queue3
*
q
,
struct
task
t
)
{
const
size_t
w
=
(
q
->
w
+
1
)
%
q
->
size
;
while
(
atomic_load
(
&
q
->
r
)
==
w
)
while
(
atomic_load
_explicit
(
&
q
->
r
,
memory_order_acquire
)
==
w
)
if
(
!
sleep_ns
(
sleep_dur_ns
))
return
false
;
q
->
tasks
[
q
->
w
]
=
t
;
atomic_store
(
&
q
->
w
,
w
);
atomic_store
_explicit
(
&
q
->
w
,
w
,
memory_order_release
);
return
true
;
}
static
bool
queue3_pop
(
struct
queue3
*
q
,
struct
task
*
t
)
{
while
(
atomic_load
(
&
q
->
w
)
==
q
->
r
)
while
(
atomic_load
_explicit
(
&
q
->
w
,
memory_order_acquire
)
==
q
->
r
)
if
(
!
sleep_ns
(
sleep_dur_ns
))
false
;
const
struct
task
ret
=
q
->
tasks
[
q
->
r
];
atomic_store
(
&
q
->
r
,
(
q
->
r
+
1
)
%
q
->
size
);
atomic_store
_explicit
(
&
q
->
r
,
(
q
->
r
+
1
)
%
q
->
size
,
memory_order_release
);
*
t
=
ret
;
return
true
;
}
...
...
util/def.h
0 → 100644
View file @
a39cabc2
#ifndef CODEX_UTIL_DEF_H
#define CODEX_UTIL_DEF_H
#ifdef __cplusplus
#include <cstdint>
using
u64
=
std
::
uint64_t
;
#else
#include <stdint.h>
typedef
uint64_t
u64
;
#endif
#endif
util/util.hpp
0 → 100644
View file @
a39cabc2
#ifndef CODEX_UTIL_UTIL_H
#define CODEX_UTIL_UTIL_H
namespace
codex
::
literals
{
inline
constexpr
std
::
size_t
operator
""
_zu
(
unsigned
long
long
int
i
)
{
return
{
i
};
}
}
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment