Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert __sync* built-ins to std::atomic #265

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/torrent/utils/thread_interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#ifndef LIBTORRENT_UTILS_THREAD_INTERRUPT_H
#define LIBTORRENT_UTILS_THREAD_INTERRUPT_H

#include "config.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should never be in a header file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no quarrel with that, but it throws off clang-tidy since it can't infer what lt_cacheline_aligned is.


#include <utility>
#include <atomic>
#include <torrent/event.h>
Expand Down
2 changes: 2 additions & 0 deletions src/utils/instrumentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#ifndef LIBTORRENT_UTILS_INSTRUMENTATION_H
#define LIBTORRENT_UTILS_INSTRUMENTATION_H

#include "config.h"

#include <algorithm>
#include <array>
#include <atomic>
Expand Down
24 changes: 12 additions & 12 deletions test/helpers/test_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@ const int test_thread::test_flag_pre_poke;
const int test_thread::test_flag_post_poke;

test_thread::test_thread() :
m_test_state(TEST_NONE),
m_test_flags(0) {
m_testState(TEST_NONE),
m_testFlags(0) {
}

void
test_thread::init_thread() {
m_state = STATE_INITIALIZED;
m_test_state = TEST_PRE_START;
m_testState = TEST_PRE_START;
m_poll = torrent::PollSelect::create(256);
}

void
test_thread::call_events() {
if ((m_test_flags & test_flag_pre_stop) && m_test_state == TEST_PRE_START && m_state == STATE_ACTIVE)
m_test_state = TEST_PRE_STOP;
if ((m_testFlags & test_flag_pre_stop) && m_testState == TEST_PRE_START && m_state == STATE_ACTIVE)
m_testState = TEST_PRE_STOP;

if ((m_test_flags & test_flag_acquire_global)) {
if ((m_testFlags & test_flag_acquire_global)) {
acquire_global_lock();
m_test_flags &= ~test_flag_acquire_global;
m_test_flags |= test_flag_has_global;
m_testFlags &= ~test_flag_acquire_global;
m_testFlags |= test_flag_has_global;
}

if ((m_flags & flag_do_shutdown)) {
Expand All @@ -50,15 +50,15 @@ test_thread::call_events() {
throw torrent::shutdown_exception();
}

if ((m_test_flags & test_flag_pre_poke)) {
if ((m_testFlags & test_flag_pre_poke)) {
}

if ((m_test_flags & test_flag_do_work)) {
if ((m_testFlags & test_flag_do_work)) {
usleep(10 * 1000); // TODO: Don't just sleep, as that give up core.
m_test_flags &= ~test_flag_do_work;
m_testFlags &= ~test_flag_do_work;
}

if ((m_test_flags & test_flag_post_poke)) {
if ((m_testFlags & test_flag_post_poke)) {
}
}

Expand Down
20 changes: 10 additions & 10 deletions test/helpers/test_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ class test_thread : public torrent::thread_base {

test_thread();

int test_state() const { return m_test_state; }
int test_state() const { return m_testState; }
bool is_state(int state) const { return m_state == state; }
bool is_test_state(int state) const { return m_test_state == state; }
bool is_test_flags(int flags) const { return (m_test_flags & flags) == flags; }
bool is_not_test_flags(int flags) const { return !(m_test_flags & flags); }
bool is_test_state(int state) const { return m_testState == state; }
bool is_test_flags(int flags) const { return (m_testFlags & flags) == flags; }
bool is_not_test_flags(int flags) const { return !(m_testFlags & flags); }

auto name() const -> const char* { return "test_thread"; }

void init_thread();

void set_pre_stop() { m_test_flags |= test_flag_pre_stop; }
void set_acquire_global() { m_test_flags |= test_flag_acquire_global; }
void set_pre_stop() { m_testFlags |= test_flag_pre_stop; }
void set_acquire_global() { m_testFlags |= test_flag_acquire_global; }

void set_test_flag(int flags) { m_test_flags |= flags; }
void set_test_flag(int flags) { m_testFlags |= flags; }

private:
void call_events();
int64_t next_timeout_usec() { return (m_test_flags & test_flag_long_timeout) ? (10000 * 1000) : (100 * 1000); }
int64_t next_timeout_usec() { return (m_testFlags & test_flag_long_timeout) ? (10000 * 1000) : (100 * 1000); }

std::atomic<int> m_test_state lt_cacheline_aligned;
std::atomic<int> m_test_flags lt_cacheline_aligned;
std::atomic<int> m_testState lt_cacheline_aligned;
std::atomic<int> m_testFlags lt_cacheline_aligned;
};

struct thread_management_type {
Expand Down
111 changes: 0 additions & 111 deletions test/torrent/task_manager_test.cc

This file was deleted.

28 changes: 0 additions & 28 deletions test/torrent/task_manager_test.h

This file was deleted.