-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mutex to NiftiIO so it doesn't crash under multithreading
tidy up cmake package finding, add sigc++ for mutex (when openmp and qt aren't used) asserts in BinaryFile for wrong length/position ranges don't set bad flags on msvc remove M_PI as msvc doesn't define it
- Loading branch information
Showing
11 changed files
with
160 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
#use pkg-config | ||
FIND_PACKAGE(PkgConfig) | ||
PKG_CHECK_MODULES(PC_SIGCXX sigc++-2.0) | ||
|
||
FIND_PATH(sigc++_INCLUDE_DIR NAMES sigc++/sigc++.h HINTS ${PC_SIGCXX_INCLUDEDIR} ${PC_SIGCXX_INCLUDE_DIRS}) | ||
FIND_PATH(sigc++_config_INCLUDE_DIR NAMES sigc++config.h HINTS ${PC_SIGCXX_INCLUDEDIR} ${PC_SIGCXX_INCLUDE_DIRS}) | ||
FIND_LIBRARY(sigc++_LIBRARY NAMES sigc sigc-2.0 HINTS ${PC_SIGCXX_LIBDIR} ${PC_SIGCXX_LIBRARY_DIRS}) | ||
|
||
SET(sigc++_LIBRARIES ${sigc++_LIBRARY} ${PC_SIGCXX_PKGCONF_LIBRARIES}) | ||
SET(sigc++_INCLUDE_DIRS ${sigc++_INCLUDE_DIR} ${sigc++_config_INCLUDE_DIR} ${PC_SIGCXX_PKGCONF_INCLUDE_DIRS}) | ||
|
||
INCLUDE(FindPackageHandleStandardArgs) | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(sigc++ DEFAULT_MSG sigc++_LIBRARY sigc++_INCLUDE_DIR) | ||
|
||
MARK_AS_ADVANCED(sigc++_INCLUDE_DIR sigc++_config_INCLUDE_DIR sigc++_LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#ifndef __CIFTI_MUTEX_H__ | ||
#define __CIFTI_MUTEX_H__ | ||
|
||
/*LICENSE_START*/ | ||
/* | ||
* Copyright (c) 2016, Washington University School of Medicine | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, | ||
* are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | ||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifdef _OPENMP | ||
#define __CIFTI_MUTEX_H_HAVE_IMPL__ | ||
|
||
#include "omp.h" | ||
|
||
namespace cifti | ||
{ | ||
class CiftiMutex | ||
{ | ||
omp_lock_t m_lock; | ||
public: | ||
CiftiMutex(const CiftiMutex&) { omp_init_lock(&m_lock); };//allow copy, assign, but make them do nothing other than default construct | ||
CiftiMutex& operator=(const CiftiMutex&) { return *this; }; | ||
CiftiMutex() { omp_init_lock(&m_lock); } | ||
~CiftiMutex() { omp_destroy_lock(&m_lock); } | ||
friend class CiftiMutexLocker; | ||
}; | ||
|
||
class CiftiMutexLocker | ||
{ | ||
CiftiMutex* m_mutex; | ||
CiftiMutexLocker();//disallow default construction, assign | ||
CiftiMutexLocker& operator=(const CiftiMutexLocker& rhs); | ||
public: | ||
CiftiMutexLocker(CiftiMutex* mutex) { m_mutex = mutex; omp_set_lock(&(m_mutex->m_lock)); } | ||
~CiftiMutexLocker() { omp_unset_lock(&(m_mutex->m_lock)); } | ||
}; | ||
} | ||
|
||
#else //_OPENMP | ||
|
||
#ifdef CIFTILIB_USE_QT | ||
#define __CIFTI_MUTEX_H_HAVE_IMPL__ | ||
|
||
#include <QMutex> | ||
|
||
namespace cifti | ||
{ | ||
typedef QMutex CiftiMutex; | ||
typedef QMutexLocker CiftiMutexLocker; | ||
} | ||
|
||
#endif //CIFTILIB_USE_QT | ||
|
||
#ifdef CIFTILIB_USE_XMLPP | ||
#define __CIFTI_MUTEX_H_HAVE_IMPL__ | ||
|
||
#include <glibmm/thread.h> | ||
|
||
namespace cifti | ||
{ | ||
typedef Glib::Mutex CiftiMutex; | ||
|
||
//API difference: glib's locker class takes a reference, while QT's takes a pointer | ||
class CiftiMutexLocker | ||
{ | ||
CiftiMutex* m_mutex; | ||
CiftiMutexLocker();//disallow default construction, assign | ||
CiftiMutexLocker& operator=(const CiftiMutexLocker& rhs); | ||
public: | ||
CiftiMutexLocker(CiftiMutex* mutex) { m_mutex = mutex; m_mutex->lock(); } | ||
~CiftiMutexLocker() { m_mutex->unlock(); } | ||
}; | ||
} | ||
|
||
#endif //CIFTILIB_USE_XMLPP | ||
|
||
#endif //_OPENMP | ||
|
||
|
||
#ifndef __CIFTI_MUTEX_H_HAVE_IMPL__ | ||
#error "you must have openmp support, or define either CIFTILIB_USE_QT or CIFTILIB_USE_XMLPP to select what mutex implementation to use" | ||
#endif | ||
|
||
#endif //__CIFTI_MUTEX_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters