add usd-21-11-win64_py39

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:43:55 +01:00
1 parent 41d23e71ba
commit ba5e1f7e67
15684 files changed
+3069957

No files matched your search

+90
View File
@@ -0,0 +1,90 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_ALIGN_H
#define PXR_BASE_ARCH_ALIGN_H
/// \file arch/align.h
/// \ingroup group_arch_Memory
/// Provide architecture-specific memory-alignment information.
#if !defined(__cplusplus)
#error This include file can only be included in C++ programs.
#endif
#include "pxr/pxr.h"
#include "pxr/base/arch/defines.h"
#include <cstddef>
#include <cstdint>
PXR_NAMESPACE_OPEN_SCOPE
/// \addtogroup group_arch_Memory
///@{
/// Return suitably aligned memory size.
///
/// Requests to \c malloc() or \c ::new for a given size are often rounded
/// upward. Given a request for \c nBytes bytes of storage, this function
/// returns the amount that would actually be consumed by the system to
/// satisfy it. This is needed for efficient user-defined memory management.
///
inline size_t
ArchAlignMemorySize(size_t nBytes) {
return (nBytes + 7) & (~0x7);
}
/// Maximum extra space needed for alignment.
///
/// The \c ArchAlignMemorySize() can increase the required memory by no more
/// than \c ARCH_MAX_ALIGNMENT_INCREASE.
///
/// \hideinitializer
#define ARCH_MAX_ALIGNMENT_INCREASE 7
/// Align memory to the next "best" alignment value.
///
/// This will take a pointer and bump it to the next ideal alignment boundary
/// that will work for all data types.
///
inline void *
ArchAlignMemory(void *base)
{
return reinterpret_cast<void *>
((reinterpret_cast<uintptr_t>(base) + 7) & ~0x7);
}
/// The size of a CPU cache line on the current processor architecture in bytes.
///
/// \hideinitializer
#if defined(ARCH_OS_DARWIN) && defined(ARCH_CPU_ARM)
#define ARCH_CACHE_LINE_SIZE 128
#else
#define ARCH_CACHE_LINE_SIZE 64
#endif
///@}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_ALIGN_H
+47
View File
@@ -0,0 +1,47 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_API_H
#define PXR_BASE_ARCH_API_H
#include "pxr/base/arch/export.h"
#if defined(PXR_STATIC)
# define ARCH_API
# define ARCH_API_TEMPLATE_CLASS(...)
# define ARCH_API_TEMPLATE_STRUCT(...)
# define ARCH_LOCAL
#else
# if defined(ARCH_EXPORTS)
# define ARCH_API ARCH_EXPORT
# define ARCH_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
# define ARCH_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
# else
# define ARCH_API ARCH_IMPORT
# define ARCH_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
# define ARCH_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
# endif
# define ARCH_LOCAL ARCH_HIDDEN
#endif
#endif
+335
View File
@@ -0,0 +1,335 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_ATTRIBUTES_H
#define PXR_BASE_ARCH_ATTRIBUTES_H
/// \file arch/attributes.h
/// Define function attributes.
///
/// This file allows you to define architecture-specific or compiler-specific
/// options to be used outside lib/arch.
#include "pxr/pxr.h"
#include "pxr/base/arch/export.h"
PXR_NAMESPACE_OPEN_SCOPE
#if defined(doxygen)
/// Macro used to indicate a function takes a printf-like specification.
///
/// This attribute is used as follows:
/// \code
/// void PrintFunc(T1 arg1, T2 arg2, const char* fmt, ...)
/// ARCH_PRINTF_FUNCTION(3, 4)
/// \endcode
/// This indicates that the third argument is the format string, and that the
/// fourth argument is where the var-args corresponding to the format string begin.
///
/// \hideinitializer
# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
/// Macro used to indicate a function takes a scanf-like specification.
///
/// This attribute is used as follows:
/// \code
/// void ScanFunc(T1 arg1, T2 arg2, const char* fmt, ...)
/// ARCH_PRINTF_FUNCTION(3, 4)
/// \endcode
/// This indicates that the third argument is the format string, and
/// that the fourth argument is where the var-args corresponding to the
/// format string begin.
///
/// \hideinitializer
# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
/// Macro used to indicate that a function should never be inlined.
///
/// This attribute is used as follows:
/// \code
/// void Func(T1 arg1, T2 arg2) ARCH_NOINLINE;
/// \endcode
///
/// \hideinitializer
# define ARCH_NOINLINE
/// Macro used to indicate a function parameter may be unused.
///
/// In general, avoid this attribute if possible. Mostly this attribute
/// should be used when the set of arguments to a function is described
/// as part of a macro. The usage is:
/// \code
/// void Func(T1 arg1, ARCH_UNUSED_ARG T2 arg2, ARCH_UNUSED_ARG T3 arg3, T4 arg4) {
/// ...
/// }
/// \endcode
///
/// \hideinitializer
# define ARCH_UNUSED_ARG
/// Macro used to indicate a function may be unused.
///
/// In general, avoid this attribute if possible. Mostly this attribute
/// should be used when you need to keep a function around (for some
/// good reason), but it is not used in the rest of the code. The usage
/// is:
/// \code
/// ARCH_UNUSED_FUNCTION void Func() {
/// ...
/// }
/// \endcode
///
/// \hideinitializer
# define ARCH_UNUSED_FUNCTION
/// Macro used to indicate that a function's code must always be emitted even
/// if not required.
///
/// This attribute is especially useful with templated registration functions,
/// which might not be present in the linked binary if they are not used (or
/// the compiler optimizes away their use.)
///
/// The usage is:
/// \code
/// template <typename T>
/// struct TraitsClass {
/// static void RegistryFunction() ARCH_USED_FUNCTION {
/// ...
/// }
/// };
/// \endcode
///
/// \hideinitializer
# define ARCH_USED_FUNCTION
/// Macro to begin the definition of a function that should be executed by
/// the dynamic loader when the dynamic object (library or program) is
/// loaded.
///
/// \p _priority is used to order the execution of constructors. Valid
/// values are integers in the range [0,255]. Constructors with lower
/// numbers are run first. It is unspecified if these functions are run
/// before or after dynamic initialization of non-local variables.
///
/// \p _name is the name of the function and must be unique across all
/// invocations of ARCH_CONSTRUCTOR in the same translation unit.
/// The remaining arguments should be types for the signature of the
/// function. The types are only to make the name unique (when mangled);
/// the function will be called with no arguments so the arguments must
/// not be used. If you don't need any arguments you must use void.
///
/// \hideinitializer
# define ARCH_CONSTRUCTOR(_name, _priority, ...)
/// Macro to begin the definition of a function that should be executed by
/// the dynamic loader when the dynamic object (library or program) is
/// unloaded.
///
/// \p _priority is used to order the execution of destructors. Valid
/// values are integers in the range [0,255]. Destructors with higher
/// numbers are run first. It is unspecified if these functions are run
/// before or after dynamically initialized non-local variables.
///
/// \p _name is the name of the function and must be unique across all
/// invocations of ARCH_CONSTRUCTOR in the same translation unit.
/// The remaining arguments should be types for the signature of the
/// function. The types are only to make the name unique (when mangled);
/// the function will be called with no arguments so the arguments must
/// not be used. If you don't need any arguments you must use void.
///
/// \hideinitializer
# define ARCH_DESTRUCTOR(_name, _priority, ...)
#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg) \
__attribute__((format(printf, _fmt, _firstArg)))
# define ARCH_SCANF_FUNCTION(_fmt, _firstArg) \
__attribute__((format(scanf, _fmt, _firstArg)))
# define ARCH_NOINLINE __attribute__((noinline))
# define ARCH_UNUSED_ARG __attribute__ ((unused))
# define ARCH_UNUSED_FUNCTION __attribute__((unused))
# define ARCH_USED_FUNCTION __attribute__((used))
#elif defined(ARCH_COMPILER_MSVC)
# define ARCH_PRINTF_FUNCTION(_fmt, _firstArg)
# define ARCH_SCANF_FUNCTION(_fmt, _firstArg)
# define ARCH_NOINLINE // __declspec(noinline)
# define ARCH_UNUSED_ARG
# define ARCH_UNUSED_FUNCTION
# define ARCH_USED_FUNCTION
#else
// Leave macros undefined so we'll fail to build on a new system/compiler
// rather than fail mysteriously at runtime.
#endif
// Helper to do on-demand static initialziation. We need to insert per-library
// static initializers if the ARCH_CONSTRUCTOR macros are used, etc, but we
// don't want that to happen otherwise. This mechanism makes that possible. It
// works by creating a class template (Arch_PerLibInit) that has hidden
// visibility and a static member of its template parameter (StaticInit). In
// its constructor, it "uses" its static member 'init', in order to ensure it
// gets instantiated. Since it's a static member, it gets initialized only if
// it's instantiated. This lets us have macros like ARCH_CONSTRUCTOR() that
// require a static initializer, but to only emit that static initializer in
// translation units that actually invoke the macro. Clients typically do this
// by way of the _ARCH_ENSURE_PER_LIB_INIT macro. This is tested on all current
// supported compilers (clang, gcc, msvc). The hidden visibility is required to
// ensure that each library gets its own initialization. Without it, on Linux,
// there would be exactly *one* initialization no matter how many libraries are
// loaded.
template <class StaticInit>
struct ARCH_HIDDEN Arch_PerLibInit {
Arch_PerLibInit() { /* "use" of init here forces instantiation */
(void)init; }
private:
static StaticInit init;
};
template <class StaticInit>
StaticInit Arch_PerLibInit<StaticInit>::init;
#define _ARCH_CAT_NOEXPAND(a, b) a ## b
#define _ARCH_CAT(a, b) _ARCH_CAT_NOEXPAND(a, b)
#define _ARCH_ENSURE_PER_LIB_INIT(T, prefix) \
static Arch_PerLibInit<T> _ARCH_CAT(prefix, __COUNTER__)
#if defined(doxygen)
// The macros are already defined above in doxygen.
#elif defined(ARCH_OS_DARWIN)
// Entry for a constructor/destructor in the custom section.
struct Arch_ConstructorEntry {
typedef void (*Type)(void);
Type function;
unsigned int version:24; // USD version
unsigned int priority:8; // Priority of function
};
// Emit a Arch_ConstructorEntry in the __Data,pxrctor section.
# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
static void _name(__VA_ARGS__); \
static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_ctor_, _name) \
__attribute__((used, section("__DATA,pxrctor"))) = { \
reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
0u, \
_priority \
}; \
static void _name(__VA_ARGS__)
// Emit a Arch_ConstructorEntry in the __Data,pxrdtor section.
# define ARCH_DESTRUCTOR(_name, _priority, ...) \
static void _name(__VA_ARGS__); \
static const Arch_ConstructorEntry _ARCH_CAT_NOEXPAND(arch_dtor_, _name) \
__attribute__((used, section("__DATA,pxrdtor"))) = { \
reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
0u, \
_priority \
}; \
static void _name(__VA_ARGS__)
#elif defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
// The used attribute is required to prevent these apparently unused functions
// from being removed by the linker.
# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
__attribute__((used, section(".pxrctor"), constructor((_priority) + 100))) \
static void _name(__VA_ARGS__)
# define ARCH_DESTRUCTOR(_name, _priority, ...) \
__attribute__((used, section(".pxrdtor"), destructor((_priority) + 100))) \
static void _name(__VA_ARGS__)
#elif defined(ARCH_OS_WINDOWS)
# include "pxr/base/arch/api.h"
// Entry for a constructor/destructor in the custom section.
__declspec(align(16))
struct Arch_ConstructorEntry {
typedef void (__cdecl *Type)(void);
Type function;
unsigned int version:24; // USD version
unsigned int priority:8; // Priority of function
};
// Declare the special sections.
# pragma section(".pxrctor", read)
# pragma section(".pxrdtor", read)
// Objects of this type run the ARCH_CONSTRUCTOR and ARCH_DESTRUCTOR functions
// for the library containing the object in the c'tor and d'tor, respectively.
// Each HMODULE is handled at most once.
struct Arch_ConstructorInit {
ARCH_API Arch_ConstructorInit();
ARCH_API ~Arch_ConstructorInit();
};
// Emit a Arch_ConstructorEntry in the .pxrctor section. The namespace and
// extern are to convince the compiler and linker to leave the object in the
// final library/executable instead of stripping it out. In clang/gcc we use
// __attribute__((used)) to do that.
# define ARCH_CONSTRUCTOR(_name, _priority, ...) \
static void _name(__VA_ARGS__); \
namespace { \
__declspec(allocate(".pxrctor")) \
extern const Arch_ConstructorEntry \
_ARCH_CAT_NOEXPAND(arch_ctor_, _name) = { \
reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
0u, \
_priority \
}; \
} \
_ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
static void _name(__VA_ARGS__)
// Emit a Arch_ConstructorEntry in the .pxrdtor section.
# define ARCH_DESTRUCTOR(_name, _priority, ...) \
static void _name(__VA_ARGS__); \
namespace { \
__declspec(allocate(".pxrdtor")) \
extern const Arch_ConstructorEntry \
_ARCH_CAT_NOEXPAND(arch_dtor_, _name) = { \
reinterpret_cast<Arch_ConstructorEntry::Type>(&_name), \
0u, \
_priority \
}; \
} \
_ARCH_ENSURE_PER_LIB_INIT(Arch_ConstructorInit, _archCtorInit); \
static void _name(__VA_ARGS__)
#else
// Leave macros undefined so we'll fail to build on a new system/compiler
// rather than fail mysteriously at runtime.
#endif
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_ATTRIBUTES_H
+47
View File
@@ -0,0 +1,47 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_BUILD_MODE_H
#define PXR_BASE_ARCH_BUILD_MODE_H
#include "pxr/pxr.h"
#include "pxr/base/arch/defines.h"
PXR_NAMESPACE_OPEN_SCOPE
struct ArchBuildMode {
// Check if the build system has specified a build mode, falling
// back to commonly-used macros if it has not. (Typically, _DEBUG
// is defined by Visual Studio and DEBUG by Xcode for debug-mode builds)
#if defined(BUILD_OPTLEVEL_DEV) || defined(_DEBUG) || defined(DEBUG)
enum { DEV_BUILD = 1 };
#else
enum { DEV_BUILD = 0 };
#endif
};
#define ARCH_DEV_BUILD ArchBuildMode::DEV_BUILD
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_BUILD_MODE_H
+68
View File
@@ -0,0 +1,68 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_DAEMON_H
#define PXR_BASE_ARCH_DAEMON_H
/// \file arch/daemon.h
/// \ingroup group_arch_Multithreading
/// Create background or daemon processes.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
PXR_NAMESPACE_OPEN_SCOPE
/// Close all file descriptors (with possible exceptions)
///
/// \c ArchCloseAllFiles will close all file descriptors open in the
/// current process. Occasionally you'd like to close all files except
/// for some small subset (like 0, 1, and 2). The \p nExcept and \p
/// exceptFds arguments can be used to provide the list of exceptions.
/// \c ArchDaemonizeProcess uses this method to close all unwanted file
/// descriptors in the daemon process.
///
/// \p nExcept should be the number of elements in the \p exceptFds array.
/// Invalid file descriptors in exceptFds are ignored.
///
/// \note Be \b very careful when using this routine. It is intended
/// to be used after a \c fork(2) call to close \b all unwanted file
/// descriptors. However, it does not flush stdio buffers, wait for
/// processes opened with popen, shut down the X11 display connection,
/// or anything. It just slams closed all the file descriptors. This
/// is appropriate following a \c fork(2) call as all these file
/// descriptors are duplicates of the ones in the parent process and
/// shutting down the X11 display connection would mess up the parent's
/// X11 display. But you shouldn't use \c ArchCloseAllFiles unless you
/// know what you are doing.
///
/// \return -1 on error and \c errno will be set to an appropriate
/// value. Returns 0 on success.
///
/// \ingroup group_arch_Multithreading
ARCH_API
int ArchCloseAllFiles(int nExcept, const int* exceptFds);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_DAEMON_H
+111
View File
@@ -0,0 +1,111 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_DEBUGGER_H
#define PXR_BASE_ARCH_DEBUGGER_H
/// \file arch/debugger.h
/// Routines for interacting with a debugger.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include "pxr/base/arch/attributes.h"
PXR_NAMESPACE_OPEN_SCOPE
/// Stop in a debugger.
///
/// This function will do one of the following: start a debugger
/// attached to this process stopped on this function; stop in an
/// already attached debugger; stop and wait for a debugger to
/// attach, or nothing.
///
/// On Linux this will start a debugger using \c ArchDebuggerAttach()
/// if no debugger is attached. If a debugger is (or was) attached it
/// will stop on this function due to \c SIGTRAP. Alternatively, users
/// can configure the debugger to not stop on \c SIGTRAP and instead
/// break on \c ArchDebuggerTrap().
///
/// If a debugger is not attached, \c ArchDebuggerAttach() does not
/// attach one, and \c ArchDebuggerWait() has been most recently
/// called with \c true then this will wait for a debugger to attach,
/// otherwise it does nothing and the process does not stop. The user
/// can continue the process from the debugger simply by issuing the
/// continue command. The user can also continue the process from an
/// attached terminal by putting the process into the foreground or
/// background.
///
ARCH_API
void ArchDebuggerTrap() ARCH_NOINLINE;
/// Cause debug traps to wait for the debugger or not.
///
/// When \p wait is \c true the next call to \c ArchDebuggerTrap()
/// will cause the process to wait for a signal. The user can attach
/// a debugger to continue the process. The process will not wait
/// again until another call to this function with \p wait \c true.
///
ARCH_API
void ArchDebuggerWait(bool wait);
/// Attach a debugger.
///
/// Attaches the debugger by running the contents of the enviroment variable
/// ARCH_DEBUGGER using /bin/sh. Any '%p' in the contents of this variable
/// will be replaced with the process id of the process launching the debugger.
/// Any '%e' will be replaced with the path to the executable for the process.
///
/// Returns true if ARCH_DEBUGGER is set and the debugger was successfully
/// launched, otherwise returns false.
ARCH_API
bool ArchDebuggerAttach() ARCH_NOINLINE;
/// Test if a debugger is attached
///
/// Attempts to detect if a debugger is currently attached to the process.
ARCH_API
bool ArchDebuggerIsAttached() ARCH_NOINLINE;
/// Abort. This will try to avoid the JIT debugger if any if ARCH_AVOID_JIT
/// is in the environment and the debugger isn't already attached. In that
/// case it will _exit(134). If \p logging is \c false then this will
/// attempt to bypass any crash logging.
[[noreturn]]
ARCH_API
void ArchAbort(bool logging = true);
/// Stop in the debugger.
///
/// This macro expands to \c ArchDebuggerTrap() and, if necessary and
/// possible, code to prevent optimization so the caller appears in the
/// debugger's stack trace. The calling functions should also use the
/// \c ARCH_NOINLINE function attribute.
#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
#define ARCH_DEBUGGER_TRAP do { ArchDebuggerTrap(); asm(""); } while (0)
#else
#define ARCH_DEBUGGER_TRAP do { ArchDebuggerTrap(); } while (0)
#endif
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_DEBUGGER_H
+113
View File
@@ -0,0 +1,113 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_DEFINES_H
#define PXR_BASE_ARCH_DEFINES_H
#include "pxr/pxr.h"
PXR_NAMESPACE_OPEN_SCOPE
//
// OS
//
#if defined(__linux__)
#define ARCH_OS_LINUX
#elif defined(__APPLE__)
#include "TargetConditionals.h"
#define ARCH_OS_DARWIN
#if TARGET_OS_IPHONE
#define ARCH_OS_IOS
#else
#define ARCH_OS_OSX
#endif
#elif defined(_WIN32) || defined(_WIN64)
#define ARCH_OS_WINDOWS
#endif
//
// Processor
//
#if defined(i386) || defined(__i386__) || defined(__x86_64__) || \
defined(_M_IX86) || defined(_M_X64)
#define ARCH_CPU_INTEL
#elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM)
#define ARCH_CPU_ARM
#endif
//
// Bits
//
#if defined(__x86_64__) || defined(__aarch64__) || defined(_M_X64)
#define ARCH_BITS_64
#else
#error "Unsupported architecture. x86_64 or ARM64 required."
#endif
//
// Compiler
//
#if defined(__clang__)
#define ARCH_COMPILER_CLANG
#define ARCH_COMPILER_CLANG_MAJOR __clang_major__
#define ARCH_COMPILER_CLANG_MINOR __clang_minor__
#define ARCH_COMPILER_CLANG_PATCHLEVEL __clang_patchlevel__
#elif defined(__GNUC__)
#define ARCH_COMPILER_GCC
#define ARCH_COMPILER_GCC_MAJOR __GNUC__
#define ARCH_COMPILER_GCC_MINOR __GNUC_MINOR__
#define ARCH_COMPILER_GCC_PATCHLEVEL __GNUC_PATCHLEVEL__
#elif defined(__ICC)
#define ARCH_COMPILER_ICC
#elif defined(_MSC_VER)
#define ARCH_COMPILER_MSVC
#define ARCH_COMPILER_MSVC_VERSION _MSC_VER
#endif
//
// Features
//
// Only use the GNU STL extensions on Linux when using gcc.
#if defined(ARCH_OS_LINUX) && defined(ARCH_COMPILER_GCC)
#define ARCH_HAS_GNU_STL_EXTENSIONS
#endif
// The current version of Apple clang does not support the thread_local
// keyword.
#if !(defined(ARCH_OS_DARWIN) && defined(ARCH_COMPILER_CLANG))
#define ARCH_HAS_THREAD_LOCAL
#endif
// The MAP_POPULATE flag for mmap calls only exists on Linux platforms.
#if defined(ARCH_OS_LINUX)
#define ARCH_HAS_MMAP_MAP_POPULATE
#endif
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_DEFINES_H
+115
View File
@@ -0,0 +1,115 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_DEMANGLE_H
#define PXR_BASE_ARCH_DEMANGLE_H
#if !defined(__cplusplus)
#error This include file can only be included in C++ programs.
#endif
/// \file arch/demangle.h
/// \ingroup group_arch_Strings
/// Demangle C++ typenames generated by the \c typeid() facility.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <string>
#include <typeinfo>
#include <typeindex>
PXR_NAMESPACE_OPEN_SCOPE
/// \addtogroup group_arch_Strings
///@{
/// Demangle RTTI-generated type name.
///
/// Given a variable \c v, the construct \c typeid(v).name() returns
/// the type-name of \c v; unfortunately, the returned type-name is
/// sometimes extremely encoded (otherwise known as "mangled").
/// \c ArchDemangle parses the passed in type-name \c typeName into a
/// readable form, and overwrites \c typeName. If \c typeName
/// cannot be unmangled, the function returns \c false without altering
/// \c typeName. Otherwise \c true is returned.
ARCH_API bool ArchDemangle(std::string* typeName);
/// Return demangled RTTI-generated type name.
///
/// If \c typeName can be demangled, the function returns the demangled
/// string; otherwise, the function returns the empty string.
///
/// \see ArchDemangle()
ARCH_API std::string
ArchGetDemangled(const std::string& typeName);
/// Return demangled RTTI-generated type name.
///
/// \see ArchDemangle()
/// \overload
ARCH_API std::string
ArchGetDemangled(const char *typeName);
/// Return demangled RTTI-generated type name.
///
/// Returns the demangled name associated with typeInfo (i.e. typeInfo.name()).
///
/// \see ArchDemangle()
/// \overload
inline std::string
ArchGetDemangled(const std::type_info& typeInfo) {
return ArchGetDemangled(typeInfo.name());
}
/// Return demangled RTTI-generated type name.
///
/// Returns the demangled name associated with typeIndex (i.e. typeIndex.name()).
///
/// \see ArchDemangle()
/// \overload
inline std::string
ArchGetDemangled(const std::type_index& typeIndex) {
return ArchGetDemangled(typeIndex.name());
}
/// Return demangled RTTI generated-type name.
///
/// Returns the demangled name of type T.
///
/// \see ArchDemangle()
/// \overload
template <typename T>
inline std::string
ArchGetDemangled() {
return ArchGetDemangled(typeid(T).name());
}
///@}
/// \private
ARCH_API
void Arch_DemangleFunctionName(std::string* functionName);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_DEMANGLE_H
+89
View File
@@ -0,0 +1,89 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_ENV_H
#define PXR_BASE_ARCH_ENV_H
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
///
/// Architecture dependent access to environment variables.
/// \ingroup group_arch_SystemFunctions
///
///
/// Returns \c true if and only if the current environment contains \c name.
/// \ingroup group_arch_SystemFunctions
///
ARCH_API
bool
ArchHasEnv(const std::string &name);
///
/// Gets a value from the current environment identified by \c name.
/// \ingroup group_arch_SystemFunctions
///
ARCH_API
std::string
ArchGetEnv(const std::string &name);
///
/// Creates or modifies an environment variable.
/// \ingroup group_arch_SystemFunctions
///
ARCH_API
bool
ArchSetEnv(const std::string &name, const std::string &value, bool overwrite);
///
/// Removes an environment variable.
/// \ingroup group_arch_SystemFunctions
///
ARCH_API
bool
ArchRemoveEnv(const std::string &name);
///
/// Expands environment variables in \c str.
/// \ingroup group_arch_SystemFunctions
///
ARCH_API
std::string
ArchExpandEnvironmentVariables(const std::string& str);
///
/// Return an array of the environment variables.
/// \ingroup group_arch_SystemFunctions
///
ARCH_API
char**
ArchEnviron();
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_ENV_H
+64
View File
@@ -0,0 +1,64 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_ERRNO_H
#define PXR_BASE_ARCH_ERRNO_H
/// \file arch/errno.h
/// \ingroup group_arch_SystemFunctions
/// Functions for dealing with system errors.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
/// \addtogroup group_arch_SystemFunctions
///@{
/// Return the error string for the current value of errno.
///
/// This function provides a thread-safe method of fetching the error string
/// from errno. POSIX.1c defines errno as a macro which provides access to a
/// thread-local integer. This function is thread-safe.
/// \overload
ARCH_API std::string ArchStrerror();
/// Return the error string for the specified value of errno.
///
/// This function is thread-safe.
ARCH_API std::string ArchStrerror(int errorCode);
#if defined(ARCH_OS_WINDOWS)
/// Return the error string for the specified error code.
///
/// This function is thread-safe.
ARCH_API std::string ArchStrSysError(unsigned long errorCode);
#endif
///@}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_ERRNO_H
+92
View File
@@ -0,0 +1,92 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_ERROR_H
#define PXR_BASE_ARCH_ERROR_H
/// \file arch/error.h
/// \ingroup group_arch_Diagnostics
/// Low-level fatal error reporting.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include "pxr/base/arch/defines.h"
#include "pxr/base/arch/functionLite.h"
#include <stddef.h>
PXR_NAMESPACE_OPEN_SCOPE
/// Print message to standard error and abort program.
///
/// \param msg The reason for the failure.
/// \param funcName The name of the function that \c Arch_Error was called from.
/// \param lineNo The line number of the file that \c Arch_Error was called from.
/// \param fileName The name of the file that \c Arch_Error was called from.
///
/// \private
[[noreturn]]
ARCH_API
void Arch_Error(const char* msg, const char* funcName,
size_t lineNo, const char* fileName);
/// Print warning message to standard error, but continue execution.
///
/// \param msg The reason for the warning.
/// \param funcName The name of the function that \c Arch_Warning was called from.
/// \param lineNo The line number of the file that \c Arch_Warning was called from.
/// \param fileName The name of the file that \c Arch_Warning was called from.
///
/// \private
ARCH_API
void Arch_Warning(const char* msg, const char* funcName,
size_t lineNo, const char* fileName);
/// \addtogroup group_arch_Diagnostics
///@{
/// Unconditionally aborts the program.
///
/// \param msg is a literal string, a \c const \c char* (but not
/// an \c std::string) that describes why the program is aborting.
/// \hideinitializer
#define ARCH_ERROR(msg) \
Arch_Error(msg, __ARCH_FUNCTION__, __LINE__, __ARCH_FILE__)
/// Prints a warning message to stderr.
///
/// \param msg is a literal string, a \c const \c char* (but not
/// an \c std::string).
/// \hideinitializer
#define ARCH_WARNING(msg) \
Arch_Warning(msg, __ARCH_FUNCTION__, __LINE__, __ARCH_FILE__)
/// Aborts the program if \p cond evaluates to false.
/// \hideinitializer
#define ARCH_AXIOM(cond) \
if (!(cond)) ARCH_ERROR("[" #cond "] axiom failed")
///@}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_ERROR_H
+189
View File
@@ -0,0 +1,189 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_EXPORT_H
#define PXR_BASE_ARCH_EXPORT_H
/// \file arch/export.h
/// \ingroup group_arch_SymbolVisibility
///
/// Defines symbol visibility macros.
///
/// Defines \c ARCH_EXPORT to indicate a symbol should be exported from
/// a library, \c ARCH_IMPORT to indicate an exported symbol should be
/// imported (which only matters on Windows), and \c ARCH_HIDDEN to
/// indicate that a symbol which would be exported should not be.
///
/// The correct way to use these macros is for each library to make a
/// header that looks like this (for some hypothetical library named foo):
///
/// \code
/// #ifndef FOO_API_H
/// #define FOO_API_H
///
/// #include "pxr/base/arch/export.h"
///
/// #if defined(FOO_STATIC)
/// # define FOO_API
/// # define FOO_API_TEMPLATE_CLASS(...)
/// # define FOO_API_TEMPLATE_STRUCT(...)
/// # define FOO_LOCAL
/// #else
/// # if defined(FOO_EXPORTS)
/// # define FOO_API ARCH_EXPORT
/// # define FOO_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
/// # define FOO_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
/// # else
/// # define FOO_API ARCH_IMPORT
/// # define FOO_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
/// # define FOO_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
/// # endif
/// # define FOO_LOCAL ARCH_HIDDEN
/// #endif
///
/// #endif
/// \endcode
///
/// Note that every library has its own unique _API and _LOCAL macros and
/// the expansion of these macros depends on whether the library is being
/// built or used (indicated by the externally set macro FOO_EXPORTS).
///
/// Library headers then include this header and mark classes, methods,
/// functions and variables as part of the API or local. Each case is
/// described below.
///
/// A class is added to the API like this:
///
/// \code
/// class FOO_API FooClass ...
/// \endcode
///
/// This will add every member to the API, including implicitly created
/// members like a default constructor, default assignment, the vtable
/// and the type_info. The type_info is especially important. If you
/// will dynamic_cast to the type or catch an exception using the type
/// outside of the library, you \b must put its type_info into the API.
/// To export the vtable & type_info specifically, use \c ARCH_EXPORT_TYPE.
/// However, due to compiler limitations, ARCH_EXPORT_TYPE may put the
/// whole class into the API as if ARCH_EXPORT were used.
///
/// Note that template classes do not get added to the API that way.
/// Instead they are added when explicitly instantiated like so:
///
/// \code
/// template class FOO_API FooTemplateClass<FooArgType>;
/// \endcode
///
/// It's also sometimes necessary to indicate that an instantiation exists
/// in the API and that a client should not do any of its own instantiation.
/// This is necessary, for example, when the template has static data members
/// and is done by using extern template in the header file that provides the
/// type. Two of the macros above will do that:
///
/// \code
/// FOO_API_TEMPLATE_CLASS(FooTemplateClass<FooArgType>);
/// FOO_API_TEMPLATE_STRUCT(FooTemplateClass<FooArgType>);
/// \endcode
///
/// Which you use depends on if FooTemplateClass is a class or struct. The
/// macro is used because we don't want to always use extern template, but
/// only when we're importing a dynamic library.
///
/// A template that is completely inlined does not need to be added to the
/// API since it's simply instantiated where needed.
///
/// Functions, methods and variables can also be put into the API:
///
/// \code
/// struct FooLocalClass {
/// ~FooLocalClass();
/// FOO_API void MoveTheThing();
/// };
/// FOO_API FooLocalClass* FooNewThing();
/// FOO_API extern int doNotUseGlobalVariables;
/// \endcode
///
/// Just because FooLocalClass is not in the API doesn't mean clients can't
/// have pointers and references to instances. What they can't do is call
/// member functions not in the API (or, as indicated above, use RTTI for
/// it). So, for example:
///
/// \code
/// FooLocalClass* thing = FooNewThing();
/// thing->MoveTheThing();
/// (void)dynamic_cast<FooLocalClass*>(thing); // Link error!
/// delete thing; // Link error!
/// \endcode
///
/// Deleting the FooLocalClass instance attempts to use the (non-API) d'tor
/// and fails to link. If we had an implicitly defined d'tor then the
/// deletion would have worked, presuming FooLocalClass didn't have any
/// data members with non-API d'tors.
///
/// A method of a class added to the API is itself in the API but on some
/// platforms (i.e. not Windows) you can remove it from the API using
/// FOO_LOCAL:
///
/// \code
/// struct FOO_API FooSemiAPI {
/// void DoSomethingPublic();
/// FOO_LOCAL void _DoSomethingPrivate();
/// };
/// \endcode
///
/// Clients of the library will fail to link if they use _DoSomethingPrivate()
/// if FOO_LOCAL is supported. If not then the symbol will remain in the API.
#include "pxr/base/arch/defines.h"
#if defined(ARCH_OS_WINDOWS)
# if defined(ARCH_COMPILER_GCC) && ARCH_COMPILER_GCC_MAJOR >= 4 || defined(ARCH_COMPILER_CLANG)
# define ARCH_EXPORT __attribute__((dllexport))
# define ARCH_IMPORT __attribute__((dllimport))
# define ARCH_HIDDEN
# define ARCH_EXPORT_TYPE
# else
# define ARCH_EXPORT __declspec(dllexport)
# define ARCH_IMPORT __declspec(dllimport)
# define ARCH_HIDDEN
# define ARCH_EXPORT_TYPE
# endif
#elif defined(ARCH_COMPILER_GCC) && ARCH_COMPILER_GCC_MAJOR >= 4 || defined(ARCH_COMPILER_CLANG)
# define ARCH_EXPORT __attribute__((visibility("default")))
# define ARCH_IMPORT
# define ARCH_HIDDEN __attribute__((visibility("hidden")))
# if defined(ARCH_COMPILER_CLANG)
# define ARCH_EXPORT_TYPE __attribute__((type_visibility("default")))
# else
# define ARCH_EXPORT_TYPE __attribute__((visibility("default")))
# endif
#else
# define ARCH_EXPORT
# define ARCH_IMPORT
# define ARCH_HIDDEN
# define ARCH_EXPORT_TYPE
#endif
#define ARCH_EXPORT_TEMPLATE(type, ...)
#define ARCH_IMPORT_TEMPLATE(type, ...) extern template type ARCH_IMPORT __VA_ARGS__
#endif // PXR_BASE_ARCH_EXPORT_H
+466
View File
@@ -0,0 +1,466 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_FILE_SYSTEM_H
#define PXR_BASE_ARCH_FILE_SYSTEM_H
/// \file arch/fileSystem.h
/// \ingroup group_arch_SystemFunctions
/// Architecture dependent file system access
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include "pxr/base/arch/defines.h"
#include "pxr/base/arch/inttypes.h"
#include <memory>
#include <cstdio>
#include <string>
#include <set>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#if defined(ARCH_OS_LINUX)
#include <unistd.h>
#include <sys/statfs.h>
#include <glob.h>
#elif defined(ARCH_OS_DARWIN)
#include <unistd.h>
#include <sys/mount.h>
#include <glob.h>
#elif defined(ARCH_OS_WINDOWS)
#include <io.h>
#include <windows.h>
#include <stringapiset.h>
#endif
PXR_NAMESPACE_OPEN_SCOPE
/// \addtogroup group_arch_SystemFunctions
///@{
#if !defined(ARCH_OS_WINDOWS)
#ifdef _POSIX_VERSION
#include <limits.h> /* for PATH_MAX */
#else
#include <sys/param.h> /* for MAXPATHLEN */
#endif
#else
// XXX -- Should probably have ARCH_ macro for this.
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
// See https://msdn.microsoft.com/en-us/library/1w06ktdy.aspx
// XXX -- Should probably have Arch enum for these.
#define F_OK 0 // Test for existence.
#define X_OK 1 // Test for execute permission.
#define W_OK 2 // Test for write permission.
#define R_OK 4 // Test for read permission.
#endif
#if defined(ARCH_OS_WINDOWS)
#define ARCH_GLOB_NOCHECK 1
#define ARCH_GLOB_MARK 2
#define ARCH_GLOB_NOSORT 4
#else
#define ARCH_GLOB_NOCHECK GLOB_NOCHECK
#define ARCH_GLOB_MARK GLOB_MARK
#define ARCH_GLOB_NOSORT GLOB_NOSORT
#endif
#define ARCH_GLOB_DEFAULT (ARCH_GLOB_NOCHECK | ARCH_GLOB_MARK)
#ifndef ARCH_PATH_MAX
#ifdef PATH_MAX
#define ARCH_PATH_MAX PATH_MAX
#else
#ifdef MAXPATHLEN
#define ARCH_PATH_MAX MAXPATHLEN
#else
#ifdef _MAX_PATH
#define ARCH_PATH_MAX _MAX_PATH
#else
#define ARCH_PATH_MAX 1024
#endif
#endif
#endif
#endif
#if defined(ARCH_OS_WINDOWS)
#define ARCH_PATH_SEP "\\"
#define ARCH_PATH_LIST_SEP ";"
#define ARCH_REL_PATH_IDENT ".\\"
#else
#define ARCH_PATH_SEP "/"
#define ARCH_PATH_LIST_SEP ":"
#define ARCH_REL_PATH_IDENT "./"
#endif
#if defined(ARCH_OS_WINDOWS)
typedef struct __stat64 ArchStatType;
#else
typedef struct stat ArchStatType;
#endif
/// \file fileSystem.h
/// Architecture dependent file system access
/// \ingroup group_arch_SystemFunctions
///
/// Opens a file.
///
/// Opens the file that is specified by filename.
/// Returning true if the file was opened successfully; false otherwise.
///
ARCH_API FILE*
ArchOpenFile(char const* fileName, char const* mode);
#if defined(ARCH_OS_WINDOWS)
# define ArchChmod(path, mode) _chmod(path, mode)
#else
# define ArchChmod(path, mode) chmod(path, mode)
#endif
#if defined(ARCH_OS_WINDOWS)
# define ArchCloseFile(fd) _close(fd)
#else
# define ArchCloseFile(fd) close(fd)
#endif
#if defined(ARCH_OS_WINDOWS)
# define ArchUnlinkFile(path) _unlink(path)
#else
# define ArchUnlinkFile(path) unlink(path)
#endif
#if defined(ARCH_OS_WINDOWS)
ARCH_API int ArchFileAccess(const char* path, int mode);
#else
# define ArchFileAccess(path, mode) access(path, mode)
#endif
#if defined(ARCH_OS_WINDOWS)
# define ArchFdOpen(fd, mode) _fdopen(fd, mode)
#else
# define ArchFdOpen(fd, mode) fdopen(fd, mode)
#endif
#if defined(ARCH_OS_WINDOWS)
# define ArchFileNo(stream) _fileno(stream)
#else
# define ArchFileNo(stream) fileno(stream)
#endif
#if defined(ARCH_OS_WINDOWS)
# define ArchFileIsaTTY(stream) _isatty(stream)
#else
# define ArchFileIsaTTY(stream) isatty(stream)
#endif
#if defined(ARCH_OS_WINDOWS)
ARCH_API int ArchRmDir(const char* path);
#else
# define ArchRmDir(path) rmdir(path)
#endif
/// Return the length of a file in bytes.
///
/// Returns -1 if the file cannot be opened/read.
ARCH_API int64_t ArchGetFileLength(const char* fileName);
ARCH_API int64_t ArchGetFileLength(FILE *file);
/// Return a filename for this file, if one can be obtained.
ARCH_API std::string ArchGetFileName(FILE *file);
/// Returns true if the data in \c stat struct \p st indicates that the target
/// file or directory is writable.
///
/// This returns true if the struct pointer is valid, and the stat indicates
/// the target is writable by the effective user, effective group, or all
/// users.
ARCH_API bool ArchStatIsWritable(const ArchStatType *st);
/// Returns the modification time (mtime) in seconds for a file.
///
/// This function stores the modification time with as much precision as is
/// available in the stat structure for the current platform in \p time and
/// returns \c true on success, otherwise just returns \c false.
ARCH_API bool ArchGetModificationTime(const char* pathname, double* time);
/// Returns the modification time (mtime) in seconds from the stat struct.
///
/// This function returns the modification time with as much precision as is
/// available in the stat structure for the current platform.
ARCH_API double ArchGetModificationTime(const ArchStatType& st);
/// Normalizes the specified path, eliminating double slashes, etc.
///
/// This canonicalizes paths, removing any double slashes, and eliminiating
/// '.', and '..' components of the path. This emulates the behavior of
/// os.path.normpath in Python.
///
/// On Windows, all backslashes are converted to forward slashes and drive
/// specifiers (e.g., "C:") are lower-cased. If \p stripDriveSpecifier
/// is \c true, these drive specifiers are removed from the path.
ARCH_API std::string ArchNormPath(const std::string& path,
bool stripDriveSpecifier = false);
/// Returns the canonical absolute path of the specified filename.
///
/// This makes the specified path absolute, by prepending the current working
/// directory. If the path is already absolute, it is returned unmodified.
ARCH_API std::string ArchAbsPath(const std::string& path);
/// Returns the permissions mode (mode_t) for the given pathname.
///
/// This function stats the given pathname and returns the permissions flags
/// for it and returns true. If the stat fails, returns false.
///
ARCH_API bool ArchGetStatMode(const char *pathname, int *mode);
/// Return the path to a temporary directory for this platform.
///
/// The returned temporary directory will be a location that will normally
/// be cleaned out on a reboot. This is /var/tmp on Linux machines (for
/// legacy reasons), but /tmp on Darwin machines (/var/tmp on Darwin is
/// specified as a location where files are kept between system reboots -
/// see "man hier"). The returned string will not have a trailing slash.
///
/// This routine is threadsafe and will not perform any memory allocations.
ARCH_API const char *ArchGetTmpDir();
/// Make a temporary file name, in a system-determined temporary directory.
///
/// The result returned has the form TMPDIR/prefix.pid[.n]suffix where TMPDIR
/// is a system-determined temporary directory (typically /tmp or /usr/tmp),
/// pid is the process id of the process, and the optional .n records the
/// number of times this function has been called by a process (and is ommited
/// the first time this function is called).
///
/// The call is threadsafe.
///
/// \warning This call opens a security hole because of the race between
/// choosing the name and opening the file. This call should be avoided in
/// favor of \c ArchMakeTmpFile().
ARCH_API
std::string ArchMakeTmpFileName(const std::string& prefix,
const std::string& suffix = std::string());
/// Create a temporary file, in a system-determined temporary directory.
///
/// The result returned has the form TMPDIR/prefix.XXXXXX where TMPDIR is a
/// system-determined temporary directory (typically /tmp or /usr/tmp) and
/// XXXXXX is a unique suffix. Returns the file descriptor of the new file
/// and, if pathname isn't NULL, returns the full path to the file in
/// pathname. Returns -1 on failure and errno is set.
///
/// The call is threadsafe.
ARCH_API
int ArchMakeTmpFile(const std::string& prefix, std::string* pathname = 0);
/// Create a temporary file, in a given temporary directory.
///
/// The result returned has the form TMPDIR/prefix.XXXXXX where TMPDIR is the
/// given temporary directory and XXXXXX is a unique suffix. Returns the file
/// descriptor of the new file and, if pathname isn't NULL, returns the full
/// path to the file in pathname. Returns -1 on failure and errno is set.
///
/// The call is threadsafe.
ARCH_API
int ArchMakeTmpFile(const std::string& tmpdir,
const std::string& prefix, std::string* pathname = 0);
/// Create a temporary sub-direcrory, in a given temporary directory.
///
/// The result returned has the form TMPDIR/prefix.XXXXXX/ where TMPDIR is the
/// given temporary directory and XXXXXX is a unique suffix. Returns the the
/// full path to the subdir in pathname. Returns empty string on failure and
/// errno is set.
///
/// The call is threadsafe.
ARCH_API
std::string ArchMakeTmpSubdir(const std::string& tmpdir,
const std::string& prefix);
// Helper 'deleter' for use with std::unique_ptr for file mappings.
struct Arch_Unmapper {
Arch_Unmapper() : _length(~0) {}
explicit Arch_Unmapper(size_t length) : _length(length) {}
ARCH_API void operator()(char *mapStart) const;
ARCH_API void operator()(char const *mapStart) const;
size_t GetLength() const { return _length; }
private:
size_t _length;
};
/// ArchConstFileMapping and ArchMutableFileMapping are std::unique_ptr<char
/// const *, ...> and std::unique_ptr<char *, ...> respectively. The functions
/// ArchMapFileReadOnly() and ArchMapFileReadWrite() return them and provide
/// access to memory-mapped file contents.
using ArchConstFileMapping = std::unique_ptr<char const, Arch_Unmapper>;
using ArchMutableFileMapping = std::unique_ptr<char, Arch_Unmapper>;
/// Return the length of an ArchConstFileMapping.
inline size_t
ArchGetFileMappingLength(ArchConstFileMapping const &m) {
return m.get_deleter().GetLength();
}
/// Return the length of an ArchMutableFileMapping.
inline size_t
ArchGetFileMappingLength(ArchMutableFileMapping const &m) {
return m.get_deleter().GetLength();
}
/// Privately map the passed \p file into memory and return a unique_ptr to the
/// read-only mapped contents. The contents may not be modified. If mapping
/// fails, return a null unique_ptr and if errMsg is not null fill it with
/// information about the failure.
ARCH_API
ArchConstFileMapping
ArchMapFileReadOnly(FILE *file, std::string *errMsg=nullptr);
/// \overload
ARCH_API
ArchConstFileMapping
ArchMapFileReadOnly(std::string const& path, std::string *errMsg=nullptr);
/// Privately map the passed \p file into memory and return a unique_ptr to the
/// copy-on-write mapped contents. If modified, the affected pages are
/// dissociated from the underlying file and become backed by the system's swap
/// or page-file storage. Edits are not carried through to the underlying file.
/// If mapping fails, return a null unique_ptr and if errMsg is not null fill it
/// with information about the failure.
ARCH_API
ArchMutableFileMapping
ArchMapFileReadWrite(FILE *file, std::string *errMsg=nullptr);
/// \overload
ARCH_API
ArchMutableFileMapping
ArchMapFileReadWrite(std::string const& path, std::string *errMsg=nullptr);
enum ArchMemAdvice {
ArchMemAdviceNormal, // Treat range with default behavior.
ArchMemAdviceWillNeed, // OS may prefetch this range.
ArchMemAdviceDontNeed, // OS may free resources related to this range.
ArchMemAdviceRandomAccess, // Prefetching may not be beneficial.
};
/// Advise the OS regarding how the application intends to access a range of
/// memory. See ArchMemAdvice. This is primarily useful for mapped file
/// regions. This call does not change program semantics. It is only an
/// optimization hint to the OS, and may be a no-op on some systems.
ARCH_API
void ArchMemAdvise(void const *addr, size_t len, ArchMemAdvice adv);
/// Report whether or not the mapped virtual memory pages starting at \p addr
/// for \p len bytes are resident in RAM. Pages that are resident will not,
/// when accessed, cause a page fault while those that are not will. Return
/// true on success and false in case of an error. The \p addr argument must be
/// a multiple of ArchGetPageSize(). The \p len argument need not be a multiple
/// of the page size; it will be rounded up to the next page boundary. Fill
/// \p pageMap with 0s for pages not resident in memory and 1s for pages that
/// are. The \p pageMap argument must therefore point to at least (\p len +
/// ArchGetPageSize()-1)/ArchGetPageSize() bytes.
///
/// Note that currently this function is only implemented on Linux and Darwin.
/// On Windows it currently always returns false.
ARCH_API
bool
ArchQueryMappedMemoryResidency(
void const *addr, size_t len, unsigned char *pageMap);
/// Read up to \p count bytes from \p offset in \p file into \p buffer. The
/// file position indicator for \p file is not changed. Return the number of
/// bytes read, or zero if at end of file. Return -1 in case of an error, with
/// errno set appropriately.
ARCH_API
int64_t ArchPRead(FILE *file, void *buffer, size_t count, int64_t offset);
/// Write up to \p count bytes from \p buffer to \p file at \p offset. The file
/// position indicator for \p file is not changed. Return the number of bytes
/// written, possibly zero if none written. Return -1 in case of an error, with
/// errno set appropriately.
ARCH_API
int64_t ArchPWrite(FILE *file, void const *bytes, size_t count, int64_t offset);
/// Returns the value of the symbolic link at \p path. Returns the empty
/// string on error or if \p path does not refer to a symbolic link.
ARCH_API
std::string ArchReadLink(const char* path);
enum ArchFileAdvice {
ArchFileAdviceNormal, // Treat range with default behavior.
ArchFileAdviceWillNeed, // OS may prefetch this range.
ArchFileAdviceDontNeed, // OS may free resources related to this range.
ArchFileAdviceRandomAccess, // Prefetching may not be beneficial.
};
/// Advise the OS regarding how the application intends to access a range of
/// bytes in a file. See ArchFileAdvice. This call does not change program
/// semantics. It is only an optimization hint to the OS, and may be a no-op on
/// some systems.
ARCH_API
void ArchFileAdvise(FILE *file, int64_t offset, size_t count,
ArchFileAdvice adv);
#if defined(ARCH_OS_WINDOWS)
/// Converts UTF-16 windows string to regular std::string - Windows-only
inline std::string ArchWindowsUtf16ToUtf8(const std::wstring &wstr)
{
if (wstr.empty()) return std::string();
// first call is only to get required size for string
int size = WideCharToMultiByte(
CP_UTF8, 0, wstr.data(), (int)wstr.size(), NULL, 0, NULL, NULL);
if (size == 0) return std::string();
std::string str(size, 0);
if (WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (int)wstr.size(),
&str[0], size, NULL, NULL) == 0) {
return std::string();
}
return str;
}
/// Converts regular std::string to UTF-16 windows string - Windows-only
inline std::wstring ArchWindowsUtf8ToUtf16(const std::string &str)
{
if (str.empty()) return std::wstring();
// first call is only to get required size for wstring
int size = MultiByteToWideChar(
CP_UTF8, 0, str.data(), (int)str.size(), NULL, 0);
if (size == 0) return std::wstring();
std::wstring wstr(size, 0);
if(MultiByteToWideChar(
CP_UTF8, 0, str.data(), (int)str.size(), &wstr[0], size) == 0) {
return std::wstring();
}
return wstr;
}
#endif
///@}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_FILE_SYSTEM_H
+54
View File
@@ -0,0 +1,54 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_FUNCTION_H
#define PXR_BASE_ARCH_FUNCTION_H
/// \file arch/function.h
/// Define preprocessor function name macros.
///
/// This file extents the functionality of pxr/base/arch/functionLite.h.
/// This file needs to be public but shouldn't be included directly by
/// anything outside of \c lib/tf.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include "pxr/base/arch/functionLite.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
/// Return well formatted function name.
///
/// This function assumes \c function is __ARCH_FUNCTION__ and
/// \c prettyFunction is __ARCH_PRETTY_FUNCTION__, and attempts to
/// reconstruct a well formatted function name.
///
/// \ingroup group_arch_Diagnostic
ARCH_API
std::string ArchGetPrettierFunctionName(const std::string &function,
const std::string &prettyFunction);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_FUNCTION_H
+56
View File
@@ -0,0 +1,56 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_FUNCTION_LITE_H
#define PXR_BASE_ARCH_FUNCTION_LITE_H
/// \file arch/functionLite.h
/// Define preprocessor function name macros.
///
/// This file defines preprocessor macros for getting the current function
/// name and related information so they can be used in a architecture
/// independent manner. This file needs to be public but shouldn't be
/// included directly by anything outside of \c pxr/base/tf.
#include "pxr/base/arch/defines.h"
// Note: this file specifically does not include <string>.
#define __ARCH_FUNCTION__ __func__
#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_ICC) || \
defined(ARCH_COMPILER_CLANG)
# define __ARCH_PRETTY_FUNCTION__ __PRETTY_FUNCTION__
#elif defined(ARCH_COMPILER_MSVC)
# define __ARCH_PRETTY_FUNCTION__ __FUNCSIG__
#else
# define __ARCH_PRETTY_FUNCTION__ __ARCH_FUNCTION__
#endif /* defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_ICC) ||
defined(ARCH_COMPILER_CLANG)*/
#if defined(BUILD_COMPONENT_SRC_PREFIX)
# define __ARCH_FILE__ BUILD_COMPONENT_SRC_PREFIX __FILE__
#else
# define __ARCH_FILE__ __FILE__
#endif /* defined(BUILD_COMPONENT_SRC_PREFIX) */
#endif // PXR_BASE_ARCH_FUNCTION_LITE_H
+60
View File
@@ -0,0 +1,60 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_HASH_H
#define PXR_BASE_ARCH_HASH_H
/// \file arch/hash.h
/// Hash functions.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include "pxr/base/arch/inttypes.h"
PXR_NAMESPACE_OPEN_SCOPE
/// Hash \a len bytes of \a data.
///
/// To compute a hash value for data that is not contiguous in memory, iterate
/// over all the contiguous blocks of memory and accumulate the hash value by
/// passing it on as \p seed. Note that this is *not* equivalent to hashing the
/// contiguous pieces as a whole. Support for that may be added in future.
///
ARCH_API uint32_t ArchHash(const char *data, size_t len);
/// \overload
ARCH_API uint32_t ArchHash(const char *data, size_t len, uint32_t seed);
/// Hash \a len bytes of \a data.
///
/// To compute a hash value for data that is not contiguous in memory, iterate
/// over all the contiguous blocks of memory and accumulate the hash value by
/// passing it on as \p seed. Note that this is *not* equivalent to hashing the
/// contiguous pieces as a whole. Support for that may be added in future.
///
ARCH_API uint64_t ArchHash64(const char *data, size_t len);
/// \overload
ARCH_API uint64_t ArchHash64(const char *data, size_t len, uint64_t seed);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_HASH_H
+51
View File
@@ -0,0 +1,51 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_HINTS_H
#define PXR_BASE_ARCH_HINTS_H
#include "pxr/base/arch/defines.h"
/// \file arch/hints.h
/// Compiler hints.
///
/// \c ARCH_LIKELY(bool-expr) and \c ARCH_UNLIKELY(bool-expr) will evaluate to
/// the value of bool-expr but will also emit compiler intrinsics providing
/// hints for branch prediction if the compiler has such intrinsics. It is
/// advised that you only use these in cases where you empirically know the
/// outcome of bool-expr to a very high degree of certainty. For example,
/// fatal-error cases, invariants, first-time initializations, etc.
#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
#define ARCH_LIKELY(x) (__builtin_expect((bool)(x), true))
#define ARCH_UNLIKELY(x) (__builtin_expect((bool)(x), false))
#else
#define ARCH_LIKELY(x) (x)
#define ARCH_UNLIKELY(x) (x)
#endif
#endif // PXR_BASE_ARCH_HINTS_H
+62
View File
@@ -0,0 +1,62 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_INTTYPES_H
#define PXR_BASE_ARCH_INTTYPES_H
/// \file arch/inttypes.h
/// \ingroup group_arch_Bits
/// Define integral types.
///
/// By including this file, the "standard" integer types \c int16_t,
/// \c int32_t, and \c int64_t are all defined, as are their unsigned
/// counterparts \c uint16_t, \c uint32_t, and \c uint64_t. This also
/// includes the macros for limits, constants, and printf format specifiers.
// These defines should in theory not be needed to get the related sized-int
// macros, as this was not adopted by the C++ committee and was dropped by the C
// committee, but glibc erroneously "respects" them so we need to have them.
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
#ifndef __STDC_CONSTANT_MACROS
#define __STDC_CONSTANT_MACROS
#endif
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
#include <cinttypes>
#include <cstdint>
#include "pxr/pxr.h"
#include "pxr/base/arch/defines.h"
#include <sys/types.h>
PXR_NAMESPACE_OPEN_SCOPE
typedef unsigned char uchar;
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_INTTYPES_H
+99
View File
@@ -0,0 +1,99 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_LIBRARY_H
#define PXR_BASE_ARCH_LIBRARY_H
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <string>
#if defined(ARCH_OS_WINDOWS)
# define ARCH_LIBRARY_LAZY 0
# define ARCH_LIBRARY_NOW 0
# define ARCH_LIBRARY_LOCAL 0
# define ARCH_LIBRARY_GLOBAL 0
# define ARCH_LIBRARY_SUFFIX ".dll"
# define ARCH_STATIC_LIBRARY_SUFFIX ".lib"
#else
# include <dlfcn.h>
# define ARCH_LIBRARY_LAZY RTLD_LAZY
# define ARCH_LIBRARY_NOW RTLD_NOW
# define ARCH_LIBRARY_LOCAL RTLD_LOCAL
# define ARCH_LIBRARY_GLOBAL RTLD_GLOBAL
# if defined(ARCH_OS_DARWIN)
# define ARCH_LIBRARY_SUFFIX ".dylib"
# else
# define ARCH_LIBRARY_SUFFIX ".so"
# endif
# define ARCH_STATIC_LIBRARY_SUFFIX ".a"
#endif
// On MacOS shared libraries and loadable modules (aka loadable bundles aka
// plugins) are different entities. Most cross-platform software packages
// that create loadable modules use .so as the extension on MacOS for
// compatibility, so we use that here.
#if defined(ARCH_OS_DARWIN)
# define ARCH_PLUGIN_SUFFIX ".so"
#else
# define ARCH_PLUGIN_SUFFIX ARCH_LIBRARY_SUFFIX
#endif
PXR_NAMESPACE_OPEN_SCOPE
/// library.h
/// Architecture dependent loading and unloading of dynamic libraries.
/// \ingroup group_arch_SystemFunctions
/// Load an executable object file.
/// \ingroup group_arch_SystemFunctions
///
/// Opens the dynamic library that is specified by filename.
/// Returning the handle to the module if successful; false otherwise.
ARCH_API
void* ArchLibraryOpen(const std::string &filename, int flag);
/// Obtain a description of the most recent error that occurred from
/// \c ArchLibraryOpen.
///\ingroup group_arch_SystemFunctions
ARCH_API
std::string ArchLibraryError();
/// Closes an object opened with \c ArchLibraryOpen.
/// \ingroup group_arch_SystemFunctions
ARCH_API
int ArchLibraryClose(void* handle);
/// Obtain the address of a symbol defined within an object opened with
/// \c ArchLibraryOpen.
/// \ingroup group_arch_SystemFunctions
///
/// Obtain the address of a symbol that is specified by name.
/// Returning the address of the symbol if successful; nullptr otherwise.
ARCH_API
void* ArchLibraryGetSymbolAddress(void* handle, const char* name);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_LIBRARY_H
+160
View File
@@ -0,0 +1,160 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_MALLOC_HOOK_H
#define PXR_BASE_ARCH_MALLOC_HOOK_H
/// \file arch/mallocHook.h
/// \ingroup group_arch_Memory
/// Routines for controlling malloc behavior.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <stdlib.h>
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
/// Return true if ptmalloc is being used as the memory allocator
///
/// ptmalloc3 is an external shared library providing implementations of the
/// standard memory allocation functions (e.g. malloc, free). Consumers with
/// special behavior that depends on this library may use this function to
/// determine if it is the active allocator.
///
/// \ingroup group_arch_Memory
ARCH_API bool ArchIsPtmallocActive();
/// Return true if the C++ STL allocator was requested to be turned off.
///
/// Under gcc, this is done by setting the environment variable
/// GLIBCXX_FORCE_NEW, but it might differ (or not even be possible) for other
/// platforms.
///
/// \ingroup group_arch_Memory
ARCH_API bool ArchIsStlAllocatorOff();
/// \class ArchMallocHook
/// \ingroup group_arch_Memory
///
/// Override default malloc() functionality.
///
/// The \c ArchMallocHook class is used on supported systems to install a
/// call-back function in place of the standard malloc/realloc/free/memalign
/// function calls. Supported systems are currently restricted to 64-bit linux
/// systems.
///
/// The call-back function can access the original allocation function by
/// calling, for example, \c ArchMallocHook::Malloc, or it is free to perform
/// its own allocation.
///
/// The \c ArchMallocHook is a POD (plain old datastructure) which means that
/// to use it properly, it should be declared at global scope, ensuring
/// zero-initialization.
class ArchMallocHook {
public:
/// Initialize hooks.
///
/// Calling \c Initialize() installs the supplied functions as call-back
/// in place of the standard system memory allocation routines. Note
/// that the callbacks take an extra \c const \c void* parameter; on
/// supported systems, the called function should simply ignore the extra
/// parameter.
///
/// If initialization fails, \c false is returned and \p *errMsg is set
/// accordingly. If \c *this has already been initialized, calling \c
/// Initialize() a second time will fail.
ARCH_API
bool Initialize(void* (*mallocWrapper)(size_t, const void*),
void* (*reallocWrapper)(void*, size_t, const void*),
void* (*memalignWrapper)(size_t, size_t, const void*),
void (*freeWrapper)(void*, const void*),
std::string* errMsg);
/// Return true if \c *this has been (successfully) initialized.
///
/// In order for this function to work properly, \c this cannot be a local
/// or dynamically initialized variable; rather, \c this must be a global
/// variable, to ensure zero-initialization.
ARCH_API
bool IsInitialized();
/// Call the original system \c malloc() function.
///
/// This function allows user-supplied callbacks to access the original
/// system-supplied malloc() call. For speed reasons, no safety checks
/// are performed; in particular, calling this function without having
/// successfully initialized \p *this will likely crash your program.
ARCH_API
void* Malloc(size_t nBytes) {
return (*_underlyingMallocFunc)(nBytes);
}
/// Call the original system \c realloc() function.
///
/// This function allows user-supplied callbacks to access the original
/// system-supplied \c realloc() call. For speed reasons, no safety checks
/// are performed; in particular, calling this function without having
/// successfully initialized \p *this will likely crash your program.
ARCH_API
void* Realloc(void* ptr, size_t nBytes) {
return (*_underlyingReallocFunc)(ptr, nBytes);
}
/// Call the original system \c memalign() function.
///
/// This function allows user-supplied callbacks to access the original
/// system-supplied \c memalign() call. For speed reasons, no safety checks
/// are performed; in particular, calling this function without having
/// successfully initialized \p *this will likely crash your program.
ARCH_API
void* Memalign(size_t alignment, size_t nBytes) {
return (*_underlyingMemalignFunc)(alignment, nBytes);
}
/// Call the original system \c free() function.
///
/// This function allows user-supplied callbacks to access the original
/// system-supplied \c free() call. For speed reasons, no safety checks
/// are performed; in particular, calling this function without having
/// successfully initialized \p *this will likely crash your program.
ARCH_API
void Free(void* ptr) {
(*_underlyingFreeFunc)(ptr);
}
private:
// Note: this is a POD (plain 'ol data structure) so we depend on zero
// initialization here to null these out. Do not add a constructor or
// destructor to this class.
void* (*_underlyingMallocFunc)(size_t);
void* (*_underlyingReallocFunc)(void*, size_t);
void* (*_underlyingMemalignFunc)(size_t, size_t);
void (*_underlyingFreeFunc)(void*);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_MALLOC_HOOK_H
+131
View File
@@ -0,0 +1,131 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_MATH_H
#define PXR_BASE_ARCH_MATH_H
/// \file arch/math.h
/// \ingroup group_arch_Math
/// Architecture-specific math function calls.
#include "pxr/pxr.h"
#include "pxr/base/arch/defines.h"
#include "pxr/base/arch/inttypes.h"
#include <cmath>
#if !defined(M_PI)
#define M_PI 3.14159265358979323846
#endif
PXR_NAMESPACE_OPEN_SCOPE
/// \addtogroup group_arch_Math
///@{
#if defined (ARCH_CPU_INTEL) || defined (ARCH_CPU_ARM) || defined (doxygen)
/// This is the smallest value e such that 1+e^2 == 1, using floats.
/// True for all IEEE754 chipsets.
#define ARCH_MIN_FLOAT_EPS_SQR 0.000244141F
/// Three-valued sign. Return 1 if val > 0, 0 if val == 0, or -1 if val < 0.
inline long ArchSign(long val) {
return (val > 0) - (val < 0);
}
/// Returns The IEEE-754 bit pattern of the specified single precision value
/// as a 32-bit unsigned integer.
inline uint32_t ArchFloatToBitPattern(float v) {
union {
float _float;
uint32_t _uint;
} value;
value._float = v;
return value._uint;
}
/// Returns The single precision floating point value corresponding to the
/// given IEEE-754 bit pattern.
inline float ArchBitPatternToFloat(uint32_t v) {
union {
uint32_t _uint;
float _float;
} value;
value._uint = v;
return value._float;
}
/// Returns The IEEE-754 bit pattern of the specified double precision value
/// as a 64-bit unsigned integer.
inline uint64_t ArchDoubleToBitPattern(double v) {
union {
double _double;
uint64_t _uint;
} value;
value._double = v;
return value._uint;
}
/// Returns The double precision floating point value corresponding to the
/// given IEEE-754 bit pattern.
inline double ArchBitPatternToDouble(uint64_t v) {
union {
uint64_t _uint;
double _double;
} value;
value._uint = v;
return value._double;
}
#else
#error Unknown system architecture.
#endif
#if defined(ARCH_OS_LINUX) || defined(doxygen)
/// Computes the sine and cosine of the specified value as a float.
inline void ArchSinCosf(float v, float *s, float *c) { sincosf(v, s, c); }
/// Computes the sine and cosine of the specified value as a double.
inline void ArchSinCos(double v, double *s, double *c) { sincos(v, s, c); }
#elif defined(ARCH_OS_DARWIN) || defined(ARCH_OS_WINDOWS)
inline void ArchSinCosf(float v, float *s, float *c) {
*s = std::sin(v);
*c = std::cos(v);
}
inline void ArchSinCos(double v, double *s, double *c) {
*s = std::sin(v);
*c = std::cos(v);
}
#else
#error Unknown architecture.
#endif
///@}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_MATH_H
+222
View File
@@ -0,0 +1,222 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_PRAGMAS_H
#define PXR_BASE_ARCH_PRAGMAS_H
/// \file arch/pragmas.h
/// Pragmas for controlling compiler-specific behaviors.
///
/// This header contains pragmas used to control compiler-specific behaviors.
/// Behaviors that are not supported or required by a certain compiler should
/// be implemented as a no-op.
#include "pxr/base/arch/defines.h"
#if defined(ARCH_COMPILER_GCC)
#define ARCH_PRAGMA_PUSH \
_Pragma("GCC diagnostic push")
#define ARCH_PRAGMA_POP \
_Pragma("GCC diagnostic pop")
// Convert errors about variables that may be used before initialization
// into warnings.
//
// This works around GCC bug 47679.
#define ARCH_PRAGMA_MAYBE_UNINITIALIZED \
_Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
#define ARCH_PRAGMA_MACRO_REDEFINITION \
_Pragma("GCC diagnostic ignored \"-Wbuiltin-macro-redefined\"")
#define ARCH_PRAGMA_WRITE_STRINGS \
_Pragma("GCC diagnostic ignored \"-Wwrite-strings\"")
#define ARCH_PRAGMA_UNUSED_FUNCTION \
_Pragma("GCC diagnostic ignored \"-Wunused-function\"")
#elif defined(ARCH_COMPILER_CLANG)
#define ARCH_PRAGMA_PUSH \
_Pragma("clang diagnostic push")
#define ARCH_PRAGMA_POP \
_Pragma("clang diagnostic pop")
#define ARCH_PRAGMA_MACRO_REDEFINITION \
_Pragma("clang diagnostic ignored \"-Wbuiltin-macro-redefined\"")
#define ARCH_PRAGMA_UNDEFINED_VAR_TEMPLATE \
_Pragma("clang diagnostic ignored \"-Wundefined-var-template\"")
#define ARCH_PRAGMA_WRITE_STRINGS \
_Pragma("clang diagnostic ignored \"-Wwrite-strings\"")
#define ARCH_PRAGMA_UNUSED_FUNCTION \
_Pragma("clang diagnostic ignored \"-Wunused-function\"")
#define ARCH_PRAGMA_INSTANTIATION_AFTER_SPECIALIZATION \
_Pragma("clang diagnostic ignored \"-Winstantiation-after-specialization\"")
#define ARCH_PRAGMA_INSTANCE_METHOD_NOT_FOUND \
_Pragma("clang diagnostic ignored \"-Wobjc-method-access\"")
#elif defined(ARCH_COMPILER_MSVC)
#define ARCH_PRAGMA_PUSH \
__pragma(warning(push))
#define ARCH_PRAGMA_POP \
__pragma(warning(pop))
#define ARCH_PRAGMA_MACRO_TOO_FEW_ARGUMENTS \
__pragma(warning(disable:4003))
#define ARCH_PRAGMA_MACRO_REDEFINITION \
__pragma(warning(disable:4005))
#define ARCH_PRAGMA_UNUSED_FUNCTION \
__pragma(warning(disable:4505))
#define ARCH_PRAGMA_QUALIFIER_HAS_NO_MEANING \
__pragma(warning(disable:4180))
#define ARCH_PRAGMA_ZERO_SIZED_STRUCT \
__pragma(warning(disable:4200))
#define ARCH_PRAGMA_NEEDS_EXPORT_INTERFACE \
__pragma(warning(disable:4251))
#define ARCH_PRAGMA_CONVERSION_FROM_SIZET \
__pragma(warning(disable:4267))
#define ARCH_PRAGMA_MAY_NOT_BE_ALIGNED \
__pragma(warning(disable:4316))
#define ARCH_PRAGMA_SHIFT_TO_64_BITS \
__pragma(warning(disable:4334))
#define ARCH_PRAGMA_DESTRUCTOR_IMPLICIT_DEFINE \
__pragma(warning(disable:4624))
#define ARCH_PRAGMA_DEPRECATED_POSIX_NAME \
__pragma(warning(disable:4996))
#define ARCH_PRAGMA_FORCING_TO_BOOL \
__pragma(warning(disable:4800))
#define ARCH_PRAGMA_UNSAFE_USE_OF_BOOL \
__pragma(warning(disable:4804))
#define ARCH_PRAGMA_UNARY_MINUS_ON_UNSIGNED \
__pragma(warning(disable:4146))
#endif
#if !defined ARCH_PRAGMA_PUSH
#define ARCH_PRAGMA_PUSH
#endif
#if !defined ARCH_PRAGMA_POP
#define ARCH_PRAGMA_POP
#endif
#if !defined ARCH_PRAGMA_MAYBE_UNINITIALIZED
#define ARCH_PRAGMA_MAYBE_UNINITIALIZED
#endif
#if !defined ARCH_PRAGMA_MACRO_REDEFINITION
#define ARCH_PRAGMA_MACRO_REDEFINITION
#endif
#if !defined ARCH_PRAGMA_WRITE_STRINGS
#define ARCH_PRAGMA_WRITE_STRINGS
#endif
#if !defined ARCH_PRAGMA_UNUSED_FUNCTION
#define ARCH_PRAGMA_UNUSED_FUNCTION
#endif
#if !defined ARCH_PRAGMA_MACRO_TOO_FEW_ARGUMENTS
#define ARCH_PRAGMA_MACRO_TOO_FEW_ARGUMENTS
#endif
#if !defined ARCH_PRAGMA_QUALIFIER_HAS_NO_MEANING
#define ARCH_PRAGMA_QUALIFIER_HAS_NO_MEANING
#endif
#if !defined ARCH_PRAGMA_ZERO_SIZED_STRUCT
#define ARCH_PRAGMA_ZERO_SIZED_STRUCT
#endif
#if !defined ARCH_PRAGMA_NEEDS_EXPORT_INTERFACE
#define ARCH_PRAGMA_NEEDS_EXPORT_INTERFACE
#endif
#if !defined ARCH_PRAGMA_CONVERSION_FROM_SIZET
#define ARCH_PRAGMA_CONVERSION_FROM_SIZET
#endif
#if !defined ARCH_PRAGMA_MAY_NOT_BE_ALIGNED
#define ARCH_PRAGMA_MAY_NOT_BE_ALIGNED
#endif
#if !defined ARCH_PRAGMA_SHIFT_TO_64_BITS
#define ARCH_PRAGMA_SHIFT_TO_64_BITS
#endif
#if !defined ARCH_PRAGMA_DESTRUCTOR_IMPLICIT_DEFINE
#define ARCH_PRAGMA_DESTRUCTOR_IMPLICIT_DEFINE
#endif
#if !defined ARCH_PRAGMA_DEPRECATED_POSIX_NAME
#define ARCH_PRAGMA_DEPRECATED_POSIX_NAME
#endif
#if !defined ARCH_PRAGMA_FORCING_TO_BOOL
#define ARCH_PRAGMA_FORCING_TO_BOOL
#endif
#if !defined ARCH_PRAGMA_UNSAFE_USE_OF_BOOL
#define ARCH_PRAGMA_UNSAFE_USE_OF_BOOL
#endif
#if !defined ARCH_PRAGMA_UNARY_MINUS_ON_UNSIGNED
#define ARCH_PRAGMA_UNARY_MINUS_ON_UNSIGNED
#endif
#if !defined ARCH_PRAGMA_INSTANTIATION_AFTER_SPECIALIZATION
#define ARCH_PRAGMA_INSTANTIATION_AFTER_SPECIALIZATION
#endif
#if !defined ARCH_PRAGMA_UNDEFINED_VAR_TEMPLATE
#define ARCH_PRAGMA_UNDEFINED_VAR_TEMPLATE
#endif
#if !defined ARCH_PRAGMA_INSTANCE_METHOD_NOT_FOUND
#define ARCH_PRAGMA_INSTANCE_METHOD_NOT_FOUND
#endif
#endif // PXR_BASE_ARCH_PRAGMAS_H
+72
View File
@@ -0,0 +1,72 @@
//
// Copyright 2017 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_REGEX_H
#define PXR_BASE_ARCH_REGEX_H
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <memory>
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
class ArchRegex {
public:
static constexpr unsigned int CASE_INSENSITIVE = 1u;
static constexpr unsigned int GLOB = 2u;
/// Create an empty regex.
ARCH_API ArchRegex();
ARCH_API ArchRegex(const std::string& pattern, unsigned int flags = 0);
ArchRegex(const ArchRegex&) = delete;
ARCH_API ArchRegex(ArchRegex&&) noexcept;
ArchRegex& operator=(const ArchRegex&) = delete;
ARCH_API ArchRegex& operator=(ArchRegex&&) noexcept;
ARCH_API ~ArchRegex();
/// Returns \c true if the regex is valid.
ARCH_API explicit operator bool() const;
/// Returns the reason the regex is invalid or the empty string if
/// it's valid.
ARCH_API std::string GetError() const;
/// Returns the flags used to construct the regex.
ARCH_API unsigned int GetFlags() const;
/// Returns \c true if the regex matches \p query anywhere, otherwise
/// returns \c false.
ARCH_API bool Match(const std::string& query) const;
private:
class _Impl;
unsigned int _flags = 0;
std::string _error;
std::unique_ptr<_Impl> _impl;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_REGEX_H
+331
View File
@@ -0,0 +1,331 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_STACK_TRACE_H
#define PXR_BASE_ARCH_STACK_TRACE_H
/// \file arch/stackTrace.h
/// \ingroup group_arch_Diagnostics
/// Architecture-specific call-stack tracing routines.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include "pxr/base/arch/defines.h"
#include <inttypes.h>
#include <stdio.h>
#include <functional>
#include <vector>
#include <string>
#include <iosfwd>
#include <ctime>
PXR_NAMESPACE_OPEN_SCOPE
/// \addtogroup group_arch_Diagnostics
///@{
/// Dumps call-stack info to a file, and prints an informative message.
///
/// The reason for the trace should be supplied in \p reason. This routine
/// can be slow and is intended to be called for a fatal error, such as a
/// caught coredump signal, but may be called at any time. An additional
/// message may be provided in \p message. If \p reason is \c NULL then this
/// function only writes \p message to the banner (if any).
///
/// This function is implemented by calling an external program. This is
/// suitable for times where the current process may be corrupted. In other
/// cases, using \c ArchPrintStackTrace() or other related functions would be
/// much faster.
///
/// Note the use of \c char* as opposed to \c string: this is intentional,
/// because we are trying to use only async-safe function from here on and
/// malloc() is not async-safe.
ARCH_API
void ArchLogPostMortem(
const char* reason,
const char* message = nullptr,
const char* extraLogMsg = nullptr);
/// Sets the command line that gathers call-stack info.
///
/// This function sets the command line to execute to gather and log
/// call-stack info. \p argv must be NULL terminated. \p command and/or \p
/// argv may be NULL to suppress execution. Otherwise argv[0] must be the
/// full path to the program to execute, typically \p command or "$cmd" as
/// described below.
///
/// \p command and \p argv are not copied and must remain valid until the next
/// call to \c ArchSetPostMortem.
///
/// Simple substitution is supported on argv elements:
/// \li $cmd: Substitutes the command pathname, or $ARCH_POSTMORTEM if set
/// \li $pid: Substitutes the process id
/// \li $log: Substitutes the log pathname
/// \li $time: Substitutes the user time (if available, else wall time)
///
/// \sa ArchLogPostMortem
ARCH_API
void ArchSetPostMortem(const char* command, const char *const argv[]);
/// Log session info.
///
/// Optionally indicate that this is due to a crash by providing
/// the path to a file containing a stack trace in \p crashStackTrace.
///
ARCH_API
void ArchLogSessionInfo(const char *crashStackTrace=NULL);
/// Sets the command line to log sessions.
///
/// This function sets the command line to execute to log session info. \p
/// argv is used if no crash stack trace is provided, otherwise \p crashArgv
/// is used. Both must be NULL terminated. If \p command or \p argv is NULL
/// then non-crashes are not logged; if \p command or \p crashArgv is NULL
/// then crashes are not logged. If not NULL then argv[0] and crashArgv[0]
/// must be full path to the program to execute, typically \p command or
/// "$cmd" as described below.
///
/// \p command, \p argv, and \p crashArgv are not copied and must remain valid
/// until the next call to \c ArchSetLogSession.
///
/// Simple substitution is supported on argv elements:
/// \li $cmd: Substitutes the command pathname, or $ARCH_LOGSESSION if set
/// \li $prog Substitutes the program name
/// \li $pid: Substitutes the process id
/// \li $time: Substitutes the user time (if available, else wall time)
/// \li $stack: Substitutes the crash stack string (only in crashArgv)
///
/// \sa ArchLogSessionInfo
ARCH_API
void ArchSetLogSession(const char* command,
const char* const argv[],
const char* const crashArgv[]);
/// Register the callback to invoke logging at end of a successful session.
///
/// This function registers ArchLogSessionInfo() and records the current
/// timestamp, to send up-time to the DB upon exiting.
ARCH_API
void ArchEnableSessionLogging();
/// Print a stack trace to the given FILE pointer.
ARCH_API
void ArchPrintStackTrace(FILE *fout,
const std::string& programName,
const std::string& reason);
/// Print a stack trace to the given FILE pointer.
/// This function uses ArchGetProgramInfoForErrors as the \c programName.
/// \overload
ARCH_API
void ArchPrintStackTrace(FILE *fout, const std::string& reason);
/// Print a stack trace to the given ostream.
/// \overload
ARCH_API
void ArchPrintStackTrace(std::ostream& out,
const std::string& programName,
const std::string& reason);
/// Print a stack trace to the given ostream.
/// This function uses ArchGetProgramInfoForErrors as the \c programName.
/// \overload
ARCH_API
void ArchPrintStackTrace(std::ostream& out, const std::string& reason);
/// A callback to get a symbolic representation of an address.
typedef std::function<std::string(uintptr_t address)> ArchStackTraceCallback;
/// Sets a callback to get a symbolic representation of an address.
///
/// The callback returns a string for an address in a stack trace, typically
/// including the name of the function containing the address. \p cb may be \c
/// NULL to use a default implementation.
ARCH_API
void ArchSetStackTraceCallback(const ArchStackTraceCallback& cb);
/// Returns the callback to get a symbolic representation of an address.
/// \sa ArchSetStackTraceCallback
ARCH_API
void ArchGetStackTraceCallback(ArchStackTraceCallback* cb);
/// Returns the set value for the application's launch time.
/// The timestamp for this value is set when the arch library is initialized.
ARCH_API
time_t ArchGetAppLaunchTime();
/// Enables or disables the automatic logging of crash information.
///
/// This function controls whether the stack trace and build information is
/// automatically caught and stored to an internal database when a fatal crash
/// occurs.
ARCH_API
void ArchSetFatalStackLogging(bool flag);
/// Returns whether automatic logging of fatal crashes is enabled
/// This is set to false by default.
/// \see ArchSetFatalStackLogging
ARCH_API
bool ArchGetFatalStackLogging();
/// Sets the program name to be used in diagnostic output
///
/// The default value is initialized to ArchGetExecutablePath().
ARCH_API
void ArchSetProgramNameForErrors(const char * progName);
/// Returns the currently set program name for reporting errors.
/// Defaults to ArchGetExecutablePath().
ARCH_API
const char * ArchGetProgramNameForErrors();
/// Sets additional program info to be reported to the terminal in case of a
/// fatal error.
ARCH_API
void ArchSetProgramInfoForErrors( const std::string& key, const std::string& value );
/// Returns currently set program info.
/// \see ArchSetExtraLogInfoForErrors
ARCH_API
std::string ArchGetProgramInfoForErrors(const std::string& key);
/// Stores (or removes if \p lines is nullptr) a pointer to additional log data
/// that will be output in the stack trace log in case of a fatal error. Note
/// that the pointer \p lines is copied, not the pointed-to data. In addition,
/// Arch might read the data pointed to by \p lines concurrently at any time.
/// Thus it is the caller's responsibility to ensure that \p lines is both valid
/// and not mutated until replacing or removing it by invoking this function
/// again with the same \p key and different \p lines.
ARCH_API
void ArchSetExtraLogInfoForErrors(const std::string &key,
std::vector<std::string> const *lines);
/// Logs a stack trace to a file in /var/tmp.
///
/// This function is similar to \c ArchLogPostMortem(), but will not fork an
/// external process and only reports a stack trace. A file in /var/tmp is
/// created with the name \c st_APPNAME.XXXXXX, where \c mktemp is used to
/// make a unique extension for the file. If \c sessionLog is specified, then
/// it will be appended to this file. A message is printed to \c stderr
/// reporting that a stack trace has been taken and what file it has been
/// written to. And if \c fatal is true, then the stack trace will be added
/// to the stack_trace database table.
ARCH_API
void ArchLogStackTrace(const std::string& progName,
const std::string& reason,
bool fatal = false,
const std::string& sessionLog = "");
/// Logs a stack trace to a file in /var/tmp.
///
/// This function is similar to \c ArchLogPostMortem(), but will not fork an
/// external process and only reports a stack trace. A file in /var/tmp is
/// created with the name \c st_APPNAME.XXXXXX, where \c mktemp is used to
/// make a unique extension for the file. If \c sessionLog is specified,
/// then it will be appended to this file. A message is printed to \c stderr
/// reporting that a stack trace has been taken and what file it has been
/// written to. And if \c fatal is true, then the stack trace will be added
/// to the stack_trace database table.
ARCH_API
void ArchLogStackTrace(const std::string& reason,
bool fatal = false,
const std::string& sessionLog = "");
/// Return stack trace.
///
/// This function will return a vector of strings containing the current
/// stack. The vector will be of maximum size \p maxDepth.
ARCH_API
std::vector<std::string> ArchGetStackTrace(size_t maxDepth);
/// Save frames of current stack
///
/// This function saves at maximum \c maxDepth frames of the current stack
/// into the vector \c frames.
ARCH_API
void ArchGetStackFrames(size_t maxDepth, std::vector<uintptr_t> *frames);
/// Save frames of current stack.
///
/// This function saves at maximum \p maxDepth frames of the current stack
/// into the vector \p frames, skipping the first \p numFramesToSkipAtTop
/// frames. The first frame will be at depth \p numFramesToSkipAtTop and the
/// last at depth \p numFramesToSkipAtTop + \p maxDepth - 1.
ARCH_API
void ArchGetStackFrames(size_t maxDepth, size_t numFramesToSkipAtTop,
std::vector<uintptr_t> *frames);
/// Print stack frames to the given ostream.
ARCH_API
void ArchPrintStackFrames(std::ostream& out,
const std::vector<uintptr_t> &frames,
bool skipUnknownFrames = false);
/// Callback for handling crashes.
/// \see ArchCrashHandlerSystemv
typedef void (*ArchCrashHandlerSystemCB)(void* userData);
/// Replacement for 'system' safe for a crash handler
///
/// This function is a substitute for system() which does not allocate or free
/// any data, and times out after \c timeout seconds if the operation in \c
/// argv is not complete. Unlike system, it takes the full \c pathname of the
/// program to run, and won't search the path. Also unlike system, \c argv[]
/// are the separated arguments, starting with the program's name, as for
/// execv. \c callback is called every second. \c userData is passed to \c
/// callback. \c callback can be used, for example, to print a '.' repeatedly
/// to show progress. The alarm used in this function could interfere with
/// setitimer or other calls to alarm, and this function uses non-locking fork
/// and exec if available so should not generally be used except following a
/// catastrophe.
ARCH_API
int ArchCrashHandlerSystemv(const char* pathname, char *const argv[],
int timeout, ArchCrashHandlerSystemCB callback,
void* userData);
/// Crash, to test crash behavior.
///
/// This function causes the calling program to crash by doing bad malloc
/// and free things. If \c spawnthread is true, it spawns a thread which
/// remains alive during the crash. It aborts if it fails to crash.
///
/// \private
ARCH_API
void ArchTestCrash(bool spawnthread);
#if defined(ARCH_OS_DARWIN)
// macOS has no ETIME. ECANCELED seems to have about the closest meaning to
// the actual error here. The operation is timing out, not being explicitly
// canceled, but it is canceled.
#ifndef ETIME
#define ETIME ECANCELED
#endif // end ETIME
#endif // end ARCH_OS_DARWIN
///@}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_STACK_TRACE_H
+57
View File
@@ -0,0 +1,57 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_SYMBOLS_H
#define PXR_BASE_ARCH_SYMBOLS_H
/// \file arch/symbols.h
/// \ingroup group_arch_Diagnostics
/// Architecture-specific symbol lookup routines.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
/// Returns information about the address \p address in the running program.
///
/// Returns \c false if no information can be found, otherwise returns \c true
/// and modifies the other arguments: \p objectPath is set to the absolute path
/// to the executable or library the address is found in, \p baseAddress is the
/// address where that object is loaded, \p symbolName is the symbolic name of
/// the thing containing the address, and \p symbolAddress is the starting
/// address of that thing. If no thing is found to contain the address then
/// \p symbolName is cleared and \p symbolAddress is set to \c NULL. Any of
/// the arguments except \p address can be \c NULL if the result isn't needed.
/// This will return \c false if \c NULL is passed to \p address.
///
/// \ingroup group_arch_Diagnostics
ARCH_API
bool ArchGetAddressInfo(void* address,
std::string* objectPath, void** baseAddress,
std::string* symbolName, void** symbolAddress);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_SYMBOLS_H
+56
View File
@@ -0,0 +1,56 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_SYSTEM_INFO_H
#define PXR_BASE_ARCH_SYSTEM_INFO_H
/// \file arch/systemInfo.h
/// \ingroup group_arch_SystemFunctions
/// Provide architecture-specific system information.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
/// \addtogroup group_arch_SystemFunctions
///@{
/// Return current working directory as a string.
ARCH_API
std::string ArchGetCwd();
/// Return the path to the program's executable.
ARCH_API
std::string ArchGetExecutablePath();
/// Return the system's memory page size. Safe to assume power-of-two.
ARCH_API
int ArchGetPageSize();
///@}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_SYSTEM_INFO_H
+48
View File
@@ -0,0 +1,48 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_THREADS_H
#define PXR_BASE_ARCH_THREADS_H
/// \file arch/threads.h
/// \ingroup group_arch_Multithreading
/// Architecture-specific thread function calls.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <thread>
PXR_NAMESPACE_OPEN_SCOPE
/// Return true if the calling thread is the main thread, false otherwise.
/// \ingroup group_arch_Multithreading
ARCH_API bool ArchIsMainThread();
/// Return the std::thread_id for the thread arch considers to be the "main"
/// thread.
ARCH_API std::thread::id ArchGetMainThreadId();
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_THREADS_H
+116
View File
@@ -0,0 +1,116 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_TIMING_H
#define PXR_BASE_ARCH_TIMING_H
/// \file arch/timing.h
/// \ingroup group_arch_SystemFunctions
/// High-resolution, low-cost timing routines.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include "pxr/base/arch/defines.h"
#include "pxr/base/arch/inttypes.h"
/// \addtogroup group_arch_SystemFunctions
///@{
#if defined(ARCH_OS_LINUX) && defined(ARCH_CPU_INTEL)
#include <x86intrin.h>
#elif defined(ARCH_OS_DARWIN)
#include <mach/mach_time.h>
#elif defined(ARCH_OS_WINDOWS)
#include <intrin.h>
#endif
PXR_NAMESPACE_OPEN_SCOPE
/// Macro that defines the clocks per second
///
/// Unfortunately, Red Hat 7.1 does not define CLK_TCK correctly, so
/// ARCH_CLK_TCK is the only guaranteed way to get the value of CLK_TCK. The
/// value is currently the same on all of our platforms.
#define ARCH_CLK_TCK 100
/// Return the current time in system-dependent units.
///
/// The current time is returned as a number of "ticks", where each tick
/// represents some system-dependent amount of time. The resolution of the
/// timing routines varies, but on all systems, it is well under one
/// microsecond. The cost of this routine is in the tens of nanoseconds
/// on GHz class machines.
inline uint64_t
ArchGetTickTime()
{
#if defined(ARCH_OS_DARWIN)
// On Darwin we'll use mach_absolute_time().
return mach_absolute_time();
#elif defined(ARCH_CPU_INTEL)
// On Intel we'll use the rdtsc instruction.
return __rdtsc();
#elif defined (ARCH_CPU_ARM)
uint64_t result;
__asm __volatile("mrs %0, CNTVCT_EL0" : "=&r" (result));
return result;
#else
#error Unknown architecture.
#endif
}
/// Convert a duration measured in "ticks", as returned by
/// \c ArchGetTickTime(), to nanoseconds.
///
/// An example to test the timing routines would be:
/// \code
/// int64_t t1 = ArchGetTickTime();
/// sleep(10);
/// int64_t t2 = ArchGetTickTime();
///
/// // duration should be approximately 10/// 1e9 = 1e10 nanoseconds.
/// int64_t duration = ArchTicksToNanoseconds(t2 - t1);
/// \endcode
///
ARCH_API
int64_t ArchTicksToNanoseconds(uint64_t nTicks);
/// Convert a duration measured in "ticks", as returned by
/// \c ArchGetTickTime(), to seconds.
ARCH_API
double ArchTicksToSeconds(uint64_t nTicks);
/// Convert a duration in seconds to "ticks", as returned by
/// \c ArchGetTickTime().
ARCH_API
uint64_t ArchSecondsToTicks(double seconds);
/// Get nanoseconds per tick. Useful when converting ticks obtained from
/// \c ArchTickTime()
ARCH_API
double ArchGetNanosecondsPerTick();
///@}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_TIMING_H
+62
View File
@@ -0,0 +1,62 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_VIRTUAL_MEMORY_H
#define PXR_BASE_ARCH_VIRTUAL_MEMORY_H
/// \file arch/virtualMemory.h
/// \ingroup group_arch_SystemFunctions
/// Architecture dependent routines for virtual memory.
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include <cstddef>
PXR_NAMESPACE_OPEN_SCOPE
/// Reserve \p numBytes bytes of virtual memory. Call ArchCommitVirtualMemory()
/// on subranges to write to and read from the memory. Return nullptr in case
/// of an error; check errno.
ARCH_API void *
ArchReserveVirtualMemory(size_t numBytes);
/// Make the range of \p numBytes bytes starting at \p start available for
/// reading and writing. The range must be within one previously reserved by
/// ArchReserveVirtualMemory(). It is not an error to commit a range that was
/// previously partly or fully committed. Return false in case of an error;
/// check errno.
ARCH_API bool
ArchCommitVirtualMemoryRange(void *start, size_t numBytes);
/// Return memory obtained with ArchReserveVirtualMemory() to the system. The
/// \p start argument must be the value returned from a previous call to
/// ArchReserveVirtualMemory, and \p numBytes must match the argument from that
/// call. Memory within the range may not be accessed after this call. Return
/// false in case of an error; check errno.
ARCH_API bool
ArchFreeVirtualMemory(void *start, size_t numBytes);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_VIRTUAL_MEMORY_H
+105
View File
@@ -0,0 +1,105 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_BASE_ARCH_VSNPRINTF_H
#define PXR_BASE_ARCH_VSNPRINTF_H
/// \file arch/vsnprintf.h
/// \ingroup group_arch_Strings
/// Architecture dependent memory-safe sprintf capability
#include "pxr/pxr.h"
#include "pxr/base/arch/api.h"
#include "pxr/base/arch/attributes.h"
#include <stdio.h>
#include <stdarg.h>
#include <string>
PXR_NAMESPACE_OPEN_SCOPE
/// \addtogroup group_arch_Strings
///@{
/// Return the number of characters (not including the null character)
/// necessary for a particular sprintf into a string.
///
/// \c ArchVsnprintf guarantees the C99 behavior of vsnprintf on all systems:
/// it returns the number of bytes (not including the terminating null
/// character) needed to actually print the requested string. If \c size
/// indicates that \c str has enough capacity to hold the result, then the
/// function actually prints into \c str.
///
/// You probably want to use the functionality of this call via
/// \c TfStringPrintf().
///
ARCH_API
int ArchVsnprintf(char *str, size_t size, const char *format, va_list ap)
#ifndef doxygen
ARCH_PRINTF_FUNCTION(3, 0)
#endif /* doxygen */
;
/// Returns a string formed by a printf()-like specification.
///
/// \c ArchStringPrintf() is a memory-safe architecture-independent way of
/// forming a string using printf()-like formatting. For example,
/// \code
/// string formatMsg(const string& caller, int i, double val[])
/// {
/// return ArchStringPrintf("%s: val[%d] = %g\n", caller.c_str(), i, val[i]);
/// }
/// \endcode
///
/// The function is safe only to the extent that the arguments match the
/// formatting string. In particular, be careful to pass strings themselve
/// into \c ArchStringPrintf() as in the above example (i.e. \c caller.c_str()
/// as opposed to just passing \c caller).
///
ARCH_API
std::string ArchStringPrintf(const char *fmt, ...)
#ifndef doxygen
ARCH_PRINTF_FUNCTION(1, 2)
#endif /* doxygen */
;
/// Returns a string formed by a printf()-like specification.
///
/// \c ArchVStringPrintf() is equivalent to \c ArchStringPrintf() except that
/// it is called with a \c va_list instead of a variable number of arguments.
/// \c ArchVStringPrintf() does not call the \c va_end macro. Consequently,
/// the value of \c ap is undefined after the call. A functions that calls \c
/// ArchVStringPrintf() should call \c va_end(ap) itself afterwards.
///
ARCH_API
std::string ArchVStringPrintf(const char *fmt, va_list ap)
#ifndef doxygen
ARCH_PRINTF_FUNCTION(1, 0)
;
#endif
/// @}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_BASE_ARCH_VSNPRINTF_H