Commit 053ca488 by Christian Kern

Worked on review comments for ticket #523

parent a023d6e4
......@@ -128,14 +128,20 @@ void embb_internal_thread_index_set_max(unsigned int 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() {
// This function is only called in tests, usually when all other threads
// except the main thread have terminated. However, the main thread still has
// potentially still stored its old index value in its thread local storage,
// 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
// local thread id here.
/** This function is only called in tests, usually when all other threads
* except the main thread have terminated. However, the main thread still has
* potentially stored its old index value in its thread local storage,
* 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
* local thread id here.
*/
embb_internal_thread_index_var = UINT_MAX;
embb_counter_init(embb_thread_index_counter());
}
}
\ No newline at end of file
......@@ -36,7 +36,6 @@
namespace embb {
namespace containers {
namespace test {
/**
* @brief a very simple wait-free object pool implementation to have tests
* being independent of the EMBB object pool implementation.
......@@ -51,7 +50,7 @@ class IntObjectTestPool {
static const int FREE_MARKER = 0;
unsigned int poolSize;
IntObjectTestPool(unsigned int poolSize);
IntObjectTestPool(unsigned int pool_size);
~IntObjectTestPool();
......@@ -67,27 +66,10 @@ class IntObjectTestPool {
*
* @param objectPointer the object to be freed
*/
void Release(int* objectPointer);
void Release(int* object_pointer);
};
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:
/**
* Adds test methods.
......@@ -96,56 +78,71 @@ class HazardPointerTest : public partest::TestCase {
void HazardPointerTest1Pre();
void HazardPointerTest1Post();
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 {
public:
void DeletePointerCallback(int* to_delete);
bool SetRelativeGuards();
void HazardPointerTest2Master();
void HazardPointerTest2Slave();
void HazardPointerTest2Pre();
void HazardPointerTest2Post();
void HazardPointerTest2ThreadMethod();
HazardPointerTest2();
private:
// 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
embb::base::Atomic<unsigned int> currentMaster;
embb::base::Atomic<unsigned int> current_master_;
// variables, to synchronize threads. At each point in time, one master,
// the master changes each round until each thread was assigned master once.
embb::base::Atomic<int> sync1;
embb::base::Atomic<unsigned int> sync2;
embb::base::Atomic<int> sync1_;
embb::base::Atomic<unsigned int> sync2_;
unsigned int guardsPerThreadCount;
unsigned int guaranteedCapacityPool;
unsigned int poolSizeUsingHazardPointer;
unsigned int guards_per_phread_count_;
unsigned int guaranteed_capacity_pool_;
unsigned int pool_size_using_hazard_pointer_;
// The threads write here, if they guarded an object successfully. Used to
// 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
// allocated with the slaves.
embb::base::Atomic<int*>* sharedAllocated;
embb::base::Atomic<int*>* shared_allocated_;
// Reference to the object pool
IntObjectTestPool* testPool;
embb::containers::internal::HazardPointer<int*>* hazardPointer;
static const int finishMarker = -1;
IntObjectTestPool* test_pool_;
public:
void DeletePointerCallback(int* toDelete);
bool SetRelativeGuards();
void HazardPointerTest2Master();
void HazardPointerTest2Slave();
void HazardPointerTest2Pre();
void HazardPointerTest2Post();
void HazardPointerTest2ThreadMethod();
HazardPointerTest2();
embb::containers::internal::HazardPointer<int*>* hazard_pointer_;
static const int FINISH_MARKER = -1;
};
} // namespace test
} // namespace containers
} // 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