Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
974e4077
Commit
974e4077
authored
Nov 11, 2014
by
Joseph Noir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bugs in join and operator=
parent
4e1aff42
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
25 deletions
+45
-25
libcaf_core/caf/thread.hpp
libcaf_core/caf/thread.hpp
+18
-12
libcaf_core/src/thread.cpp
libcaf_core/src/thread.cpp
+27
-13
No files found.
libcaf_core/caf/thread.hpp
View file @
974e4077
...
...
@@ -32,8 +32,9 @@
#include <type_traits>
extern
"C"
{
#include
<time.h>
#include
"time.h"
#include "thread.h"
#include "kernel_internal.h"
}
#include "caf/mutex.hpp"
...
...
@@ -153,9 +154,12 @@ class thread {
~
thread
();
thread
(
const
thread
&
)
=
delete
;
inline
thread
(
thread
&&
t
)
noexcept
:
m_handle
{
t
.
m_handle
}
{
inline
thread
(
thread
&&
t
)
noexcept
:
m_handle
{
t
.
m_handle
},
m_data
{
t
.
m_data
}
{
t
.
m_handle
=
thread_uninitialized
;
std
::
swap
(
m_data
,
t
.
m_data
);
//std::swap(m_data, t.m_data);
t
.
m_data
.
reset
();
}
thread
&
operator
=
(
const
thread
&
)
=
delete
;
thread
&
operator
=
(
thread
&&
)
noexcept
;
...
...
@@ -165,7 +169,9 @@ class thread {
std
::
swap
(
m_handle
,
t
.
m_handle
);
}
inline
bool
joinable
()
const
noexcept
{
return
false
;
}
inline
bool
joinable
()
const
noexcept
{
return
m_handle
!=
thread_uninitialized
;
}
void
join
();
void
detach
();
inline
id
get_id
()
const
noexcept
{
return
m_handle
;
}
...
...
@@ -186,17 +192,16 @@ void* thread_proxy(void* vp) {
data
->
deref
();
// remove count incremented in constructor
auto
indices
=
detail
::
get_right_indices
<
caf
::
detail
::
tl_size
<
F
>::
value
-
2
>
(
*
p
);
detail
::
apply_args
(
std
::
get
<
1
>
(
*
p
),
indices
,
*
p
);
try
{
detail
::
apply_args
(
std
::
get
<
1
>
(
*
p
),
indices
,
*
p
);
}
catch
(...)
{
// nop
}
if
(
data
->
joining_thread
!=
thread_uninitialized
)
{
thread_wakeup
(
data
->
joining_thread
);
}
//sched_task_exit();
//dINT();
//sched_threads[sched_active_pid] = NULL;
--
sched_num_threads
;
//sched_set_status((tcb_t *)sched_active_thread, STATUS_STOPPED);
//sched_active_thread = NULL;
//cpu_switch_context_exit();
// some riot cleanup code
sched_task_exit
();
return
nullptr
;
}
...
...
@@ -230,6 +235,7 @@ inline thread& thread::operator=(thread&& other) noexcept {
}
m_handle
=
other
.
m_handle
;
other
.
m_handle
=
thread_uninitialized
;
std
::
swap
(
m_data
,
other
.
m_data
);
return
*
this
;
}
...
...
libcaf_core/src/thread.cpp
View file @
974e4077
...
...
@@ -2,24 +2,37 @@
#include <time.h>
#include <cerrno>
#include <system_error>
#include "caf/thread.hpp"
using
namespace
std
;
namespace
caf
{
thread
::~
thread
()
{
// not needed, as our thread is always detachted
if
(
m_handle
!=
thread_uninitialized
)
{
throw
std
::
runtime_error
(
"Thread is not joined or detached!"
);
if
(
joinable
())
{
terminate
();
}
}
void
thread
::
join
()
{
if
(
m_handle
!=
thread_uninitialized
)
{
m_data
->
joining_thread
=
sched_active_pid
;
if
(
this
->
get_id
()
==
this_thread
::
get_id
())
{
throw
system_error
(
make_error_code
(
errc
::
resource_deadlock_would_occur
),
"Joining this leads to a deadlock."
);
}
if
(
joinable
())
{
m_handle
=
thread_uninitialized
;
thread_sleep
();
auto
status
=
thread_getstatus
(
m_handle
);
if
(
status
!=
STATUS_NOT_FOUND
&&
status
!=
STATUS_STOPPED
)
{
m_data
->
joining_thread
=
sched_active_pid
;
thread_sleep
();
}
}
else
{
throw
system_error
(
make_error_code
(
errc
::
invalid_argument
),
"Can not join an unjoinable thread."
);
}
// missing: no_such_process system error
}
void
thread
::
join
()
{
...
...
@@ -27,33 +40,34 @@ void thread::join() {
}
void
thread
::
detach
()
{
if
(
m_handle
!=
thread_uninitialized
)
{
if
(
joinable
()
)
{
m_handle
=
thread_uninitialized
;
}
else
{
throw
system_error
(
make_error_code
(
errc
::
invalid_argument
),
"Can not detach an unjoinable thread."
);
}
}
unsigned
thread
::
hardware_concurrency
()
noexcept
{
// embedded systems often do not have more cores
// RIOT does currently not ofter these informations
return
1
;
}
namespace
this_thread
{
void
sleep_for
(
const
std
::
chrono
::
nanoseconds
&
ns
)
{
using
namespace
std
::
chrono
;
void
sleep_for
(
const
chrono
::
nanoseconds
&
ns
)
{
using
namespace
chrono
;
if
(
ns
>
nanoseconds
::
zero
())
{
seconds
s
=
duration_cast
<
seconds
>
(
ns
);
timespec
ts
;
using
ts_sec
=
decltype
(
ts
.
tv_sec
);
// typedef decltype(ts.tv_sec) ts_sec;
constexpr
ts_sec
ts_sec_max
=
std
::
numeric_limits
<
ts_sec
>::
max
();
constexpr
ts_sec
ts_sec_max
=
numeric_limits
<
ts_sec
>::
max
();
if
(
s
.
count
()
<
ts_sec_max
)
{
ts
.
tv_sec
=
static_cast
<
ts_sec
>
(
s
.
count
());
ts
.
tv_nsec
=
static_cast
<
decltype
(
ts
.
tv_nsec
)
>
((
ns
-
s
).
count
());
}
else
{
ts
.
tv_sec
=
ts_sec_max
;
ts
.
tv_nsec
=
std
::
giga
::
num
-
1
;
ts
.
tv_nsec
=
giga
::
num
-
1
;
}
while
(
nanosleep
(
&
ts
,
&
ts
)
==
-
1
&&
errno
==
EINTR
)
{
;
}
}
...
...
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