<commit_before>/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
 *     Copyright 2010 Couchbase, Inc
 *
 *   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.
 */

#ifndef _JSAHN_ARCH_H
#define _JSAHN_ARCH_H

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <stdio.h>
#include <fcntl.h>

#include "forestdb_endian.h"

#ifdef _PLATFORM_LIB_AVAILABLE
#include <platform/platform.h>
#endif // _PLATFORM_LIB_AVAILABLE

/* Large File Support */
#define _LARGE_FILE 1
#ifndef _FILE_OFFSET_BITS
#  define _FILE_OFFSET_BITS 64
#elif (_FILE_OFFSET_BITS != 64)
#error "bad things"
#endif
#define _LARGEFILE_SOURCE 1
#ifndef O_LARGEFILE
# define O_LARGEFILE 0
#endif

#ifndef _MSC_VER
#include <stdbool.h>
#else
#ifndef __cplusplus
#pragma once
#define false (0)
#define true (1)
#define bool int
#endif
#endif

#ifdef HAVE_JEMALLOC
#ifdef WIN32
/* jemalloc.h tries to include strings.h, but on win32
   that is our own "hacked" version that provides stuff
   we use elsewhere in the system. By including that
   file you might end up having to link with the
   platform lib which supplies a lot of the functions
   forestdb also provides an implementation of (but
   with a different linkage)
*/
#define STRINGS_H
#endif

/* string has some memory allocators of its own which MUST come first
 in the include order to ensure that je_malloc can correctly override
 the string malloc and free definitions too, otherwise we can have
 asymmetrical operation resulting in crashes.
 TODO: We plan to address this in a modularized way in the future.
*/
#include <string>
#include <jemalloc/jemalloc.h>

#ifdef WIN32
#undef STRINGS_H
#endif

#undef malloc
#undef calloc
#undef realloc
#undef free
#undef posix_memalign
#undef memalign
#undef aligned_malloc
#undef aligned_free

#define malloc(size) je_malloc(size)
#define calloc(nmemb, size) je_calloc(nmemb, size)
#define realloc(ptr, size) je_realloc(ptr, size)
#define free(addr) je_free(addr)
#define posix_memalign(memptr, alignment, size) \
	je_posix_memalign(memptr, alignment, size)
#define memalign(alignment, size) je_memalign(alignment, size)
#define aligned_malloc(size, align) je_aligned_malloc(size, align)
#define aligned_free(addr) je_aligned_free(addr)
#endif //HAVE_JEMALLOC

#ifdef __APPLE__
    #include <inttypes.h>
    #include <alloca.h>
    #include <TargetConditionals.h>

    #define INLINE extern inline

    #define _X64 "llx"
    #define _F64 "llu"
    #define _FSEC "ld"
    #define _FUSEC "d"

    #define _ARCH_O_DIRECT (0x0)

    #if TARGET_CPU_ARM
    #define _ALIGN_MEM_ACCESS
    #endif

    #define malloc_align(addr, align, size) \
        {int __ret__; __ret__=posix_memalign(&(addr), (align), (size));\
         (void)__ret__;}
    #define free_align(addr) free(addr)

    #ifndef spin_t
        // spinlock
        #include <libkern/OSAtomic.h>
        #define spin_t OSSpinLock
        #define spin_lock(arg) OSSpinLockLock(arg)
        #define spin_trylock(arg) OSSpinLockTry(arg)
        #define spin_unlock(arg) OSSpinLockUnlock(arg)
        #define SPIN_INITIALIZER (spin_t)(0)
        #define spin_init(arg) *(arg) = (spin_t)(0)
        #define spin_destroy(arg)
    #endif
    #ifndef mutex_t
        // mutex
        #include <pthread.h>
        #define mutex_t pthread_mutex_t
        #define mutex_init(arg) pthread_mutex_init(arg, NULL)
        #define mutex_lock(arg) pthread_mutex_lock(arg)
        #define mutex_trylock(arg) \
            (pthread_mutex_trylock(arg) == 0)
        #define mutex_unlock(arg) pthread_mutex_unlock(arg)
        #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER<commit_msg>MB-21503: Replace OSSpinLock with os_unfair_lock for OSX>=10.12<commit_after>/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/*
 *     Copyright 2010 Couchbase, Inc
 *
 *   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.
 */

#ifndef _JSAHN_ARCH_H
#define _JSAHN_ARCH_H

#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif

#include <stdio.h>
#include <fcntl.h>

#include "forestdb_endian.h"

#ifdef _PLATFORM_LIB_AVAILABLE
#include <platform/platform.h>
#endif // _PLATFORM_LIB_AVAILABLE

/* Large File Support */
#define _LARGE_FILE 1
#ifndef _FILE_OFFSET_BITS
#  define _FILE_OFFSET_BITS 64
#elif (_FILE_OFFSET_BITS != 64)
#error "bad things"
#endif
#define _LARGEFILE_SOURCE 1
#ifndef O_LARGEFILE
# define O_LARGEFILE 0
#endif

#ifndef _MSC_VER
#include <stdbool.h>
#else
#ifndef __cplusplus
#pragma once
#define false (0)
#define true (1)
#define bool int
#endif
#endif

#ifdef HAVE_JEMALLOC
#ifdef WIN32
/* jemalloc.h tries to include strings.h, but on win32
   that is our own "hacked" version that provides stuff
   we use elsewhere in the system. By including that
   file you might end up having to link with the
   platform lib which supplies a lot of the functions
   forestdb also provides an implementation of (but
   with a different linkage)
*/
#define STRINGS_H
#endif

/* string has some memory allocators of its own which MUST come first
 in the include order to ensure that je_malloc can correctly override
 the string malloc and free definitions too, otherwise we can have
 asymmetrical operation resulting in crashes.
 TODO: We plan to address this in a modularized way in the future.
*/
#include <string>
#include <jemalloc/jemalloc.h>

#ifdef WIN32
#undef STRINGS_H
#endif

#undef malloc
#undef calloc
#undef realloc
#undef free
#undef posix_memalign
#undef memalign
#undef aligned_malloc
#undef aligned_free

#define malloc(size) je_malloc(size)
#define calloc(nmemb, size) je_calloc(nmemb, size)
#define realloc(ptr, size) je_realloc(ptr, size)
#define free(addr) je_free(addr)
#define posix_memalign(memptr, alignment, size) \
        je_posix_memalign(memptr, alignment, size)
#define memalign(alignment, size) je_memalign(alignment, size)
#define aligned_malloc(size, align) je_aligned_malloc(size, align)
#define aligned_free(addr) je_aligned_free(addr)
#endif //HAVE_JEMALLOC

#ifdef __APPLE__
    #include <inttypes.h>
    #include <alloca.h>
    #include <TargetConditionals.h>
    #include <AvailabilityMacros.h>

    #define INLINE extern inline

    #define _X64 "llx"
    #define _F64 "llu"
    #define _FSEC "ld"
    #define _FUSEC "d"

    #define _ARCH_O_DIRECT (0x0)

    #if TARGET_CPU_ARM
    #define _ALIGN_MEM_ACCESS
    #endif

    #define malloc_align(addr, align, size) \
        {int __ret__; __ret__=posix_memalign(&(addr), (align), (size));\
         (void)__ret__;}
    #define free_align(addr) free(addr)

    #ifndef spin_t
        // spinlock
        #include <libkern/OSAtomic.h>
        #ifndef MAC_OS_X_VERSION_10_12
            #define MAC_OS_X_VERSION_10_12 101200
        #endif
        #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
            #include <os/lock.h>
            #define spin_t os_unfair_lock
            #define spin_lock(arg) os_unfair_lock_lock(arg)
            #define spin_trylock(arg) os_unfair_lock_trylock(arg)
            #define spin_unlock(arg) os_unfair_lock_unlock(arg)
            #define spin_init(arg) *(arg) = OS_UNFAIR_LOCK_INIT
        #else
            #define spin_t OSSpinLock
            #define spin_lock(arg) OSSpinLockLock(arg)
            #define spin_trylock(arg) OSSpinLockTry(arg)
            #define spin_unlock(arg) OSSpinLockUnlock(arg)
            #define SPIN_INITIALIZER (spin_t)(0)
            #define spin_init(arg) *(arg) = (spin_t)(0)
        #endif
        #define spin_destroy(arg)
    #endif
    #ifndef mutex_t
        // mutex
        #include <pthread.h>
        #define mutex_t pthread_mutex_t
        #define mutex_init(arg) pthread_mutex_init(arg, NULL)
        #define mutex_lock(arg) pthread_mutex_lock(arg)
        #define mutex_trylock(arg) \
            (pthread_mutex_trylock(arg) == 0)
        #define mutex_unlock(arg) pthread_mutex_unlock(arg)
        #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
{'fraction_non_alphanumeric': 0.08803561491374513, 'fraction_numerical': 0.010573177518085699, 'mean_word_length': 3.7394514767932487, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, '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': '5576016', 'n_tokens_mistral': 3086, 'n_tokens_neox': 2989, 'n_words': 904}