1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-04 18:06:22 +03:00

0025215: Porting to Android - fix minor issues

STEPConstruct_AP203Context = pw_gecos member of passwd struct disabled in android case.
Standard_Atomic - correct usage of __atomic_inc()/__atomic_dec().
Standard_CLocaleSentry - Android doesn't support locales in the C library.
Standard_MMgrOpt - use "/dev/zero" and "/dev/null" for allocation of memory blocks on Android.
OSD_Chronometer - fix compilation on Android.
OSD_Disk, OSD_signal - fix headers inclusion on Android.
This commit is contained in:
kgv 2014-09-05 14:27:01 +04:00 committed by bugmaster
parent aaf512f112
commit 9bf6baed3c
8 changed files with 49 additions and 23 deletions

View File

@ -57,7 +57,7 @@
//=======================================================================
void OSD_Chronometer::GetProcessCPU (Standard_Real& UserSeconds, Standard_Real& SystemSeconds)
{
#if defined(LIN) || defined(linux) || defined(__FreeBSD__)
#if defined(LIN) || defined(linux) || defined(__FreeBSD__) || defined(__ANDROID__)
static const long aCLK_TCK = sysconf(_SC_CLK_TCK);
#else
static const long aCLK_TCK = CLK_TCK;
@ -87,7 +87,7 @@ void OSD_Chronometer::GetThreadCPU (Standard_Real& theUserSeconds,
theUserSeconds = Standard_Real(aTaskInfo.user_time.seconds) + 0.000001 * aTaskInfo.user_time.microseconds;
theSystemSeconds = Standard_Real(aTaskInfo.system_time.seconds) + 0.000001 * aTaskInfo.system_time.microseconds;
}
#elif defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)
#elif (defined(_POSIX_TIMERS) && defined(_POSIX_THREAD_CPUTIME)) || defined(__ANDROID__)
// on Linux, only user times are available for threads via clock_gettime()
struct timespec t;
if (!clock_gettime (CLOCK_THREAD_CPUTIME_ID, &t))

View File

@ -12,7 +12,7 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef WNT
#ifndef _WIN32
#include <OSD_Disk.ixx>
#include <OSD_WhoAmI.hxx>
@ -23,7 +23,14 @@ const OSD_WhoAmI Iam = OSD_WDisk;
extern "C" {
#endif
#if defined(__ANDROID__)
#include <sys/vfs.h>
#define statvfs statfs
#define fstatvfs fstatfs
#else
#include <sys/statvfs.h>
int statvfs(const char *, struct statvfs *);
#endif
#ifdef __cplusplus
}
@ -31,8 +38,6 @@ extern "C" {
#include <errno.h>
extern "C" {int statvfs(const char *, struct statvfs *); }
OSD_Disk::OSD_Disk() : myQuotaSize(0) {}

View File

@ -13,7 +13,7 @@
#include <OSD.ixx>
#ifndef WNT
#ifndef _WIN32
//---------- All Systems except Windows NT : ----------------------------------
@ -68,7 +68,10 @@ typedef void (* SIG_PFV) (int);
typedef void (* SIG_PFV) (int);
#include <signal.h>
#if !defined(__ANDROID__)
#include <sys/signal.h>
#endif
#if defined(HAVE_PTHREAD_H) && defined(NO_CXX_EXCEPTION)
//============================================================================

View File

@ -167,7 +167,7 @@ Handle(StepBasic_PersonAndOrganization) STEPConstruct_AP203Context::DefaultPerso
// construct person`s name
OSD_Process sys;
Standard_CString usr = sys.UserName().ToCString();
#ifndef WNT
#if !defined(_WIN32) && !defined(__ANDROID__)
if ( usr ) {
struct passwd *pwd = getpwnam ( usr );
if ( pwd ) usr = pwd->pw_gecos;

View File

@ -27,10 +27,6 @@
#ifndef _Standard_Atomic_HeaderFile
#define _Standard_Atomic_HeaderFile
#if defined(__ANDROID__)
#include <sys/atomics.h>
#endif
//! Increments atomically integer variable pointed by theValue
//! and returns resulting incremented value.
inline int Standard_Atomic_Increment (volatile int* theValue);
@ -59,7 +55,7 @@ int Standard_Atomic_Decrement (volatile int* theValue)
return __sync_sub_and_fetch (theValue, 1);
}
#elif defined(_WIN32) || defined(__WIN32__)
#elif defined(_WIN32)
extern "C" {
long _InterlockedIncrement (volatile long* lpAddend);
long _InterlockedDecrement (volatile long* lpAddend);
@ -100,20 +96,22 @@ int Standard_Atomic_Decrement (volatile int* theValue)
}
#elif defined(__ANDROID__)
// Atomic operations that were exported by the C library didn't
// provide any memory barriers, which created potential issues on
// multi-core devices. Starting from ndk version r7b they are defined as
// inlined calls to GCC sync builtins, which always provide a full barrier.
// It is strongly recommended to use newer versions of ndk.
#include <sys/atomics.h>
int Standard_Atomic_Increment (volatile int* theValue)
{
return __atomic_inc (theValue);
return __atomic_inc (theValue) + 1; // analog of __sync_fetch_and_add
}
int Standard_Atomic_Decrement (volatile int* theValue)
{
return __atomic_dec (theValue);
return __atomic_dec (theValue) - 1; // analog of __sync_fetch_and_sub
}
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64))

View File

@ -19,6 +19,8 @@
#include <cstring>
#if !defined(__ANDROID__)
namespace
{
@ -79,9 +81,10 @@ Standard_CLocaleSentry::Standard_CLocaleSentry()
#endif
#endif
{
#ifndef HAVE_XLOCALE_H
#if !defined(HAVE_XLOCALE_H)
const char* aPrevLocale = (const char* )myPrevLocale;
if (aPrevLocale[0] == 'C' && aPrevLocale[1] == '\0')
if (myPrevLocale == NULL
|| (aPrevLocale[0] == 'C' && aPrevLocale[1] == '\0'))
{
myPrevLocale = NULL; // already C locale
return;
@ -101,7 +104,7 @@ Standard_CLocaleSentry::Standard_CLocaleSentry()
// =======================================================================
Standard_CLocaleSentry::~Standard_CLocaleSentry()
{
#ifdef HAVE_XLOCALE_H
#if defined(HAVE_XLOCALE_H)
uselocale ((locale_t )myPrevLocale);
#else
if (myPrevLocale != NULL)
@ -118,3 +121,5 @@ Standard_CLocaleSentry::~Standard_CLocaleSentry()
#endif
#endif
}
#endif // __ANDROID__

View File

@ -39,6 +39,8 @@
#include <xlocale.h>
#endif
#if !defined(__ANDROID__)
//! This class intended to temporary switch C locale and logically equivalent to setlocale(LC_ALL, "C").
//! It is intended to format text regardless of user locale settings (for import/export functionality).
//! Thus following calls to sprintf, atoi and other functions will use "C" locale.
@ -57,7 +59,7 @@ public:
Standard_EXPORT Standard_CLocaleSentry();
//! Restore previous locale.
Standard_EXPORT virtual ~Standard_CLocaleSentry();
Standard_EXPORT ~Standard_CLocaleSentry();
public:
@ -88,4 +90,17 @@ private:
};
#else
//! C/C++ runtime on Android currently supports only C-locale, no need to call anything.
class Standard_CLocaleSentry
{
public:
Standard_CLocaleSentry() {}
typedef void* clocale_t;
static clocale_t GetCLocale() { return 0; }
};
#endif // __ANDROID__
#endif // _Standard_CLocaleSentry_H__

View File

@ -247,7 +247,7 @@ void Standard_MMgrOpt::Initialize()
perror("ERR_MEMRY_FAIL");
#endif
#if defined(IRIX) || defined(__sgi) || defined(SOLARIS) || defined(__sun) || defined(LIN) || defined(linux) || defined(__FreeBSD__)
#if defined(IRIX) || defined(__sgi) || defined(SOLARIS) || defined(__sun) || defined(LIN) || defined(linux) || defined(__FreeBSD__) || defined(__ANDROID__)
if ((myMMap = open ("/dev/zero", O_RDWR)) < 0) {
if ((myMMap = open ("/dev/null", O_RDWR)) < 0){
myMMap = 0;