Skip to content

Commit

Permalink
mutual exclusion with bart_lock;
Browse files Browse the repository at this point in the history
this is a wrapper around the locks from the omp runtime - was required to be able to easily switch between mutex implementations.
  • Loading branch information
schaten authored and uecker committed Jul 8, 2024
1 parent 238f321 commit 33f3143
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/misc/lock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Copyright 2024. Institute of Biomedical Imaging. TU Graz.
* All rights reserved. Use of this source code is governed by
* a BSD-style license which can be found in the LICENSE file.
*
* Authors:
* 2024 Philip Schaten <philip.schaten@tugraz.at>
*/

#ifdef _OPENMP
#include <omp.h>
#endif

#include "misc/misc.h"

#include "lock.h"

struct bart_lock {
#ifdef _OPENMP
omp_lock_t omp;
#else
int dummy;
#endif
};

void bart_lock(bart_lock_t* lock)
{
#ifdef _OPENMP
omp_set_lock(&lock->omp);
#endif
}

void bart_unlock(bart_lock_t* lock)
{
#ifdef _OPENMP
omp_unset_lock(&lock->omp);
#endif
}

bart_lock_t* bart_lock_create(void)
{
bart_lock_t* lock = xmalloc(sizeof *lock);

#ifdef _OPENMP
omp_init_lock(&lock->omp);
#endif
return lock;
}

void bart_lock_destroy(bart_lock_t* lock)
{
#ifdef _OPENMP
omp_destroy_lock(&lock->omp);
#endif
xfree(lock);
}

8 changes: 8 additions & 0 deletions src/misc/lock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

typedef struct bart_lock bart_lock_t;

void bart_lock(bart_lock_t* lock);
void bart_unlock(bart_lock_t* lock);
void bart_lock_destroy(bart_lock_t* x);
bart_lock_t* bart_lock_create(void);

0 comments on commit 33f3143

Please sign in to comment.