Files
externals/linux/include/celoxica/platform.h
T
2017-10-04 14:16:02 -04:00

101 lines
2.3 KiB
C

#ifndef __CELOXICA_LINUX_PLATFORM_H__
#define __CELOXICA_LINUX_PLATFORM_H__
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdint.h>
#include <fcntl.h>
#include <sched.h>
#include <syscall.h>
#include <assert.h>
#include <stdlib.h>
#ifdef __cplusplus
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
# pragma GCC diagnostic push
# endif
# pragma GCC diagnostic ignored "-Wold-style-cast"
# endif
#endif
#define REQUIRES_C99(X) X
#define closesocket close
//A patch to man-defined but non existing gettid() function
static inline int __gettid()
{
int i = (pid_t)syscall(SYS_gettid);
if(i == -1) {
assert(!"(pid_t)syscall(SYS_gettid) returns -1 on this platform");
abort();
}
return i;
}
//#define __gettid() 0
/* Platform specific stuff, mainly for copying pointers to/from i64 variables */
/* FIXME: conditional may need changing/extending for new targets */
#ifdef __x86_64__ /* pointer is 64 bits */
#define POINTER_IS64BITS 1
#else /* __x86_64__ */
#define POINTER_IS64BITS 0
#endif /* __x86_64__ */
/* It would also be good if an ASSERT could check that this is set
* correctly during the initialisation of every executable.
* eg: ASSERT(POINTER_IS64BITS == (sizeof(void *) == 8));
*/
/* macros to convert pointer to/from uint64_t based on POINTER_IS64BITS */
#if POINTER_IS64BITS
#define PTR_AS_U64(p) ((uint64_t)(p))
#define PTR_FROM_U64(i) ((void *)(i))
#else /* POINTER_IS64BITS */
#define PTR_AS_U64(p) ((uint64_t)(uint32_t)(p))
#define PTR_FROM_U64(i) ((void *)(uint32_t)(i))
#endif /* POINTER_IS64BITS */
static inline int64_t GetFileSize64 (const char *Filename)
{
struct stat stat_buf;
if (stat(Filename, &stat_buf))
return -1;
return stat_buf.st_size;
}
static inline int CPUAffinityGetPossible (uint64_t *Mask, uint32_t *Count)
{
int total_cores = (int)sysconf (_SC_NPROCESSORS_ONLN);
if (total_cores == -1)
return -1;
*Count = (uint32_t)total_cores;
if (total_cores < 64)
{
*Mask = ((uint64_t)1 << *Count) - 1;
}
else
{
*Mask = ~0ULL;
}
return 0;
}
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
# pragma GCC diagnostic pop
#endif
#endif