MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Classes | Functions | Variables
spinlocks.c File Reference
#include "spinlocks.h"
#include "mymalloc.h"
#include <pthread.h>
Include dependency graph for spinlocks.c:

Go to the source code of this file.

Classes

struct  SpinLocks
 

Functions

void lock_spinlock (int i, struct SpinLocks *spin)
 
void unlock_spinlock (int i, struct SpinLocks *spin)
 
int try_lock_spinlock (int i, struct SpinLocks *spin)
 
struct SpinLocksinit_spinlocks (int NumLock)
 
void free_spinlocks (struct SpinLocks *spin)
 

Variables

static struct SpinLocks spin
 

Function Documentation

◆ free_spinlocks()

void free_spinlocks ( struct SpinLocks spin)

Definition at line 70 of file spinlocks.c.

71 {
72  int i;
73  for(i = 0; i < spin->NumSpinLock; i ++) {
74 #ifndef NO_OPENMP_SPINLOCK
75  pthread_spin_destroy(&(spin->SpinLocks[i]));
76 #else
77  omp_destroy_lock(&(spin->SpinLocks[i]));
78 #endif
79  }
80  myfree((void *) spin->SpinLocks);
81 }
#define myfree(x)
Definition: mymalloc.h:19
static struct SpinLocks spin
Definition: spinlocks.c:21
int NumSpinLock
Definition: spinlocks.c:18
pthread_spinlock_t * SpinLocks
Definition: spinlocks.c:14

References myfree, SpinLocks::NumSpinLock, spin, and SpinLocks::SpinLocks.

Referenced by fof_label_primary(), and metal_return().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_spinlocks()

struct SpinLocks* init_spinlocks ( int  NumLock)

Definition at line 49 of file spinlocks.c.

50 {
51  int i;
52  /* Initialize the spinlocks*/
53 #ifndef NO_OPENMP_SPINLOCK
54  spin.SpinLocks = (pthread_spinlock_t *) mymalloc("SpinLocks", NumLock * sizeof(pthread_spinlock_t));
55  #pragma omp parallel for
56 #else
57  spin.SpinLocks = mymalloc("SpinLocks", NumLock * sizeof(omp_lock_t));
58 #endif
59  for(i = 0; i < NumLock; i ++) {
60 #ifndef NO_OPENMP_SPINLOCK
61  pthread_spin_init(&spin.SpinLocks[i], PTHREAD_PROCESS_PRIVATE);
62 #else
63  omp_init_lock(&spin.SpinLocks[i]);
64 #endif
65  }
66  spin.NumSpinLock = NumLock;
67  return &spin;
68 }
#define mymalloc(name, size)
Definition: mymalloc.h:15

References mymalloc, SpinLocks::NumSpinLock, spin, and SpinLocks::SpinLocks.

Referenced by fof_label_primary(), and metal_return().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lock_spinlock()

void lock_spinlock ( int  i,
struct SpinLocks spin 
)

Definition at line 23 of file spinlocks.c.

23  {
24 #ifndef NO_OPENMP_SPINLOCK
25  pthread_spin_lock(&spin->SpinLocks[i]);
26 #else
27  omp_set_lock(&spin->SpinLocks[i]);
28 #endif
29 }

References spin, and SpinLocks::SpinLocks.

Referenced by fof_label_primary(), fof_primary_ngbiter(), fofp_merge(), and metal_return_ngbiter().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_lock_spinlock()

int try_lock_spinlock ( int  i,
struct SpinLocks spin 
)

Definition at line 38 of file spinlocks.c.

39 {
40 #ifndef NO_OPENMP_SPINLOCK
41  return pthread_spin_trylock(&spin->SpinLocks[i]);
42 #else
43  /* omp returns true if successful, ie, lock taken.
44  * pthread_spin_lock returns 0 on success*/
45  return !omp_test_lock(&spin->SpinLocks[i]);
46 #endif
47 }

References spin, and SpinLocks::SpinLocks.

Here is the call graph for this function:

◆ unlock_spinlock()

void unlock_spinlock ( int  i,
struct SpinLocks spin 
)

Definition at line 30 of file spinlocks.c.

30  {
31 #ifndef NO_OPENMP_SPINLOCK
32  pthread_spin_unlock(&spin->SpinLocks[i]);
33 #else
34  omp_unset_lock(&spin->SpinLocks[i]);
35 #endif
36 }

References spin, and SpinLocks::SpinLocks.

Referenced by fof_label_primary(), fof_primary_ngbiter(), fofp_merge(), and metal_return_ngbiter().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ spin

struct SpinLocks spin
static