Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
053ca488
authored
Oct 21, 2015
by
Christian Kern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Worked on review comments for ticket #523
parent
a023d6e4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
55 deletions
+58
-55
base_c/src/internal/thread_index.c
+12
-6
containers_cpp/include/embb/containers/internal/hazard_pointer-inl.h
+0
-0
containers_cpp/include/embb/containers/internal/hazard_pointer.h
+0
-0
containers_cpp/test/hazard_pointer_test.cc
+0
-0
containers_cpp/test/hazard_pointer_test.h
+46
-49
No files found.
base_c/src/internal/thread_index.c
View file @
053ca488
...
@@ -128,13 +128,19 @@ void embb_internal_thread_index_set_max(unsigned int max) {
...
@@ -128,13 +128,19 @@ void embb_internal_thread_index_set_max(unsigned int max) {
*
embb_max_number_thread_indices
()
=
max
;
*
embb_max_number_thread_indices
()
=
max
;
}
}
/**
* \pre the calling thread is the only active thread
*
* \post the thread indices count and calling thread index is reset
*/
void
embb_internal_thread_index_reset
()
{
void
embb_internal_thread_index_reset
()
{
// This function is only called in tests, usually when all other threads
/** This function is only called in tests, usually when all other threads
// except the main thread have terminated. However, the main thread still has
* except the main thread have terminated. However, the main thread still has
// potentially still stored its old index value in its thread local storage,
* potentially stored its old index value in its thread local storage,
// which might be assigned additionally to another thread (as the counter is
* which might be assigned additionally to another thread (as the counter is
// reset), which may lead to hard to detect bugs. Therefore, reset the thread
* reset), which may lead to hard to detect bugs. Therefore, reset the thread
// local thread id here.
* local thread id here.
*/
embb_internal_thread_index_var
=
UINT_MAX
;
embb_internal_thread_index_var
=
UINT_MAX
;
embb_counter_init
(
embb_thread_index_counter
());
embb_counter_init
(
embb_thread_index_counter
());
...
...
containers_cpp/include/embb/containers/internal/hazard_pointer-inl.h
View file @
053ca488
This diff is collapsed.
Click to expand it.
containers_cpp/include/embb/containers/internal/hazard_pointer.h
View file @
053ca488
This diff is collapsed.
Click to expand it.
containers_cpp/test/hazard_pointer_test.cc
View file @
053ca488
This diff is collapsed.
Click to expand it.
containers_cpp/test/hazard_pointer_test.h
View file @
053ca488
...
@@ -36,7 +36,6 @@
...
@@ -36,7 +36,6 @@
namespace
embb
{
namespace
embb
{
namespace
containers
{
namespace
containers
{
namespace
test
{
namespace
test
{
/**
/**
* @brief a very simple wait-free object pool implementation to have tests
* @brief a very simple wait-free object pool implementation to have tests
* being independent of the EMBB object pool implementation.
* being independent of the EMBB object pool implementation.
...
@@ -51,7 +50,7 @@ class IntObjectTestPool {
...
@@ -51,7 +50,7 @@ class IntObjectTestPool {
static
const
int
FREE_MARKER
=
0
;
static
const
int
FREE_MARKER
=
0
;
unsigned
int
poolSize
;
unsigned
int
poolSize
;
IntObjectTestPool
(
unsigned
int
pool
S
ize
);
IntObjectTestPool
(
unsigned
int
pool
_s
ize
);
~
IntObjectTestPool
();
~
IntObjectTestPool
();
...
@@ -67,27 +66,10 @@ class IntObjectTestPool {
...
@@ -67,27 +66,10 @@ class IntObjectTestPool {
*
*
* @param objectPointer the object to be freed
* @param objectPointer the object to be freed
*/
*/
void
Release
(
int
*
object
P
ointer
);
void
Release
(
int
*
object
_p
ointer
);
};
};
class
HazardPointerTest
:
public
partest
::
TestCase
{
class
HazardPointerTest
:
public
partest
::
TestCase
{
private
:
embb
::
base
::
Function
<
void
,
embb
::
base
::
Atomic
<
int
>*>
deletePointerCallback
;
//used to allocate random stuff, we will just use the pointers, not the
//contents
embb
::
containers
::
ObjectPool
<
embb
::
base
::
Atomic
<
int
>
>*
objectPool
;
//used to move pointer between threads
embb
::
containers
::
LockFreeStack
<
embb
::
base
::
Atomic
<
int
>*
>*
stack
;
embb
::
base
::
Mutex
vectorMutex
;
embb
::
containers
::
internal
::
HazardPointer
<
embb
::
base
::
Atomic
<
int
>*>*
hazardPointer
;
std
::
vector
<
embb
::
base
::
Atomic
<
int
>*
>
deletedVector
;
int
nThreads
;
int
nElementsPerThread
;
int
nElements
;
public
:
public
:
/**
/**
* Adds test methods.
* Adds test methods.
...
@@ -96,56 +78,71 @@ class HazardPointerTest : public partest::TestCase {
...
@@ -96,56 +78,71 @@ class HazardPointerTest : public partest::TestCase {
void
HazardPointerTest1Pre
();
void
HazardPointerTest1Pre
();
void
HazardPointerTest1Post
();
void
HazardPointerTest1Post
();
void
HazardPointerTest1ThreadMethod
();
void
HazardPointerTest1ThreadMethod
();
void
DeletePointerCallback
(
embb
::
base
::
Atomic
<
int
>*
toDelete
);
void
DeletePointerCallback
(
embb
::
base
::
Atomic
<
int
>*
to_delete
);
private
:
embb
::
base
::
Function
<
void
,
embb
::
base
::
Atomic
<
int
>*>
delete_pointer_callback_
;
//used to allocate random stuff, we will just use the pointers, not the
//contents
embb
::
containers
::
ObjectPool
<
embb
::
base
::
Atomic
<
int
>
>*
object_pool_
;
//used to move pointer between threads
embb
::
containers
::
LockFreeStack
<
embb
::
base
::
Atomic
<
int
>*
>*
stack_
;
embb
::
base
::
Mutex
vector_mutex_
;
embb
::
containers
::
internal
::
HazardPointer
<
embb
::
base
::
Atomic
<
int
>*>*
hazard_pointer_
;
std
::
vector
<
embb
::
base
::
Atomic
<
int
>*
>
deleted_vector_
;
int
n_threads_
;
int
n_elements_per_thread_
;
int
n_elements_
;
};
};
class
HazardPointerTest2
:
public
partest
::
TestCase
{
class
HazardPointerTest2
:
public
partest
::
TestCase
{
public
:
void
DeletePointerCallback
(
int
*
to_delete
);
bool
SetRelativeGuards
();
void
HazardPointerTest2Master
();
void
HazardPointerTest2Slave
();
void
HazardPointerTest2Pre
();
void
HazardPointerTest2Post
();
void
HazardPointerTest2ThreadMethod
();
HazardPointerTest2
();
private
:
private
:
// number of threads, participating in that test
// number of threads, participating in that test
int
n
T
hreads
;
int
n
_t
hreads
;
embb
::
base
::
Function
<
void
,
int
*>
delete
PointerCallback
;
embb
::
base
::
Function
<
void
,
int
*>
delete
_pointer_callback_
;
// the thread id of the master
// the thread id of the master
embb
::
base
::
Atomic
<
unsigned
int
>
current
Master
;
embb
::
base
::
Atomic
<
unsigned
int
>
current
_master_
;
// variables, to synchronize threads. At each point in time, one master,
// variables, to synchronize threads. At each point in time, one master,
// the master changes each round until each thread was assigned master once.
// the master changes each round until each thread was assigned master once.
embb
::
base
::
Atomic
<
int
>
sync1
;
embb
::
base
::
Atomic
<
int
>
sync1
_
;
embb
::
base
::
Atomic
<
unsigned
int
>
sync2
;
embb
::
base
::
Atomic
<
unsigned
int
>
sync2
_
;
unsigned
int
guards
PerThreadCount
;
unsigned
int
guards
_per_phread_count_
;
unsigned
int
guaranteed
CapacityPool
;
unsigned
int
guaranteed
_capacity_pool_
;
unsigned
int
pool
SizeUsingHazardPointer
;
unsigned
int
pool
_size_using_hazard_pointer_
;
// The threads write here, if they guarded an object successfully. Used to
// The threads write here, if they guarded an object successfully. Used to
// determine when all allocated objects were guarded successfully.
// determine when all allocated objects were guarded successfully.
embb
::
base
::
Atomic
<
int
*>*
shared
Guarded
;
embb
::
base
::
Atomic
<
int
*>*
shared
_guarded_
;
// This array is used by the master, to communicate and share what he has
// This array is used by the master, to communicate and share what he has
// allocated with the slaves.
// allocated with the slaves.
embb
::
base
::
Atomic
<
int
*>*
shared
Allocated
;
embb
::
base
::
Atomic
<
int
*>*
shared
_allocated_
;
// Reference to the object pool
// Reference to the object pool
IntObjectTestPool
*
testPool
;
IntObjectTestPool
*
test_pool_
;
embb
::
containers
::
internal
::
HazardPointer
<
int
*>*
hazardPointer
;
static
const
int
finishMarker
=
-
1
;
public
:
embb
::
containers
::
internal
::
HazardPointer
<
int
*>*
hazard_pointer_
;
void
DeletePointerCallback
(
int
*
toDelete
);
static
const
int
FINISH_MARKER
=
-
1
;
bool
SetRelativeGuards
();
void
HazardPointerTest2Master
();
void
HazardPointerTest2Slave
();
void
HazardPointerTest2Pre
();
void
HazardPointerTest2Post
();
void
HazardPointerTest2ThreadMethod
();
HazardPointerTest2
();
};
};
}
// namespace test
}
// namespace test
}
// namespace containers
}
// namespace containers
}
// namespace embb
}
// namespace embb
...
...
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