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
1 change: 0 additions & 1 deletion include/bitcoin/protocol/config/authority.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef LIBBITCOIN_PROTOCOL_CONFIG_AUTHORITY_HPP
#define LIBBITCOIN_PROTOCOL_CONFIG_AUTHORITY_HPP

Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/protocol/config/sodium.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ class BCP_API sodium
/// A list of base85 values.
/// This must provide operator<< for ostream in order to be used as a
/// boost::program_options default_value.
typedef std::vector<sodium> list;

sodium() NOEXCEPT;
sodium(const std::string& base85) THROWS;
sodium(const system::hash_digest& value) NOEXCEPT;
Expand All @@ -61,6 +59,8 @@ class BCP_API sodium
system::hash_digest value_;
};

typedef std::vector<sodium> sodiums;

} // namespace protocol
} // namespace libbitcoin

Expand Down
11 changes: 0 additions & 11 deletions include/bitcoin/protocol/define.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@
#define BCP_INTERNAL BC_HELPER_DLL_LOCAL
#endif

// Log name.
////#define LOG_PROTOCOL "protocol"
////#define LOG_PROTOCOL_HTTP "http"
////
////// TODO: generalize logging.
////#define LOG_INFO(name) std::cout << name << " : "
////#define LOG_DEBUG(name) std::cout << name << " : "
////#define LOG_VERBOSE(name) std::cout << name << " : "
////#define LOG_ERROR(name) std::cerr << name << " : "
////#define LOG_WARNING(name) std::cerr << name << " : "

#endif

// context ->
Expand Down
45 changes: 35 additions & 10 deletions include/bitcoin/protocol/network.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,29 @@
// config::authority and config::endpoint are also cloned from network.

#include <memory>
#include <thread>
#include <bitcoin/system.hpp>

#ifdef HAVE_MSC
#include <windows.h>
// #define THREAD_PRIORITY_IDLE -15
// #define THREAD_PRIORITY_LOWEST -2
// #define THREAD_PRIORITY_BELOW_NORMAL -1
// #define THREAD_PRIORITY_NORMAL 0
// #define THREAD_PRIORITY_ABOVE_NORMAL 1
// #define THREAD_PRIORITY_HIGHEST 2
// #define THREAD_PRIORITY_TIME_CRITICAL 15
// #define THREAD_PRIORITY_ERROR_RETURN (MAXLONG)
#else
#include <unistd.h>
#include <pthread.h>
#include <sys/resource.h>
#include <sys/types.h>
#ifndef PRIO_MAX
#define PRIO_MAX 20
#endif
#define THREAD_PRIORITY_ABOVE_NORMAL (-2)
#define THREAD_PRIORITY_NORMAL 0
#define THREAD_PRIORITY_BELOW_NORMAL 2
#define THREAD_PRIORITY_LOWEST PRIO_MAX
#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
#endif

namespace libbitcoin {
Expand All @@ -62,6 +69,7 @@ class enable_shared_from_base

enum class thread_priority
{
highest,
high,
normal,
low,
Expand All @@ -79,26 +87,43 @@ inline int get_priority(thread_priority priority) NOEXCEPT
return THREAD_PRIORITY_BELOW_NORMAL;
case thread_priority::high:
return THREAD_PRIORITY_ABOVE_NORMAL;
case thread_priority::highest:
return THREAD_PRIORITY_HIGHEST;
default:
case thread_priority::normal:
return THREAD_PRIORITY_NORMAL;
}
}

// Set the thread priority (or process if thread priority is not available).
// Set the thread priority.
// TODO: handle error conditions.
// TODO: handle potential lack of PRIO_THREAD
// TODO: use proper non-win32 priority levels.
// TODO: Linux: pthread_setschedprio()
// TOOD: macOS: somethign else.
inline void set_priority(thread_priority priority) NOEXCEPT
{
const auto prioritization = get_priority(priority);

BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
#if defined(HAVE_MSC)
// learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/
// nf-processthreadsapi-getthreadpriority
SetThreadPriority(GetCurrentThread(), prioritization);

#elif defined(PRIO_THREAD)
// lore.kernel.org/lkml/[email protected]/
setpriority(PRIO_THREAD, pthread_self(), prioritization);

#else
// BUGBUG: This will set all threads in the process.
// man7.org/linux/man-pages/man3/pthread_self.3.html
setpriority(PRIO_PROCESS, getpid(), prioritization);
#endif
BC_POP_WARNING()
}

inline size_t cores() NOEXCEPT
{
return std::max(std::thread::hardware_concurrency(), 1_u32);
}

} // namespace protocol
Expand Down
2 changes: 1 addition & 1 deletion install-cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ build_from_tarball_boost()
"$BOOST_CXXFLAGS" \
"$BOOST_LINKFLAGS" \
"link=$BOOST_LINK" \
"warnings=off" \
"warnings=off" \
"boost.locale.iconv=$BOOST_ICU_ICONV" \
"boost.locale.posix=$BOOST_ICU_POSIX" \
"-sNO_BZIP2=1" \
Expand Down
2 changes: 1 addition & 1 deletion install-cmakepresets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ build_from_tarball_boost()
"$BOOST_CXXFLAGS" \
"$BOOST_LINKFLAGS" \
"link=$BOOST_LINK" \
"warnings=off" \
"warnings=off" \
"boost.locale.iconv=$BOOST_ICU_ICONV" \
"boost.locale.posix=$BOOST_ICU_POSIX" \
"-sNO_BZIP2=1" \
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ build_from_tarball_boost()
"$BOOST_CXXFLAGS" \
"$BOOST_LINKFLAGS" \
"link=$BOOST_LINK" \
"warnings=off" \
"warnings=off" \
"boost.locale.iconv=$BOOST_ICU_ICONV" \
"boost.locale.posix=$BOOST_ICU_POSIX" \
"-sNO_BZIP2=1" \
Expand Down
2 changes: 1 addition & 1 deletion src/zmq/authenticator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ authenticator::~authenticator() NOEXCEPT
stop();
}

authenticator::operator context& () NOEXCEPT
authenticator::operator context&() NOEXCEPT
{
return context_;
}
Expand Down
2 changes: 0 additions & 2 deletions src/zmq/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ namespace zmq {

using namespace bc::system;

#define NAME "worker"

// Derive from this abstract worker to implement concrete worker.
worker::worker(thread_priority priority) NOEXCEPT
: priority_(priority),
Expand Down
Loading