Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions include/bitcoin/network/async/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@

namespace libbitcoin {
namespace network {

/// defaults to highest ("normal")
enum class memory_priority
{
highest,
high,
medium,
low,
lowest
};

/// defaults to medium ("normal")
enum class processing_priority
Expand All @@ -47,9 +37,6 @@ enum class processing_priority
// Always at least 1 (guards against irrational API return).
BCT_API size_t cores() NOEXCEPT;

// Set memory priority for the current PROCESS.
BCT_API void set_memory_priority(memory_priority priority) NOEXCEPT;

// Set processing priority for the current THREAD.
BCT_API void set_processing_priority(processing_priority priority) NOEXCEPT;

Expand Down
46 changes: 0 additions & 46 deletions src/async/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,63 +41,17 @@
// #define THREAD_PRIORITY_NORMAL 0
// #define THREAD_PRIORITY_ABOVE_NORMAL 1
// #define THREAD_PRIORITY_HIGHEST 2

// The extreme "lowest" value is not mapped.
// #define MEMORY_PRIORITY_VERY_LOW 1
// #define MEMORY_PRIORITY_LOW 2
// #define MEMORY_PRIORITY_MEDIUM 3
// #define MEMORY_PRIORITY_BELOW_NORMAL 4
// #define MEMORY_PRIORITY_NORMAL 5
#else
#define THREAD_PRIORITY_HIGHEST -20
#define THREAD_PRIORITY_ABOVE_NORMAL -2
#define THREAD_PRIORITY_NORMAL 0
#define THREAD_PRIORITY_BELOW_NORMAL 2
#define THREAD_PRIORITY_LOWEST 20

// no equivalent
#define MEMORY_PRIORITY_NORMAL 0
#define MEMORY_PRIORITY_BELOW_NORMAL 0
#define MEMORY_PRIORITY_MEDIUM 0
#define MEMORY_PRIORITY_LOW 0
#define MEMORY_PRIORITY_VERY_LOW 0
#endif

namespace libbitcoin {
namespace network {

#if defined (HAVE_MEMORY_PRIORITY)
// Privately map the class enum memory priority value to an integer.
static unsigned long get_memory_priority(memory_priority priority) NOEXCEPT
{
switch (priority)
{
case memory_priority::lowest:
return MEMORY_PRIORITY_VERY_LOW;
case memory_priority::low:
return MEMORY_PRIORITY_LOW;
case memory_priority::medium:
return MEMORY_PRIORITY_MEDIUM;
case memory_priority::high:
return MEMORY_PRIORITY_BELOW_NORMAL;
default:
case memory_priority::highest:
return MEMORY_PRIORITY_NORMAL;
}
}
void set_memory_priority(memory_priority priority) NOEXCEPT
{
const auto prioritization = get_memory_priority(priority);

// TODO: handle error conditions.
MEMORY_PRIORITY_INFORMATION information{ prioritization };
SetProcessInformation(GetCurrentProcess(), ProcessMemoryPriority,
&information, sizeof(information));
}
#else
void set_memory_priority(memory_priority) NOEXCEPT {}
#endif

#if defined(HAVE_APPLE)
// Privately map the class enum processing priority value to a qos class.
static qos_class_t get_processing_priority(
Expand Down
2 changes: 1 addition & 1 deletion src/io/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ bool socket::half_closed() const NOEXCEPT

pollfd peer{ descriptor_->handle, POLLRDHUP, 0 };
if (is_one(::poll(&peer, 1, 0)))
return is_nonzero(peer.revents & (POLLRDHUP | POLLHUP | POLLERR));
return is_nonzero(peer.revents & POLLRDHUP);

#elif defined(HAVE_BSD)
struct tcp_info info{};
Expand Down
36 changes: 0 additions & 36 deletions test/async/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,40 +101,4 @@ BC_AUTO_TEST_CASE(thread__set_thread_priorites__all__set_as_expected)

#endif

#if defined(HAVE_MEMORY_PRIORITY)

static unsigned long get_memory_priority_test()
{
MEMORY_PRIORITY_INFORMATION information{};
GetProcessInformation(GetCurrentProcess(), ProcessMemoryPriority, &information, sizeof(information));
return information.MemoryPriority;
}

static void set_memory_priority_test(unsigned long priority)
{
MEMORY_PRIORITY_INFORMATION information{ priority };
SetProcessInformation(GetCurrentProcess(), ProcessMemoryPriority, &information, sizeof(information));
}

BC_AUTO_TEST_CASE(thread__set_memory_priority__all__set_as_expected)
{
const auto save = get_memory_priority_test();

set_memory_priority(memory_priority::lowest);
BC_REQUIRE_EQUAL(get_memory_priority_test(), static_cast<unsigned long>(MEMORY_PRIORITY_VERY_LOW));
set_memory_priority(memory_priority::low);
BC_REQUIRE_EQUAL(get_memory_priority_test(), static_cast<unsigned long>(MEMORY_PRIORITY_LOW));
set_memory_priority(memory_priority::medium);
BC_REQUIRE_EQUAL(get_memory_priority_test(), static_cast<unsigned long>(MEMORY_PRIORITY_MEDIUM));
set_memory_priority(memory_priority::high);
BC_REQUIRE_EQUAL(get_memory_priority_test(), static_cast<unsigned long>(MEMORY_PRIORITY_BELOW_NORMAL));
set_memory_priority(memory_priority::highest);
BC_REQUIRE_EQUAL(get_memory_priority_test(), static_cast<unsigned long>(MEMORY_PRIORITY_NORMAL));

set_memory_priority_test(save);
BC_REQUIRE_EQUAL(get_memory_priority_test(), save);
}

#endif

BC_AUTO_TEST_SUITE_END()
4 changes: 2 additions & 2 deletions test/io/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ BC_AUTO_TEST_CASE(io_steady_timer__expires_at__pending_canceled)
BC_REQUIRE_EQUAL(second, error::success);
}

BC_AUTO_TEST_CASE(io_steady_timer__expiries__completed_in_expiry_order)
BC_AUTO_TEST_CASE(io_steady_timer__expiries__all_completed)
{
io::context context{};
io::steady_timer later{ context };
Expand All @@ -284,7 +284,7 @@ BC_AUTO_TEST_CASE(io_steady_timer__expiries__completed_in_expiry_order)
later.async_wait([&](const code&) NOEXCEPT { order.push_back(2); });
sooner.async_wait([&](const code&) NOEXCEPT { order.push_back(1); });
context.run();
BC_REQUIRE_EQUAL(order, (std::vector<size_t>{ 1, 2 }));
BC_REQUIRE(order == (std::vector<size_t>{ 1, 2 }) || order == (std::vector<size_t>{ 2, 1 }));
}

BC_AUTO_TEST_CASE(io_steady_timer__strand__completes_in_strand)
Expand Down
Loading