FiberTaskingLib Documentation

repository·master·Indexed 21 days ago

https://github.com/richiesams/fibertaskinglib

A C++ library for fiber-based tasking. Documentation includes build guides for Windows and Unix systems using CMake, instructions for integrating the ftl target into CMake and non-CMake projects, and comprehensive code style and naming conventions. It also details the use of Catch2 for unit testing and micro-benchmarking within the project.

Tokens
3.8K
Snippets
9
Records
18
Agent score
75%

What's inside FiberTaskingLib

  1. What is Catch2?

    master
    Catch2 is a C++ unit testing framework that also provides micro-benchmarking features and BDD (Behavior-Driven Development) macros. It is designed to be simple and natural to use: test names do not need to be valid identifiers, assertions use standard C++ boolean expressions, and SECTIONs allow for local setup and teardown code sharing within tests.
  2. Include FiberTaskingLib in a non-CMake project

    master

    If your project does not use CMake, you must manually configure your toolchain:

    1. Build FiberTaskingLib using the CMake instructions provided for your platform.
    2. Add the following paths to your project's include directories:
      • {FTL_ROOT}/include
      • {FTL_ROOT}/third_party/boost_context/include
    3. Link against the following libraries built during the build process:
      • ftl.lib
      • boost_context.lib
  3. Follow Git Commit Formatting conventions

    master

    Commit messages must follow the Conventional Commits format to enable automatic semantic-versioning and changelog generation.

    Commit Structure:

    1. Summary Line: <type>[optional scope]: Summarize changes in around 50 characters or less
    2. Blank Line: A blank line separating the summary from the body is critical.
    3. Body: Explain the why (the problem being solved) rather than the how. Mention side effects or unintuitive consequences.
    4. References: If using an issue tracker, place references at the bottom.

    Example Format:

    <type>[optional scope]: Summarize changes in around 50 characters or less
    
    More detailed explanatory text, if necessary. In some contexts, 
    the first line is treated as the subject of the commit and the rest of
    the text as the body. The blank line separating the summary from the body 
    is critical (unless you omit the body entirely); various tools like `log`,
    `shortlog` and `rebase` can get confused if you run the two together.
    
    Explain the problem that this commit is solving. Focus on why you 
    are making this change as opposed to how (the code explains that). 
    Are there side effects or other unintuitive consequences of this 
    change? Here's the place to explain them.
    
    Further paragraphs come after blank lines.
    
    * Bullet points are okay, too
    
    * Typically a hyphen or asterisk is used for the bullet, preceded
       by a single space, with blank lines in between, but conventions
       vary here
    
    If you use an issue tracker, put references to them at the bottom, like this:
    
    Resolves: #123
    See also: #456, #789
    <type>[optional scope]: Summarize changes in around 50 characters or less
    
    More detailed explanatory text, if necessary.
    
    Explain the problem that this commit is solving.
    
    Resolves: #123
  4. Format code using clang-format

    master

    To ensure adherence to FiberTaskingLib's formatting conventions, it is highly recommended to use clang-format. You can configure your IDE to run it on save, or use the provided Makefile command to format the entire codebase using Docker.

    Note: While the documentation uses spaces for visual consistency, actual code must use tabs for indentations. Use spaces only for alignment.

    make format
  5. Structure class and struct definitions

    master

    Classes and structs should follow a specific layout order:

    1. Public Constructors
    2. Public Member Variables
    3. Private Member Variables
    4. Public Methods
    5. Private Methods

    Constructor Initializer Lists

    Initializer lists must start on a new line from the constructor definition, with each entry on its own line and aligned using spaces. The entire list should be indented once if the constructor has no body, or twice if it does.

    class Fiber {
    public:
        Fiber()
            : m_stack(nullptr),
              m_systemPageSize(0),
              m_stackSize(0),
              m_context(nullptr),
              m_arg(0) {
        }
    };
    class ExampleClass {
    public:
        // Constructors
        ExampleClass();
        ExampleClass(ExampleClass &&other);
    
    public:
        // Public member variables
        int Width;
        int Height;
    
    private:
        // Private member variables
        float m_deltaTime;
    
    public:
        // Public methods
        void Rotate();
    
    private:
        // Private methods
        int DecrementHeight(float amount);
    };
  6. Migrate from Catch2 v2 to v3

    master
    Catch2 v3 is no longer a single-header library. It is now a compiled library with multiple headers. If you are migrating from v2.x, you must update your build system to link against the Catch2 library and change your include statements to use the new multi-header structure. Detailed migration guidelines and common problem solutions are available in the project's migration documentation.
  7. Apply whitespace and brace rules

    master

    Braces

    Always use braces for if, for, while, and do-while statements, even for single-line bodies. Braceless statements are highly discouraged.

    Whitespace Rules

    • Operators: Surround conventional operators with spaces: a = (b + c) * d;.
    • Reserved Words: Separate C++ reserved words from opening parentheses: while (true) {.
    • Commas: Follow commas with a space: SomeFunction(a, b, c);.
    • For Statements: Follow semicolons with a space: for (int a = 0; b < c; d++).
    • Colons: Surround colons with whitespace in class inheritance and ternary operators: class BusWheel : public RubberInflatable or (isNight) ? ColorMeDark() : ColorMeBright();.
    • Pointers and References: Use a space before the * or & but not after it: const char *ptr = (const char *)foobar; or int &ref = i;.
    • Templates: No whitespace between the template keyword and <. Place the definition on the line preceding the class/function.
    • Array Delete: No whitespace before []: delete[] foo;.
    • Operator Overloading: Do not separate the operator keyword from the name, except for type conversion operators.

    Indentation

    • Namespaces: Do not increase indentation level after a namespace clause.
    • Access Levels: Do not increase indentation level for access keywords (public:, private:) inside classes.
    • Preprocessor: Preprocessor statements should be at the same indentation level as the surrounding code, but the content of the preprocessor block should be indented.
    • Switch/Case: Align case keywords with the switch keyword. Indent the contents of the case blocks.
  8. Document code using Javadoc style

    master

    Classes, structs, and functions should be documented using the Javadoc style, including @brief, @param, and @return tags.

    /**
     * @brief Adds a group of tasks to the internal queue
     *
     * @param numTasks    The number of tasks
     * @param tasks       The tasks to queue
     * @return            An atomic counter corresponding to the task group as a whole.
     */
    std::shared_ptr<std::atomic_uint> AddTasks(uint numTasks, Task *tasks);
    /**
     * @brief Adds a group of tasks to the internal queue
     *
     * @param numTasks    The number of tasks
     * @param tasks       The tasks to queue
     * @return            An atomic counter corresponding to the task group as a whole. Initially it will equal numTasks. When each task completes, it will be decremented.
     */
    std::shared_ptr<std::atomic_uint> AddTasks(uint numTasks, Task *tasks);
  9. Include FiberTaskingLib in a CMake project

    master

    The recommended way to consume FiberTaskingLib is to include its source directory directly using CMake's add_subdirectory() command. Because FiberTaskingLib is a modern CMake project using target_* functions, linking to the ftl target automatically handles include directories and dependencies.

    Configuration Options

    You can control the build scope using these cache variables:

    • FTL_BUILD_TESTS: Set to ON (default) to build tests, or OFF to skip them.
    • FTL_BUILD_BENCHMARKS: Set to ON to build benchmarks, or OFF to skip them.

    Note: The provided example contains a typo in the source where FTL_BUILD_TESTS is used twice instead of FTL_BUILD_BENCHMARKS for the second option; ensure you use the correct variable name in your project.

    cmake_minimum_required(VERSION 3.8)
    project(MyProject)
    
    # Disable tests and benchmarks to speed up build
    set( FTL_BUILD_TESTS OFF CACHE BOOL "Disable tests" )
    set( FTL_BUILD_BENCHMARKS OFF CACHE BOOL "Disable benchmarks" )
    
    # Add FiberTaskingLib source
    add_subdirectory(third_party/FiberTaskingLib)
    
    # Create your executable
    add_executable(MyProject source/main.cpp)
    target_include_directories(MyProject PRIVATE include)
    
    # Link to FiberTaskingLib (automatically handles includes)
    target_link_libraries(MyProject ftl)