Commit 053ca488 by Christian Kern

Worked on review comments for ticket #523

parent a023d6e4
...@@ -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());
......
...@@ -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 poolSize); IntObjectTestPool(unsigned int pool_size);
~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* objectPointer); void Release(int* object_pointer);
}; };
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 nThreads; int n_threads;
embb::base::Function<void, int*> deletePointerCallback; 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> currentMaster; 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 guardsPerThreadCount; unsigned int guards_per_phread_count_;
unsigned int guaranteedCapacityPool; unsigned int guaranteed_capacity_pool_;
unsigned int poolSizeUsingHazardPointer; 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*>* sharedGuarded; 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*>* sharedAllocated; 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment