Skip to content

Commit

Permalink
Squashed 'externals/nitro/' changes from abf559925..9e5cd6e6f
Browse files Browse the repository at this point in the history
9e5cd6e6f Merge commit '318a3825b20d34fdbfd12a4c5bf800f8b9ed162b' into cpp17
318a3825b Squashed 'externals/coda-oss/' changes from 808c64e9ec..8abcb1825d
1376ba1e8 Merge branch 'main' into cpp17
089ba0b5b latest from coda-oss
3b52f0025 latest from coda-oss (#547)
90c6263e2 latest from coda-oss (#544)

git-subtree-dir: externals/nitro
git-subtree-split: 9e5cd6e6f45efb83a93f2f6ea045eaca26327e62
  • Loading branch information
Dan Smith authored and Dan Smith committed May 15, 2023
1 parent afbd000 commit bd9f16e
Show file tree
Hide file tree
Showing 14 changed files with 539 additions and 123 deletions.
6 changes: 3 additions & 3 deletions externals/coda-oss/.github/workflows/build_unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ jobs:
- name: test
run: |
cd target-Release
ctest -C Release
ctest -C Release --output-on-failure
cd ..
cd target-Debug
ctest -C Debug
ctest -C Debug --output-on-failure
build-linux-cmake:
strategy:
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- name: test
run: |
cd target
ctest
ctest --output-on-failure
build-waf:
strategy:
Expand Down
4 changes: 2 additions & 2 deletions externals/coda-oss/modules/c++/gsl/include/gsl/Gsl_.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "gsl/Gsl_narrow.h"

#include "gsl/use_gsl.h" // Can't compile all of GSL with older versions of GCC/MSVC
#if !CODA_OSS_gsl_use_real_gsl_
#if !CODA_OSS_use_real_gsl_
// Add to "gsl" if we're not using the real thing
namespace gsl
{
Expand All @@ -45,6 +45,6 @@ namespace gsl
return Gsl::narrow<T>(u);
}
}
#endif // CODA_OSS_gsl_use_real_gsl_
#endif // CODA_OSS_coda_oss_use_real_gsl_

#endif // CODA_OSS_gsl_Gsl__h_INCLUDED_
3 changes: 2 additions & 1 deletion externals/coda-oss/modules/c++/gsl/include/gsl/gsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
// always compile Gsl (not "gsl") code--our own simple implementation
#include "gsl/Gsl_.h" // our own "fake" GSL

#if CODA_OSS_gsl_use_real_gsl_
#if CODA_OSS_use_real_gsl_
CODA_OSS_disable_warning_push
#if _MSC_VER
#pragma warning(disable: 4619) // #pragma warning : there is no warning number '..'
#pragma warning(disable: 4626) // '...' : assignment operator was implicitly defined as deleted
#pragma warning(disable: 5027) // '...' : move assignment operator was implicitly defined as deleted
#pragma warning(disable: 26487) // Don 't return a pointer '...' that may be invalid (lifetime.4).
Expand Down
8 changes: 4 additions & 4 deletions externals/coda-oss/modules/c++/gsl/include/gsl/use_gsl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
#pragma once

// Need a fairly decent C++ compiler to use the real GSL
#ifndef CODA_OSS_coda_oss_use_real_gsl_
#ifndef CODA_OSS_use_real_gsl_
#if defined(_MSC_VER)
// need VS2017 or later to compile the real GSL code
#define CODA_OSS_coda_oss_use_real_gsl_ (_MSC_VER >= 1910) // VS2017: https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-160
#define CODA_OSS_use_real_gsl_ (_MSC_VER >= 1910) // VS2017: https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-160
#elif defined (__GNUC__)
// GCC 4.9.1 and 4.9.4 won't compile GSL
#define CODA_OSS_coda_oss_use_real_gsl_ (__GNUC__ >= 5)
#define CODA_OSS_use_real_gsl_ (__GNUC__ >= 5)
#else
// assume GSL can be compiled with any C++14 compiler
#include "coda_oss/CPlusPlus.h"
#define CODA_OSS_coda_oss_use_real_gsl_ CODA_OSS_cpp14
#define CODA_OSS_use_real_gsl_ CODA_OSS_cpp14
#endif
#endif

Expand Down
39 changes: 5 additions & 34 deletions externals/coda-oss/modules/c++/mt/include/mt/Algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,12 @@

namespace mt
{
namespace details
{
template <typename InputIt, typename OutputIt, typename TFunc>
inline OutputIt transform_async(const InputIt first1, const InputIt last1, OutputIt d_first, TFunc f,
typename std::iterator_traits<InputIt>::difference_type cutoff, std::launch policy)
{
// https://en.cppreference.com/w/cpp/thread/async
const auto len = std::distance(first1, last1);
if (len < cutoff)
{
return std::transform(first1, last1, d_first, f);
}

const auto mid1 = first1 + len / 2;
const auto d_mid = d_first + len / 2;
auto handle = std::async(policy, transform_async<InputIt, OutputIt, TFunc>, mid1, last1, d_mid, f, cutoff, policy);
details::transform_async(first1, mid1, d_first, f, cutoff, policy);
return handle.get();
}
}
template <typename InputIt, typename OutputIt, typename TFunc>
inline OutputIt transform_async(const InputIt first1, const InputIt last1, OutputIt d_first, TFunc f,
typename std::iterator_traits<InputIt>::difference_type cutoff, std::launch policy)
{
// details::... eliminates the overload
return details::transform_async(first1, last1, d_first, f, cutoff, policy);
}
template <typename InputIt, typename OutputIt, typename TFunc>
inline OutputIt transform_async(const InputIt first1, const InputIt last1, OutputIt d_first, TFunc f,
typename std::iterator_traits<InputIt>::difference_type cutoff)
{
const std::launch policy = std::launch::deferred | std::launch::async;
return transform_async(first1, last1, d_first, f, cutoff, policy);
// There was a transform_async() utility here, but I removed it.
//
// First of all, C++11's std::async() is now (in 2023) thought of as maybe a
// bit "half baked," and perhaps shouldn't be emulated. Then, C++17 added
// parallel algorithms which might be a better ... although we're still at C++14.
}

}
#endif // CODA_OSS_mt_Algorithm_h_INCLUDED_

24 changes: 0 additions & 24 deletions externals/coda-oss/modules/c++/mt/unittests/Runnable1DTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,7 @@ TEST_CASE(Runnable1DWithCopiesTest)
TEST_ASSERT_TRUE(true); // need to use hidden "testName" parameter
}

TEST_CASE(transform_async_test)
{
const auto f = [&](const int& i) { return i * i; };

std::vector<int> ints_(10000);
std::iota(ints_.begin(), ints_.end(), 1);
const auto& ints = ints_;

std::vector<int> results(ints.size());

results.back() = results.front();
std::transform(ints.begin(), ints.end(), results.begin(), f);
TEST_ASSERT_EQ(results.back(), f(ints.back()));

results.back() = results.front();
mt::transform_async(ints.begin(), ints.end(), results.begin(), f, 1000);
TEST_ASSERT_EQ(results.back(), f(ints.back()));

results.back() = results.front();
mt::transform_async(ints.begin(), ints.end(), results.begin(), f, 1000, std::launch::async);
TEST_ASSERT_EQ(results.back(), f(ints.back()));
}

TEST_MAIN(
TEST_CHECK(DoRunnable1DTest);
TEST_CHECK(Runnable1DWithCopiesTest);
TEST_CHECK(transform_async_test);
)
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static std::string to_native(coda_oss::u8string::const_pointer p, size_t sz)
}
if (Platform == PlatformType::Linux)
{
return str::cast<std::string::const_pointer>(p); // copy
return std::string(str::cast<std::string::const_pointer>(p), sz);
}
throw std::logic_error("Unknown platform.");
}
Expand All @@ -75,7 +75,7 @@ static std::string to_native(str::W1252string::const_pointer p, size_t sz)
{
if (Platform == PlatformType::Windows)
{
return str::cast<std::string::const_pointer>(p); // copy
return std::string(str::cast<std::string::const_pointer>(p), sz);
}
if (Platform == PlatformType::Linux)
{
Expand Down
Loading

0 comments on commit bd9f16e

Please sign in to comment.