Skip to content

Commit

Permalink
Cleanup and some doc
Browse files Browse the repository at this point in the history
  • Loading branch information
wichtounet committed Jun 2, 2012
1 parent 4c1e63c commit ce3339b
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 439 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Expand Up @@ -15,8 +15,8 @@ if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -march=native -funroll-loops -pthread -std=c++0x -pedantic -Wall -Wextra -Wno-long-long")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pthread -std=c++0x -pedantic -Wall -Wextra -Wno-long-long")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -march=native -funroll-loops -pthread -std=c++0x -pedantic -Wall -Wextra -Wno-long-long")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pthread -std=c++0x -pedantic -Wall -Wextra -Wno-long-long")
endif()

set(EXECUTABLE_OUTPUT_PATH bin)
Expand Down
51 changes: 44 additions & 7 deletions include/HazardManager.hpp
Expand Up @@ -14,6 +14,13 @@ extern __thread unsigned int thread_num;
#include <algorithm>
#include <iostream>

/*!
* A manager for Hazard Pointers manipulation.
* \param Node The type of node to manage.
* \param Threads The maximum number of threads.
* \param Size The number of hazard pointers per thread.
* \param Prefill The number of nodes to precreate in the queue.
*/
template<typename Node, unsigned int Threads, unsigned int Size = 2, unsigned int Prefill = 50>
class HazardManager {
public:
Expand All @@ -23,17 +30,52 @@ class HazardManager {
HazardManager(const HazardManager& rhs) = delete;
HazardManager& operator=(const HazardManager& rhs) = delete;

/* Manage nodes */
/*!
* Release the node.
*/
void releaseNode(Node* node);

/*!
* \brief Release the node by checking first if it is not already in the queue.
* This method can be slow depending on the number of nodes already released.
* \param node The node to release.
*/
void safe_release_node(Node* node);

/*!
* Return a free node for the calling thread.
* \return A free node
*/
Node* getFreeNode();

/* Manage references */
/*!
* Publish a reference to the given Node using ith Hazard Pointer.
* \param node The node to be published
* \param i The index of the pointer to use.
*/
void publish(Node* node, unsigned int i);

/*!
* Release the ith reference of the calling thread.
* \param i The reference index.
*/
void release(unsigned int i);

/*!
* Release all the hazard points of the calling thread.
*/
void releaseAll();

/*!
* Return a reference to the internal free queue of the given thread.
* \return A reference to the free queue of the given thread.
*/
std::list<Node*>& direct_free(unsigned int t);

/*!
* Return a reference to the internal local queue of the given thread.
* \return A reference to the local queue of the given thread.
*/
std::list<Node*>& direct_local(unsigned int t);

private:
Expand Down Expand Up @@ -136,11 +178,6 @@ void HazardManager<Node, Threads, Size, Prefill>::releaseNode(Node* node){
//If the node is null, we have nothing to do
if(node){
#ifdef DEBUG
/*if(std::find(LocalQueues.at(thread_num).begin(), LocalQueues.at(thread_num).end(), node) != LocalQueues.at(thread_num).end()){
std::cout << node << std::endl;
return;
}*/

//Add the node to the localqueue
LocalQueues.at(thread_num).push_back(node);
#else
Expand Down
3 changes: 3 additions & 0 deletions include/Results.hpp
Expand Up @@ -9,6 +9,9 @@ typedef std::map<std::string, std::vector<std::vector<unsigned long>>> results_m
typedef std::map<std::string, std::vector<unsigned long>> stats_map;
typedef std::map<std::string, int> currents_map;

/*!
* Simple class to store the results of a bench and write them to a file.
*/
class Results {
public:
void start(const std::string& name);
Expand Down
7 changes: 7 additions & 0 deletions include/Utils.hpp
@@ -1,6 +1,13 @@
#ifndef UTILS
#define UTILS

/*!
* Compare and Swap a pointer.
* \param ptr The pointer to swap.
* \param old The expected value.
* \param value The new value to set.
* \return true if the CAS suceeded, otherwise false.
*/
template<typename T>
bool inline CASPTR(T** ptr, T* old, T* value){
return __sync_bool_compare_and_swap(ptr, old, value);
Expand Down
3 changes: 3 additions & 0 deletions include/bench.hpp
@@ -1,6 +1,9 @@
#ifndef BENCH_TREE
#define BENCH_TREE

/*!
* Bench the different structures
*/
void bench();

#endif
7 changes: 6 additions & 1 deletion include/file_distribution.hpp
Expand Up @@ -4,6 +4,11 @@
#include <iostream>
#include <fstream>

/*!
* \brief A sample random distribution that takes its value in a file.
* All the values of the file will be loaded in memory at construction time of the distribution.
* \param Type The type of value contained in the file.
*/
template<class Type = int>
class file_distribution {
public:
Expand All @@ -19,7 +24,7 @@ class file_distribution {
std::ifstream stream(file.c_str());

if(!stream){
std::cout << "Unable to open the file " << file << std::endl;
throw "Unable to open the file " + file;
}

for(unsigned int i = 0; i < size; ++i){
Expand Down
9 changes: 9 additions & 0 deletions include/hash.hpp
@@ -1,9 +1,18 @@
#ifndef HASH
#define HASH

/*!
* Hash the given value depending on its type.
* This function is made to be template-specialized.
* \param T The type of value to hash.
* \param value The value to hash.
*/
template<typename T>
int hash(T value);

/*!
* Specialization of hash for the int type.
*/
template<>
inline int hash<int>(int value){
return value;
Expand Down
3 changes: 3 additions & 0 deletions include/test.hpp
@@ -1,6 +1,9 @@
#ifndef TEST_TREES
#define TEST_TREES

/*!
* Launch all the tests.
*/
void test();

#endif
146 changes: 0 additions & 146 deletions include/zipf.hpp

This file was deleted.

0 comments on commit ce3339b

Please sign in to comment.