patch by Jeffrey Yasskin for porting to Ubuntu Hardy. Everything was accepted except there were some bug fixes needed in <locale> for the __nolocale_* series. For the apple branch I ended up using templates instead of the var_args solution because it seemed both safer and more efficient.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@104516 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -9,7 +9,13 @@
|
||||
|
||||
#include "chrono"
|
||||
#include <sys/time.h> //for gettimeofday and timeval
|
||||
#if __APPLE__
|
||||
#include <mach/mach_time.h> // mach_absolute_time, mach_timebase_info_data_t
|
||||
#else /* !__APPLE__ */
|
||||
#include <cerrno> // errno
|
||||
#include <system_error> // __throw_system_error
|
||||
#include <time.h> // clock_gettime, CLOCK_MONOTONIC
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
@@ -40,6 +46,7 @@ system_clock::from_time_t(time_t t)
|
||||
|
||||
// monotonic_clock
|
||||
|
||||
#if __APPLE__
|
||||
// mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of
|
||||
// nanoseconds since the computer booted up. MachInfo.numer and MachInfo.denom
|
||||
// are run time constants supplied by the OS. This clock has no relationship
|
||||
@@ -96,6 +103,26 @@ monotonic_clock::now()
|
||||
return time_point(duration(fp()));
|
||||
}
|
||||
|
||||
#else /* !APPLE */
|
||||
// FIXME: We assume that clock_gettime(CLOCK_MONOTONIC) works on
|
||||
// non-apple systems. Instead, we should check _POSIX_TIMERS and
|
||||
// _POSIX_MONOTONIC_CLOCK and fall back to something else if those
|
||||
// don't exist.
|
||||
|
||||
// Warning: If this is not truly monotonic, then it is non-conforming. It is
|
||||
// better for it to not exist and have the rest of libc++ use system_clock
|
||||
// instead.
|
||||
|
||||
monotonic_clock::time_point
|
||||
monotonic_clock::now()
|
||||
{
|
||||
struct timespec tp;
|
||||
if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
|
||||
__throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
|
||||
return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
|
||||
}
|
||||
#endif /* APPLE */
|
||||
|
||||
}
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
@@ -72,8 +72,11 @@ bool std::uncaught_exception() throw()
|
||||
// on Darwin, there is a helper function so __cxa_get_globals is private
|
||||
return __cxxabiapple::__cxa_uncaught_exception();
|
||||
#else
|
||||
__cxa_eh_globals * globals = __cxa_get_globals();
|
||||
return (globals->uncaughtExceptions != 0);
|
||||
#warning uncaught_exception not yet implemented
|
||||
::abort();
|
||||
// Not provided by Ubuntu gcc-4.2.4's cxxabi.h.
|
||||
// __cxa_eh_globals * globals = __cxa_get_globals();
|
||||
// return (globals->uncaughtExceptions != 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -168,4 +171,3 @@ void std::rethrow_exception(exception_ptr p)
|
||||
::abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@@ -106,7 +106,11 @@ __iostream_category::name() const
|
||||
string
|
||||
__iostream_category::message(int ev) const
|
||||
{
|
||||
if (ev != static_cast<int>(io_errc::stream) && ev <= ELAST)
|
||||
if (ev != static_cast<int>(io_errc::stream)
|
||||
#ifdef ELAST
|
||||
&& ev <= ELAST
|
||||
#endif
|
||||
)
|
||||
return __do_message::message(ev);
|
||||
return string("unspecified iostream_category error");
|
||||
}
|
||||
|
@@ -17,10 +17,11 @@
|
||||
#include "cstring"
|
||||
#include "cwctype"
|
||||
#include "__sso_allocator"
|
||||
#include <libkern/OSAtomic.h>
|
||||
#include <langinfo.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// FIXME: Locales are hard.
|
||||
#if __APPLE__
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
namespace {
|
||||
@@ -534,7 +535,7 @@ locale::id::__get()
|
||||
void
|
||||
locale::id::__init()
|
||||
{
|
||||
__id_ = OSAtomicIncrement32Barrier(&__next_id);
|
||||
__id_ = __sync_add_and_fetch(&__next_id, 1);
|
||||
}
|
||||
|
||||
// template <> class collate_byname<char>
|
||||
@@ -3678,3 +3679,4 @@ template class codecvt_byname<char32_t, char, mbstate_t>;
|
||||
template class __vector_base_common<true>;
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
#endif /* __APPLE__ */
|
||||
|
@@ -8,7 +8,6 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "memory"
|
||||
#include <libkern/OSAtomic.h>
|
||||
|
||||
_LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
@@ -16,57 +15,19 @@ namespace
|
||||
{
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
sizeof(T) * __CHAR_BIT__ == 32,
|
||||
T
|
||||
>::type
|
||||
inline T
|
||||
increment(T& t)
|
||||
{
|
||||
return OSAtomicIncrement32Barrier((volatile int32_t*)&t);
|
||||
return __sync_add_and_fetch(&t, 1);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
sizeof(T) * __CHAR_BIT__ == 32,
|
||||
T
|
||||
>::type
|
||||
inline T
|
||||
decrement(T& t)
|
||||
{
|
||||
return OSAtomicDecrement32Barrier((volatile int32_t*)&t);
|
||||
return __sync_add_and_fetch(&t, -1);
|
||||
}
|
||||
|
||||
#ifndef __ppc__
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
sizeof(T) * __CHAR_BIT__ == 64,
|
||||
T
|
||||
>::type
|
||||
increment(T& t)
|
||||
{
|
||||
return OSAtomicIncrement64Barrier((volatile int64_t*)&t);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
typename enable_if
|
||||
<
|
||||
sizeof(T) * __CHAR_BIT__ == 64,
|
||||
T
|
||||
>::type
|
||||
decrement(T& t)
|
||||
{
|
||||
return OSAtomicDecrement64Barrier((volatile int64_t*)&t);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -134,9 +95,9 @@ __shared_weak_count::lock()
|
||||
long object_owners = __shared_owners_;
|
||||
while (object_owners != -1)
|
||||
{
|
||||
if (OSAtomicCompareAndSwapLongBarrier(object_owners,
|
||||
object_owners+1,
|
||||
&__shared_owners_))
|
||||
if (__sync_bool_compare_and_swap(&__shared_owners_,
|
||||
object_owners,
|
||||
object_owners+1))
|
||||
{
|
||||
__add_weak();
|
||||
return this;
|
||||
|
@@ -148,7 +148,7 @@ timed_mutex::unlock()
|
||||
|
||||
recursive_timed_mutex::recursive_timed_mutex()
|
||||
: __count_(0),
|
||||
__id_(nullptr)
|
||||
__id_(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ recursive_timed_mutex::unlock()
|
||||
unique_lock<mutex> lk(__m_);
|
||||
if (--__count_ == 0)
|
||||
{
|
||||
__id_ = nullptr;
|
||||
__id_ = 0;
|
||||
lk.unlock();
|
||||
__cv_.notify_one();
|
||||
}
|
||||
|
@@ -7,13 +7,13 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cxxabi.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "new"
|
||||
|
||||
|
||||
#if __APPLE__
|
||||
#include <cxxabi.h>
|
||||
// On Darwin, there are two STL shared libraries and a lower level ABI
|
||||
// shared libray. The global holding the current new handler is
|
||||
// in the ABI library and named __cxa_new_handler.
|
||||
|
@@ -15,7 +15,6 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include "system_error"
|
||||
#include <libkern/OSAtomic.h>
|
||||
|
||||
// Note: optimize for size
|
||||
|
||||
@@ -59,7 +58,7 @@ inline
|
||||
__libcpp_nmstr::__libcpp_nmstr(const __libcpp_nmstr& s)
|
||||
: str_(s.str_)
|
||||
{
|
||||
OSAtomicIncrement32Barrier(&count());
|
||||
__sync_add_and_fetch(&count(), 1);
|
||||
}
|
||||
|
||||
__libcpp_nmstr&
|
||||
@@ -67,8 +66,8 @@ __libcpp_nmstr::operator=(const __libcpp_nmstr& s)
|
||||
{
|
||||
const char* p = str_;
|
||||
str_ = s.str_;
|
||||
OSAtomicIncrement32Barrier(&count());
|
||||
if (OSAtomicDecrement32((count_t*)(p-sizeof(count_t))) < 0)
|
||||
__sync_add_and_fetch(&count(), 1);
|
||||
if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), -1) < 0)
|
||||
delete [] (p-offset);
|
||||
return *this;
|
||||
}
|
||||
@@ -76,7 +75,7 @@ __libcpp_nmstr::operator=(const __libcpp_nmstr& s)
|
||||
inline
|
||||
__libcpp_nmstr::~__libcpp_nmstr()
|
||||
{
|
||||
if (OSAtomicDecrement32(&count()) < 0)
|
||||
if (__sync_add_and_fetch(&count(), -1) < 0)
|
||||
delete [] (str_ - offset);
|
||||
}
|
||||
|
||||
|
@@ -64,9 +64,11 @@ __generic_error_category::name() const
|
||||
string
|
||||
__generic_error_category::message(int ev) const
|
||||
{
|
||||
if (ev <= ELAST)
|
||||
return __do_message::message(ev);
|
||||
return string("unspecified generic_category error");
|
||||
#ifdef ELAST
|
||||
if (ev > ELAST)
|
||||
return string("unspecified generic_category error");
|
||||
#endif
|
||||
return __do_message::message(ev);
|
||||
}
|
||||
|
||||
const error_category&
|
||||
@@ -94,17 +96,21 @@ __system_error_category::name() const
|
||||
string
|
||||
__system_error_category::message(int ev) const
|
||||
{
|
||||
if (ev <= ELAST)
|
||||
return __do_message::message(ev);
|
||||
return string("unspecified system_category error");
|
||||
#ifdef ELAST
|
||||
if (ev > ELAST)
|
||||
return string("unspecified system_category error");
|
||||
#endif
|
||||
return __do_message::message(ev);
|
||||
}
|
||||
|
||||
error_condition
|
||||
__system_error_category::default_error_condition(int ev) const
|
||||
{
|
||||
if (ev <= ELAST)
|
||||
return error_condition(ev, generic_category());
|
||||
return error_condition(ev, system_category());
|
||||
#ifdef ELAST
|
||||
if (ev > ELAST)
|
||||
return error_condition(ev, system_category());
|
||||
#endif
|
||||
return error_condition(ev, generic_category());
|
||||
}
|
||||
|
||||
const error_category&
|
||||
|
@@ -15,7 +15,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
|
||||
|
||||
thread::~thread()
|
||||
{
|
||||
if (__t_ != nullptr)
|
||||
if (__t_ != 0)
|
||||
terminate();
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ thread::join()
|
||||
int ec = pthread_join(__t_, 0);
|
||||
if (ec)
|
||||
throw system_error(error_code(ec, system_category()), "thread::join failed");
|
||||
__t_ = nullptr;
|
||||
__t_ = 0;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -45,11 +45,17 @@ thread::detach()
|
||||
unsigned
|
||||
thread::hardware_concurrency()
|
||||
{
|
||||
#if defined(CTL_HW) && defined(HW_NCPU)
|
||||
int n;
|
||||
int mib[2] = {CTL_HW, HW_NCPU};
|
||||
std::size_t s = sizeof(n);
|
||||
sysctl(mib, 2, &n, &s, 0, 0);
|
||||
return n;
|
||||
#else // !defined(CTL_HW && HW_NCPU)
|
||||
// TODO: grovel through /proc or check cpuid on x86 and similar
|
||||
// instructions on other architectures.
|
||||
return 0; // Means not computable [thread.thread.static]
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace this_thread
|
||||
|
Reference in New Issue
Block a user