Commit 92e093d7 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Unified the atomic calls everywhere using the defined macros

parent a4f97e08
......@@ -269,7 +269,7 @@ int cell_locktree(struct cell *c) {
/* Undo the holds up to finger. */
for (struct cell *finger2 = c->parent; finger2 != finger;
finger2 = finger2->parent)
__sync_fetch_and_sub(&finger2->hold, 1);
atomic_dec(&finger2->hold);
/* Unlock this cell. */
if (lock_unlock(&c->lock) != 0) error("Failed to unlock cell.");
......@@ -309,7 +309,7 @@ int cell_glocktree(struct cell *c) {
if (lock_trylock(&finger->glock) != 0) break;
/* Increment the hold. */
__sync_fetch_and_add(&finger->ghold, 1);
atomic_inc(&finger->ghold);
/* Unlock the cell. */
if (lock_unlock(&finger->glock) != 0) error("Failed to unlock cell.");
......@@ -327,7 +327,7 @@ int cell_glocktree(struct cell *c) {
/* Undo the holds up to finger. */
for (struct cell *finger2 = c->parent; finger2 != finger;
finger2 = finger2->parent)
__sync_fetch_and_sub(&finger2->ghold, 1);
atomic_dec(&finger2->ghold);
/* Unlock this cell. */
if (lock_unlock(&c->glock) != 0) error("Failed to unlock cell.");
......@@ -353,7 +353,7 @@ void cell_unlocktree(struct cell *c) {
/* Climb up the tree and unhold the parents. */
for (struct cell *finger = c->parent; finger != NULL; finger = finger->parent)
__sync_fetch_and_sub(&finger->hold, 1);
atomic_dec(&finger->hold);
TIMER_TOC(timer_locktree);
}
......@@ -367,7 +367,7 @@ void cell_gunlocktree(struct cell *c) {
/* Climb up the tree and unhold the parents. */
for (struct cell *finger = c->parent; finger != NULL; finger = finger->parent)
__sync_fetch_and_sub(&finger->ghold, 1);
atomic_dec(&finger->ghold);
TIMER_TOC(timer_locktree);
}
......
......@@ -23,6 +23,7 @@
#include <pthread.h>
/* Includes. */
#include "atomic.h"
#include "inline.h"
#ifdef PTHREAD_SPINLOCK
......@@ -48,14 +49,14 @@
#define lock_init(l) (*(l) = 0)
#define lock_destroy(l) 0
INLINE static int lock_lock(volatile int *l) {
while (__sync_val_compare_and_swap(l, 0, 1) != 0)
while (atomic_cas(l, 0, 1) != 0)
;
// while( *l );
return 0;
}
#define lock_trylock(l) ((*(l)) ? 1 : __sync_val_compare_and_swap(l, 0, 1))
#define lock_unlock(l) (__sync_val_compare_and_swap(l, 1, 0) != 1)
#define lock_unlock_blind(l) __sync_val_compare_and_swap(l, 1, 0)
#define lock_trylock(l) ((*(l)) ? 1 : atomic_cas(l, 0, 1))
#define lock_unlock(l) (atomic_cas(l, 1, 0) != 1)
#define lock_unlock_blind(l) atomic_cas(l, 1, 0)
#endif
#endif /* SWIFT_LOCK_H */
......@@ -18,15 +18,23 @@
*
******************************************************************************/
#include "map.h"
/* Config parameters. */
#include "../config.h"
/* Some standard headers. */
#include <stdio.h>
#include <stdlib.h>
/* This object's header. */
#include "map.h"
/* Local headers. */
#include "atomic.h"
#include "error.h"
/**
* @brief Mapping function to draw a specific cell (gnuplot).
*/
void map_cells_plot(struct cell *c, void *data) {
int depth = *(int *)data;
......@@ -80,24 +88,21 @@ void map_cells_plot(struct cell *c, void *data) {
/**
* @brief Mapping function for checking if each part is in its box.
*/
void map_check(struct part *p, struct cell *c, void *data) {
/* void map_check ( struct part *p , struct cell *c , void *data ) {
if ( p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] ||
p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] ||
p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] )
printf( "map_check: particle %i is outside of its box.\n" , p->id );
} */
if (p->x[0] < c->loc[0] || p->x[0] > c->loc[0] + c->h[0] ||
p->x[0] < c->loc[0] || p->x[0] > c->loc[0] + c->h[0] ||
p->x[0] < c->loc[0] || p->x[0] > c->loc[0] + c->h[0])
printf("map_check: particle %lld is outside of its box.\n", p->id);
}
/**
* @brief Mapping function for neighbour count.
*/
void map_cellcheck(struct cell *c, void *data) {
int *count = (int *)data;
__sync_fetch_and_add(count, c->count);
atomic_add(count, c->count);
/* Loop over all parts and check if they are in the cell. */
for (int k = 0; k < c->count; k++) {
......@@ -133,7 +138,6 @@ void map_cellcheck(struct cell *c, void *data) {
/**
* @brief Mapping function for maxdepth cell count.
*/
void map_maxdepth(struct cell *c, void *data) {
int maxdepth = ((int *)data)[0];
......@@ -147,7 +151,6 @@ void map_maxdepth(struct cell *c, void *data) {
/**
* @brief Mapping function for neighbour count.
*/
void map_count(struct part *p, struct cell *c, void *data) {
double *wcount = (double *)data;
......@@ -156,7 +159,6 @@ void map_count(struct part *p, struct cell *c, void *data) {
*wcount += p->density.wcount;
}
void map_wcount_min(struct part *p, struct cell *c, void *data) {
struct part **p2 = (struct part **)data;
......@@ -188,7 +190,6 @@ void map_h_max(struct part *p, struct cell *c, void *data) {
/**
* @brief Mapping function for neighbour count.
*/
void map_icount(struct part *p, struct cell *c, void *data) {
// int *count = (int *)data;
......@@ -201,7 +202,6 @@ void map_icount(struct part *p, struct cell *c, void *data) {
/**
* @brief Mapping function to print the particle position.
*/
void map_dump(struct part *p, struct cell *c, void *data) {
double *shift = (double *)data;
......
......@@ -23,6 +23,7 @@
#define SWIFT_TIMERS_H
/* Includes. */
#include "atomic.h"
#include "cycle.h"
#include "inline.h"
......@@ -71,7 +72,7 @@ extern ticks timers[timer_count];
#define TIMER_TOC2(t) timers_toc(t, tic2)
INLINE static ticks timers_toc(int t, ticks tic) {
ticks d = (getticks() - tic);
__sync_add_and_fetch(&timers[t], d);
atomic_add(&timers[t], d);
return d;
}
#else
......
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