diff options
author | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2019-01-16 20:07:39 +0000 |
---|---|---|
committer | Jonathan Peyton <jonathan.l.peyton@intel.com> | 2019-01-16 20:07:39 +0000 |
commit | 9b8bb323c94768ae788d77fc597f057d97b9eb17 (patch) | |
tree | 12c14373815b1a903478b5feebb041ca5f1af3c6 /openmp/runtime/src/z_Linux_util.cpp | |
parent | 837da5d3ecdda47cc8cbc08420eea6d1327117e5 (diff) | |
download | bcm5719-llvm-9b8bb323c94768ae788d77fc597f057d97b9eb17.tar.gz bcm5719-llvm-9b8bb323c94768ae788d77fc597f057d97b9eb17.zip |
[OpenMP] Add omp_pause_resource* API
Add omp_pause_resource and omp_pause_resource_all API and enum, plus stub for
internal implementation. Implemented callable helper function to do local pause,
and added basic functionality for hard and soft pause.
Patch by Terry Wilmarth
Differential Revision: https://reviews.llvm.org/D55078
llvm-svn: 351372
Diffstat (limited to 'openmp/runtime/src/z_Linux_util.cpp')
-rw-r--r-- | openmp/runtime/src/z_Linux_util.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp index aa0302c0fc3..eb6c3c0b4ce 100644 --- a/openmp/runtime/src/z_Linux_util.cpp +++ b/openmp/runtime/src/z_Linux_util.cpp @@ -1414,6 +1414,21 @@ void __kmp_suspend_uninitialize_thread(kmp_info_t *th) { } } +// return true if lock obtained, false otherwise +int __kmp_try_suspend_mx(kmp_info_t *th) { + return (pthread_mutex_trylock(&th->th.th_suspend_mx.m_mutex) == 0); +} + +void __kmp_lock_suspend_mx(kmp_info_t *th) { + int status = pthread_mutex_lock(&th->th.th_suspend_mx.m_mutex); + KMP_CHECK_SYSFAIL("pthread_mutex_lock", status); +} + +void __kmp_unlock_suspend_mx(kmp_info_t *th) { + int status = pthread_mutex_unlock(&th->th.th_suspend_mx.m_mutex); + KMP_CHECK_SYSFAIL("pthread_mutex_unlock", status); +} + /* This routine puts the calling thread to sleep after setting the sleep bit for the indicated flag variable to true. */ template <class C> @@ -1437,7 +1452,15 @@ static inline void __kmp_suspend_template(int th_gtid, C *flag) { /* TODO: shouldn't this use release semantics to ensure that __kmp_suspend_initialize_thread gets called first? */ old_spin = flag->set_sleeping(); - +#if OMP_50_ENABLED + if (__kmp_dflt_blocktime == KMP_MAX_BLOCKTIME && + __kmp_pause_status != kmp_soft_paused) { + flag->unset_sleeping(); + status = pthread_mutex_unlock(&th->th.th_suspend_mx.m_mutex); + KMP_CHECK_SYSFAIL("pthread_mutex_unlock", status); + return; + } +#endif KF_TRACE(5, ("__kmp_suspend_template: T#%d set sleep bit for spin(%p)==%x," " was %x\n", th_gtid, flag->get(), flag->load(), old_spin)); |