Commit e38f1267 authored by Berenger Bramas's avatar Berenger Bramas
Browse files

Add PBC rounding to the positions and add lock free array to protect the cells from race conditions

parent cba0515b
#ifndef LOCK_FREE_BOOL_ARRAY_HPP
#define LOCK_FREE_BOOL_ARRAY_HPP
#include <vector>
#include <memory>
class lock_free_bool_array{
std::vector<std::unique_ptr<long int>> keys;
public:
explicit lock_free_bool_array(const long int inNbKeys = 512){
keys.resize(inNbKeys);
for(std::unique_ptr<long int>& k : keys){
k.reset(new long int(0));
}
}
void lock(const int inKey){
volatile long int* k = keys[inKey%keys.size()].get();
long int res = 1;
int cpt = 0;
while(res == 1){
res = __sync_val_compare_and_swap(k, 0, res);
cpt++;
}
}
void unlock(const int inKey){
volatile long int* k = keys[inKey%keys.size()].get();
assert(k && *k);
(*k) = 0;
}
};
#endif
This diff is collapsed.
......@@ -15,7 +15,7 @@ class p2p_tree{
}
long int get_cell_coord_y_from_index(const long int index) const{
return (index - get_cell_coord_z_from_index(index)*(nb_cell_levels[IDX_X]*nb_cell_levels[IDX_Y]))
return (index % (nb_cell_levels[IDX_X]*nb_cell_levels[IDX_Y]))
/ nb_cell_levels[IDX_X];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment