Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
RichieSams committed Jan 17, 2021
1 parent 8af2879 commit 3e3e99d
Show file tree
Hide file tree
Showing 16 changed files with 116 additions and 107 deletions.
16 changes: 8 additions & 8 deletions README.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,22 @@ int main() {
taskScheduler.Init();
// Define the constants to test
constexpr uint64_t triangleNum = 47593243ull;
constexpr uint64_t numAdditionsPerTask = 10000ull;
constexpr uint64_t numTasks = (triangleNum + numAdditionsPerTask - 1ull) / numAdditionsPerTask;
constexpr uint64_t triangleNum = 47593243ULL;
constexpr uint64_t numAdditionsPerTask = 10000ULL;
constexpr uint64_t numTasks = (triangleNum + numAdditionsPerTask - 1ULL) / numAdditionsPerTask;
// Create the tasks
// FTL allows you to create Tasks on the stack.
// However, in this case, that would cause a stack overflow
ftl::Task *tasks = new ftl::Task[numTasks];
NumberSubset *subsets = new NumberSubset[numTasks];
uint64_t nextNumber = 1ull;
uint64_t nextNumber = 1ULL;
for (uint64_t i = 0ull; i < numTasks; ++i) {
for (uint64_t i = 0ULL; i < numTasks; ++i) {
NumberSubset *subset = &subsets[i];
subset->start = nextNumber;
subset->end = nextNumber + numAdditionsPerTask - 1ull;
subset->end = nextNumber + numAdditionsPerTask - 1ULL;
if (subset->end > triangleNum) {
subset->end = triangleNum;
}
Expand All @@ -104,13 +104,13 @@ int main() {
taskScheduler.WaitForCounter(&counter);
// Add the results
uint64_t result = 0ull;
uint64_t result = 0ULL;
for (uint64_t i = 0; i < numTasks; ++i) {
result += subsets[i].total;
}
// Test
assert(triangleNum * (triangleNum + 1ull) / 2ull == result);
assert(triangleNum * (triangleNum + 1ULL) / 2ULL == result);
// Cleanup
delete[] subsets;
Expand Down
16 changes: 8 additions & 8 deletions examples/triangle_num.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ int main() {
taskScheduler.Init();

// Define the constants to test
constexpr uint64_t triangleNum = 47593243ull;
constexpr uint64_t numAdditionsPerTask = 10000ull;
constexpr uint64_t numTasks = (triangleNum + numAdditionsPerTask - 1ull) / numAdditionsPerTask;
constexpr uint64_t triangleNum = 47593243ULL;
constexpr uint64_t numAdditionsPerTask = 10000ULL;
constexpr uint64_t numTasks = (triangleNum + numAdditionsPerTask - 1ULL) / numAdditionsPerTask;

// Create the tasks
// FTL allows you to create Tasks on the stack.
// However, in this case, that would cause a stack overflow
ftl::Task *tasks = new ftl::Task[numTasks];
NumberSubset *subsets = new NumberSubset[numTasks];
uint64_t nextNumber = 1ull;
uint64_t nextNumber = 1ULL;

for (uint64_t i = 0ull; i < numTasks; ++i) {
for (uint64_t i = 0ULL; i < numTasks; ++i) {
NumberSubset *subset = &subsets[i];

subset->start = nextNumber;
subset->end = nextNumber + numAdditionsPerTask - 1ull;
subset->end = nextNumber + numAdditionsPerTask - 1ULL;
if (subset->end > triangleNum) {
subset->end = triangleNum;
}
Expand All @@ -84,13 +84,13 @@ int main() {
taskScheduler.WaitForCounter(&counter);

// Add the results
uint64_t result = 0ull;
uint64_t result = 0ULL;
for (uint64_t i = 0; i < numTasks; ++i) {
result += subsets[i].total;
}

// Test
assert(triangleNum * (triangleNum + 1ull) / 2ull == result);
assert(triangleNum * (triangleNum + 1ULL) / 2ULL == result);

// Cleanup
delete[] subsets;
Expand Down
6 changes: 4 additions & 2 deletions include/ftl/atomic_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
namespace ftl {

/**
* FullAtomicCounter implements TaskCounter and adds the full function set
* FullAtomicCounter implements the full set of functions
* of an atomic (with more overhead vs TaskCounter)
*/
class FullAtomicCounter : public BaseCounter {
Expand All @@ -42,6 +42,7 @@ class FullAtomicCounter : public BaseCounter {
FullAtomicCounter(FullAtomicCounter &&) noexcept = delete;
FullAtomicCounter &operator=(FullAtomicCounter const &) = delete;
FullAtomicCounter &operator=(FullAtomicCounter &&) noexcept = delete;
~FullAtomicCounter() = default;

public:
/**
Expand Down Expand Up @@ -137,7 +138,7 @@ class FullAtomicCounter : public BaseCounter {
};

/**
* AtomicFlag implements TaskCounter and adds Set/Clear
* AtomicFlag implements a simple Set/Clear counter
*/
class AtomicFlag : public BaseCounter {
public:
Expand All @@ -149,6 +150,7 @@ class AtomicFlag : public BaseCounter {
AtomicFlag(AtomicFlag &&) noexcept = delete;
AtomicFlag &operator=(AtomicFlag const &) = delete;
AtomicFlag &operator=(AtomicFlag &&) noexcept = delete;
~AtomicFlag() = default;

public:
bool Set(std::memory_order const memoryOrder = std::memory_order_seq_cst) {
Expand Down
6 changes: 3 additions & 3 deletions include/ftl/base_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

#include <atomic>
#include <limits>
#include <thread>
#include <vector>

namespace ftl {

Expand All @@ -51,11 +49,13 @@ class TaskScheduler;
/**
* BaseCounter is a wrapper over a C++11 atomic_unsigned
* It implements the base logic for the rest of the AtomicCounter-type classes
*
* You should never use this class directly. Use the other AtomicCounter-type classes
*/
class BaseCounter {

public:
explicit BaseCounter(TaskScheduler *taskScheduler, unsigned const initialValue = 0, unsigned const fiberSlots = NUM_WAITING_FIBER_SLOTS);
explicit BaseCounter(TaskScheduler *taskScheduler, unsigned initialValue = 0, unsigned fiberSlots = NUM_WAITING_FIBER_SLOTS);

BaseCounter(BaseCounter const &) = delete;
BaseCounter(BaseCounter &&) noexcept = delete;
Expand Down
8 changes: 4 additions & 4 deletions include/ftl/callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ enum class FiberState : int {
Detached
};

typedef void (*ThreadCreationCallback)(void *context, unsigned threadCount);
typedef void (*FiberCreationCallback)(void *context, unsigned fiberCount);
typedef void (*ThreadEventCallback)(void *context, unsigned threadIndex);
typedef void (*FiberEventCallback)(void *context, unsigned fiberIndex, FiberState newState);
using ThreadCreationCallback = void (*)(void *context, unsigned threadCount);
using FiberCreationCallback = void (*)(void *context, unsigned fiberCount);
using ThreadEventCallback = void (*)(void *context, unsigned threadIndex);
using FiberEventCallback = void (*)(void *context, unsigned fiberIndex, FiberState newState);

struct EventCallbacks {
void *Context = nullptr;
Expand Down
8 changes: 0 additions & 8 deletions include/ftl/fibtex.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@
#include "ftl/atomic_counter.h"
#include "ftl/task_scheduler.h"

#include <cassert>
#include <mutex>
#include <system_error>

namespace ftl {
// Pull std helpers into ftl namespace
using std::adopt_lock;
using std::defer_lock;
using std::try_to_lock;

/**
* A fiber aware mutex. Does not block in the traditional way. Methods do not follow the lowerCamelCase convention
Expand Down
1 change: 1 addition & 0 deletions include/ftl/task_counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class TaskCounter : public BaseCounter {
TaskCounter(TaskCounter &&) noexcept = delete;
TaskCounter &operator=(TaskCounter const &) = delete;
TaskCounter &operator=(TaskCounter &&) noexcept = delete;
~TaskCounter() = default;

public:
/**
Expand Down
11 changes: 3 additions & 8 deletions include/ftl/task_scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "ftl/wait_free_queue.h"

#include <atomic>
#include <climits>
#include <condition_variable>
#include <mutex>
#include <vector>
Expand All @@ -44,9 +43,6 @@ class AtomicFlag;
class FullAtomicCounter;

enum class EmptyQueueBehavior {
// Fixing this will break api.
// ReSharper disable CppInconsistentNaming

// Spin in a loop, actively searching for tasks
Spin,
// Same as spin, except yields to the OS after each round of searching
Expand Down Expand Up @@ -132,6 +128,8 @@ class TaskScheduler {
};

struct ReadyFiberBundle {
ReadyFiberBundle() = default;

// The fiber
unsigned FiberIndex;
// A flag used to signal if the fiber has been successfully switched out of and "cleaned up". See @CleanUpOldFiber()
Expand Down Expand Up @@ -251,7 +249,6 @@ class TaskScheduler {
* Yields execution to another task until counter == 0
*
* @param counter The counter to check
* @param value The value to wait for
* @param pinToCurrentThread If true, the task invoking this call will not resume on a different thread
*/
void WaitForCounter(TaskCounter *counter, bool pinToCurrentThread = false);
Expand All @@ -260,7 +257,6 @@ class TaskScheduler {
* Yields execution to another task until counter == 0
*
* @param counter The counter to check
* @param value The value to wait for
* @param pinToCurrentThread If true, the task invoking this call will not resume on a different thread
*/
void WaitForCounter(AtomicFlag *counter, bool pinToCurrentThread = false);
Expand Down Expand Up @@ -371,8 +367,7 @@ class TaskScheduler {
* for a new task
*
* @param pinnedThreadIndex The index of the thread this fiber is pinned to. If not pinned, this will equal kNoThreadPinning
* @param fiberIndex The index of the fiber to add
* @param fiberStoredFlag A flag used to signal if the fiber has been successfully switched out of and "cleaned
* @param bundle The fiber bundle to add
* up"
*/
void AddReadyFiber(unsigned pinnedThreadIndex, ReadyFiberBundle *bundle);
Expand Down
20 changes: 11 additions & 9 deletions include/ftl/thread_abstraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@
// Forward declare the platform types so we don't have to include their heavy header files
#if defined(FTL_WIN32_THREADS)

typedef void *HANDLE;
typedef unsigned long DWORD;
typedef void *HANDLE; // NOLINT(modernize-use-using)
typedef unsigned long DWORD; // NOLINT(modernize-use-using)

#elif defined(FTL_POSIX_THREADS)

# if defined(FTL_OS_LINUX)
typedef unsigned long int pthread_t;
typedef unsigned long int pthread_t; // NOLINT(modernize-use-using)
# elif defined(FTL_OS_APPLE)
struct _opaque_pthread_t;
typedef struct _opaque_pthread_t *__darwin_pthread_t;
typedef __darwin_pthread_t pthread_t;
typedef struct _opaque_pthread_t *__darwin_pthread_t; // NOLINT(modernize-use-using)
typedef __darwin_pthread_t pthread_t; // NOLINT(modernize-use-using)
# endif
#endif

Expand All @@ -55,18 +55,18 @@ struct Win32Thread {
DWORD Id;
};

typedef Win32Thread ThreadType;
typedef Win32Thread ThreadType; // NOLINT(modernize-use-using)

typedef unsigned int(__stdcall *ThreadStartRoutine)(void *arg);
typedef unsigned int(__stdcall *ThreadStartRoutine)(void *arg); // NOLINT(modernize-use-using)
# define FTL_THREAD_FUNC_RETURN_TYPE unsigned int
# define FTL_THREAD_FUNC_DECL FTL_THREAD_FUNC_RETURN_TYPE __stdcall
# define FTL_THREAD_FUNC_END return 0

#elif defined(FTL_POSIX_THREADS)

typedef pthread_t ThreadType;
typedef pthread_t ThreadType; // NOLINT(modernize-use-using)

typedef void *(*ThreadStartRoutine)(void *arg);
typedef void *(*ThreadStartRoutine)(void *arg); // NOLINT(modernize-use-using)
# define FTL_THREAD_FUNC_RETURN_TYPE void *
# define FTL_THREAD_FUNC_DECL FTL_THREAD_FUNC_RETURN_TYPE
# define FTL_THREAD_FUNC_END return nullptr
Expand All @@ -81,6 +81,7 @@ typedef void *(*ThreadStartRoutine)(void *arg);
* @param stackSize The size of the stack
* @param startRoutine The start routine
* @param arg The argument for the start routine
* @param name The name of the thread
* @param returnThread The handle for the newly created thread. Undefined if thread creation fails
* @return True if thread creation succeeds, false if it fails
*/
Expand All @@ -91,6 +92,7 @@ bool CreateThread(size_t stackSize, ThreadStartRoutine startRoutine, void *arg,
* @param stackSize The size of the stack
* @param startRoutine The start routine
* @param arg The argument for the start routine
* @param name The name of the thread
* @param coreAffinity The core affinity
* @param returnThread The handle for the newly created thread. Undefined if thread creation fails
* @return True if thread creation succeeds, false if it fails
Expand Down
4 changes: 3 additions & 1 deletion source/base_counter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
#include "ftl/ftl_valgrind.h"
#include "ftl/task_scheduler.h"

#include <thread>

namespace ftl {

BaseCounter::BaseCounter(TaskScheduler *const taskScheduler, unsigned const initialValue, unsigned const fiberSlots)
BaseCounter::BaseCounter(TaskScheduler *const taskScheduler, unsigned initialValue, unsigned fiberSlots)
: m_taskScheduler(taskScheduler), m_value(initialValue), m_lock(0), m_fiberSlots(fiberSlots) {
m_freeSlots = new std::atomic<bool>[fiberSlots];
m_waitingFibers = new WaitingFiberBundle[fiberSlots];
Expand Down
Loading

0 comments on commit 3e3e99d

Please sign in to comment.