<commit_before>/* Copyright 2022 Stanford University, NVIDIA Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// mutexes, condition variables, etc.

#include "realm/realm_config.h"

// include gasnet header files before mutex.h to make sure we have
//  definitions for gasnet_hsl_t and gasnett_cond_t
#ifdef REALM_USE_GASNET1

// so OpenMPI borrowed gasnet's platform-detection code and didn't change
//  the define names - work around it by undef'ing anything set via mpi.h
//  before we include gasnet.h
#undef __PLATFORM_COMPILER_GNU_VERSION_STR

#ifndef GASNET_PAR
#define GASNET_PAR
#endif
#include <gasnet.h>

#ifndef GASNETT_THREAD_SAFE
#define GASNETT_THREAD_SAFE
#endif
#include <gasnet_tools.h>

// eliminate GASNet warnings for unused static functions
REALM_ATTR_UNUSED(static const void *ignore_gasnet_warning1) = (void *)_gasneti_threadkey_init;
REALM_ATTR_UNUSED(static const void *ignore_gasnet_warning2) = (void *)_gasnett_trace_printf_noop;

// can't use gasnet_hsl_t in debug mode
// actually, don't use gasnet_hsl_t at all right now...
//#ifndef GASNET_DEBUG
#if 0
#define USE_GASNET_HSL_T
#endif
#endif

#ifdef USE_GASNET_HSL_T

#define REALM_KERNEL_MUTEX_IMPL   gasnet_hsl_t mutex
#define REALM_KERNEL_CONDVAR_IMPL gasnett_cond_t condvar
// gasnet doesn't provide an rwlock?
#define REALM_RWLOCK_IMPL  pthread_rwlock_t rwlock

#else

#ifdef REALM_ON_WINDOWS
#include <windows.h>
#include <synchapi.h>
#include <processthreadsapi.h>

#define REALM_KERNEL_MUTEX_IMPL   CRITICAL_SECTION mutex
#define REALM_KERNEL_CONDVAR_IMPL CONDITION_VARIABLE condvar
struct RWLockImpl {
  SRWLOCK rwlock;
  bool exclusive;
};
#define REALM_RWLOCK_IMPL  RWLockImpl rwlock
#else
// use pthread mutex/condvar
#include <pthread.h>
#include <errno.h>

#define REALM_KERNEL_MUTEX_IMPL   pthread_mutex_t mutex
#define REALM_KERNEL_CONDVAR_IMPL pthread_cond_t  condvar
#define REALM_RWLOCK_IMPL  pthread_rwlock_t rwlock
#endif
#endif

#include "realm/mutex.h"
#include "realm/timers.h"
#include "realm/faults.h"

#include <assert.h>
#include <new>

#if defined(REALM_ON_LINUX) && !defined(REALM_NO_USE_FUTEX)
#include <linux/futex.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/syscall.h>
#endif

#ifdef REALM_ON_MACOS
#include <unistd.h>
#endif

#ifdef __SSE2__
// technically pause is an "SSE2" instruction, but it's defined in xmmintrin
//  (it'd be fine to call it on older CPUs, but since we're doing conditional
//  compilation, only use it if it does something)
#include <xmmintrin.h>
#endif

#ifdef REALM_ON_WINDOWS
static void sleep(long seconds) { Sleep(seconds * 1000); }
#endif

namespace Realm {<commit_msg>realm: more tweaks for inclusion of platform-specific headers<commit_after>/* Copyright 2022 Stanford University, NVIDIA Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// mutexes, condition variables, etc.

#include "realm/realm_config.h"

// include gasnet header files before mutex.h to make sure we have
//  definitions for gasnet_hsl_t and gasnett_cond_t
#ifdef REALM_USE_GASNET1

// so OpenMPI borrowed gasnet's platform-detection code and didn't change
//  the define names - work around it by undef'ing anything set via mpi.h
//  before we include gasnet.h
#undef __PLATFORM_COMPILER_GNU_VERSION_STR

#ifndef GASNET_PAR
#define GASNET_PAR
#endif
#include <gasnet.h>

#ifndef GASNETT_THREAD_SAFE
#define GASNETT_THREAD_SAFE
#endif
#include <gasnet_tools.h>

// eliminate GASNet warnings for unused static functions
REALM_ATTR_UNUSED(static const void *ignore_gasnet_warning1) = (void *)_gasneti_threadkey_init;
REALM_ATTR_UNUSED(static const void *ignore_gasnet_warning2) = (void *)_gasnett_trace_printf_noop;

// can't use gasnet_hsl_t in debug mode
// actually, don't use gasnet_hsl_t at all right now...
//#ifndef GASNET_DEBUG
#if 0
#define USE_GASNET_HSL_T
#endif
#endif

#ifdef USE_GASNET_HSL_T

#define REALM_KERNEL_MUTEX_IMPL   gasnet_hsl_t mutex
#define REALM_KERNEL_CONDVAR_IMPL gasnett_cond_t condvar
// gasnet doesn't provide an rwlock?
#define REALM_RWLOCK_IMPL  pthread_rwlock_t rwlock

#else

#ifdef REALM_ON_WINDOWS
#include <windows.h>
#include <synchapi.h>
#include <processthreadsapi.h>

#define REALM_KERNEL_MUTEX_IMPL   CRITICAL_SECTION mutex
#define REALM_KERNEL_CONDVAR_IMPL CONDITION_VARIABLE condvar
struct RWLockImpl {
  SRWLOCK rwlock;
  bool exclusive;
};
#define REALM_RWLOCK_IMPL  RWLockImpl rwlock
#else
// use pthread mutex/condvar
#include <pthread.h>
#include <errno.h>

#define REALM_KERNEL_MUTEX_IMPL   pthread_mutex_t mutex
#define REALM_KERNEL_CONDVAR_IMPL pthread_cond_t  condvar
#define REALM_RWLOCK_IMPL  pthread_rwlock_t rwlock
#endif
#endif

#include "realm/mutex.h"
#include "realm/timers.h"
#include "realm/faults.h"

#include <assert.h>
#include <new>

#if defined(REALM_ON_LINUX) || defined(REALM_ON_MACOS) || defined(REALM_ON_FREEBSD)
#include <unistd.h>
#endif

#if defined(REALM_ON_LINUX) && !defined(REALM_NO_USE_FUTEX)
#include <linux/futex.h>
#include <sys/time.h>
#include <sys/syscall.h>
#endif

#ifdef __SSE2__
// technically pause is an "SSE2" instruction, but it's defined in xmmintrin
//  (it'd be fine to call it on older CPUs, but since we're doing conditional
//  compilation, only use it if it does something)
#include <xmmintrin.h>
#endif

#ifdef REALM_ON_WINDOWS
static void sleep(long seconds) { Sleep(seconds * 1000); }
#endif

namespace Realm {
{'fraction_non_alphanumeric': 0.0821875, 'fraction_numerical': 0.005625, 'mean_word_length': 5.2509765625, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5287915', 'n_tokens_mistral': 2333, 'n_tokens_neox': 2264, 'n_words': 677}