apple2ix/src/common.h

160 lines
3.2 KiB
C
Raw Normal View History

2013-07-07 21:01:21 +00:00
/*
* Apple // emulator for *ix
2013-07-07 21:01:21 +00:00
*
* This software package is subject to the GNU General Public License
* version 3 or later (your choice) as published by the Free Software
2013-07-07 21:01:21 +00:00
* Foundation.
*
* Copyright 2013-2015 Aaron Culliney
2013-07-07 21:01:21 +00:00
*
*/
#ifndef _COMMON_H_
#define _COMMON_H_
2013-10-23 04:18:03 +00:00
#if defined(__GNUC__) && !defined(_GNU_SOURCE)
# define _GNU_SOURCE 1
#endif
// custom annotations
#define INOUT
#define INPARM
#define _NONNULL
#define _NULLABLE
#define OUTPARM
#define PRIVATE
#define PUBLIC
#define READONLY
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2013-07-07 21:01:21 +00:00
#include <stdlib.h>
#include <stdio.h>
2013-07-07 21:01:21 +00:00
#include <errno.h>
#include <string.h>
2013-10-06 06:13:24 +00:00
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <ctype.h>
#include <dirent.h>
#include <fcntl.h>
#include <limits.h>
#include <math.h>
#include <zlib.h>
2013-07-07 21:01:21 +00:00
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "json_parse.h"
#include "misc.h"
#include "vm.h"
#include "timing.h"
#include "cpu.h"
#include "interface.h"
#include "display.h"
#include "video/video.h"
#include "disk.h"
#include "keys.h"
#include "joystick.h"
#include "glue.h"
#include "prefs.h"
#include "zlib-helpers.h"
#include "meta/trace.h"
2017-08-20 06:05:58 +00:00
#if __APPLE__
# include "meta/darwin-shim.h"
# if TARGET_OS_MAC || TARGET_OS_PHONE
# import <CoreFoundation/CoreFoundation.h>
# endif
2015-01-17 05:10:45 +00:00
#endif
#if VIDEO_OPENGL
# include "video_util/glUtil.h"
#endif
#include "meta/log.h"
#include "meta/debug.h"
#include "audio/soundcore.h"
#include "audio/speaker.h"
#include "audio/mockingboard.h"
#ifdef ANDROID
# include "../Android/jni/android_globals.h"
# define USE_SIMD 1
# define SIMD_IS_AVAILABLE() (android_armNeonEnabled/* || android_x86SSSE3Enabled*/)
#else
# define SIMD_IS_AVAILABLE()
#endif
2015-06-02 05:25:29 +00:00
#define PATH_SEPARATOR "/" // =P
2014-03-30 17:39:45 +00:00
#if !defined(MIN)
#define MIN(a,b) (((a) <= (b)) ? (a) : (b))
#endif
#if !defined(MAX)
#define MAX(a,b) (((a) >= (b)) ? (a) : (b))
#endif
#define SPINLOCK_INIT 0
#define SPINLOCK_ACQUIRED -1
#define SPINLOCK_ACQUIRE(x) \
do { \
long val = __sync_sub_and_fetch((x), 1); \
if (val == SPINLOCK_ACQUIRED) { \
break; \
} \
__sync_add_and_fetch((x), 1); \
} while (1);
#define SPINLOCK_RELINQUISH(x) \
__sync_add_and_fetch((x), 1);
2015-10-04 21:39:53 +00:00
// cribbed from AOSP and modified with usleep() and to also ignore EAGAIN (should this be a different errno than EINTR)
#define TEMP_FAILURE_RETRY_FOPEN(exp) ({ \
typeof (exp) _rc; \
do { \
_rc = (exp); \
if (_rc == NULL && (errno == EINTR || errno == EAGAIN) ) { \
usleep(10); \
} else { \
break; \
} \
} while (1); \
_rc; })
// memory management
2017-08-20 05:53:51 +00:00
#include "meta/memmngt.h"
// branch prediction
#define LIKELY(x) __builtin_expect((x), true)
#define UNLIKELY(x) __builtin_expect((x), false)
2017-08-20 06:05:58 +00:00
#if !defined(TEMP_FAILURE_RETRY)
# define TEMP_FAILURE_RETRY(exp) ({ \
typeof (exp) _rc; \
do { \
_rc = (exp); \
if (_rc == -1 && (errno == EINTR || errno == EAGAIN) ) { \
usleep(10); \
} else { \
break; \
} \
} while (1); \
_rc; })
#endif
2013-07-07 21:01:21 +00:00
#endif // whole file