Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "Headers/Task.h"

#include "Core/Headers/Kernel.h"
#include "Core/Headers/Console.h"
#include "Core/Headers/Application.h"
#include "Core/Headers/ApplicationTimer.h"
#include "Utility/Headers/Localization.h"

#include <chrono>
#include <thread>

namespace Divide {
namespace {
    U64 g_sleepThresholdMS = 5UL;
};

U64 Task::_currentTime = 0UL;

Task::Task(ThreadPool& tp, U64 tickInterval, I32 numberOfTicks,
           const DELEGATE_CBK<>& f)
    : GUIDWrapper(),
      _tp(tp),
      _tickInterval(tickInterval),
      _callback(f)
{
    _numberOfTicks = numberOfTicks;
    _end = false;
    _paused = false;
    _done = false;
}

Task::~Task()
{
    if (_end != true) {
        Console::errorfn(Locale::get(_ID("TASK_DELETE_ACTIVE")));
        stopTask();
    }

    WAIT_FOR_CONDITION(_done || _tp.active() == 0);
}

void Task::updateTickInterval(U64 tickInterval) {
    _tickInterval = std::max(tickInterval, Time::MillisecondsToMicroseconds(1));
}

void Task::updateTickCounter(I32 numberOfTicks) {
    _numberOfTicks = numberOfTicks;
}

void Task::startTask(TaskPriority priority) {
    if (!_tp.schedule(PoolTask(to_uint(priority), DELEGATE_BIND(&Task::run, this))))
    {
        Console::errorfn(Locale::get(_ID("TASK_SCHEDULE_FAIL")));
    }
}

void Task::stopTask() { 
    _end = true;
}

void Task::pauseTask(bool state) {
    _paused = state;
}

void Task::run() {
    Console::d_printfn(Locale::get(_ID("TASK_START_THREAD")), getGUID(), std::this_thread::get_id());

    U64 lastCallTime = _currentTime;
    // 0 == run forever
    if (_numberOfTicks == 0) {
        _numberOfTicks = -1;
    }

    Application& app = Application::getInstance();

    _done = !_callback;
    while (true) {
        if (_numberOfTicks == 0) {
            _end = true;
        }

        if (_end || app.ShutdownRequested()) {
            break;
        }

        if (_paused) {
            continue;
        }

        if (_currentTime >= (lastCallTime + _tickInterval)) {
            _callback();
            if (_numberOfTicks > 0) {
                _numberOfTicks--;
            }
            lastCallTime = _currentTime;
            // Sleep does not guarantee a maximum wait time, just a minimum, so g_sleepThresholdMS should be enough margin
            if (_tickInterval > Time::MillisecondsToMicroseconds(g_sleepThresholdMS)) {
                // If the tick interval is over 'g_sleepThreshold', sleep for at least half of the duration
                std::this_thread::sleep_for(std::chrono::microseconds(_tickInterval / 2));
            }
        }

    }

    Console::d_printfn(Locale::get(_ID("TASK_DELETE_THREAD")), getGUID(), std::this_thread::get_id());

    if (_onCompletionCbk) {
        _onCompletionCbk(getGUID());
    }

    _done = true;
}
};

Commits for Divide-Framework/trunk/Source Code/Platform/Threading/Task.cpp

Diff revisions: vs.
Revision Author Commited Message
631 Diff Diff IonutCava picture IonutCava Sun 24 Jan, 2016 20:28:21 +0000

[IonutCava]
- Fix and optimize particle rendering system
- Temporarily disable Z_PRE_PASS system for testing
- Improve thread pool destruction system a bit
- Fix texture loading when used as fb attachment
- Forward+ renderer now takes the entire light buffer (no need to split up by light type)
- Start work on occlusion culling fixes:
— ToDo: Take into account batching system
— Fix gl_DrawIDARB usage

630 Diff Diff IonutCava picture IonutCava Fri 22 Jan, 2016 17:15:44 +0000

[IonutCava]
- Improve reflection generation system
— Still buggy
- Investigate occlusion culling issue
— Still buggy
- Improve threadpool idle time using main app time and conservative thread sleep calls

577 Diff Diff IonutCava picture IonutCava Fri 20 Nov, 2015 15:59:10 +0000

[IonutCava]
- Replace all string indexed maps with unsigned long long indexed maps and add both compile time and runtime hashing functions to convert strings to the proper indices
— Balancing the calls between _ID and _ID_RT can reduce map lookup overhead, especially with ParamHandler and Locale::get

516 Diff Diff IonutCava picture IonutCava Tue 29 Sep, 2015 18:21:34 +0000

[IonutCava]
- Fixed VBO partitioning system
- Replaced some DELEGATE_BIND calls with lambda expressions
- Some multithreaded rendering work (still not functional)

488 Diff Diff IonutCava picture IonutCava Wed 12 Aug, 2015 18:11:11 +0000

[Ionut]
- Timing related fixes
- Bugfix for lingering debug primitives

468 Diff Diff IonutCava picture IonutCava Mon 08 Jun, 2015 16:13:10 +0000

[Ionut]
- Small bug fix in Task.cpp when iteration count is 1. Guarantee at least a callback call.
- Fixing particle system rendering (part 1)

442 Diff Diff IonutCava picture IonutCava Wed 20 May, 2015 15:25:02 +0000

[Ionut]
- Better platform handling:
— All platform specific code moved in 3 separate files: PlatformDefinesWindows / PlatformDefinesUnix / PlatformDefinesApple
— Added CPU and RAM check at startup to make sure we meet minimum requirements to run properly
- Smart pointers should never used MemoryManager_NEW for allocating memory (MemoryManager_NEW tracks allocations but must be matched with a DELETE call in order to no report leaks). Corrected.
- Zombification of Singletons is only enabled in Debug builds
- Fixed a bug in Task.cpp (nowTime check) that prevented some tasks to run on the first call (changed a ‘>’ check to a ‘>=’)
— This also fixed bounding box computations for skinned submeshes
- Improved dead zone handling for joysticks

427 Diff Diff IonutCava picture IonutCava Sun 10 May, 2015 20:23:07 +0000

[Ionut]
- Multithreaded bounding box calculations for skinned submeshes
- Better PhysicsActor <-> PhysicsComponent coupling
- Changed the ThreadPool model to a priority based system
- Added a ScopedTimer class to simplify timing of functions
- Added a reset system to WarScene to unload and reload all units and AIEntities

412 Diff Diff IonutCava picture IonutCava Mon 27 Apr, 2015 15:37:55 +0000

[Ionut]
- Bug fixes relating to ApplicationTimer (bad conversions, higher precision changes, etc)
- NavMesh loading updates.

350 IonutCava picture IonutCava Tue 10 Feb, 2015 16:25:39 +0000

[Ionut]
- Simplified some Util-namespace level functions by using STL algorithms where possible
- Formatted the entire codebase using clang-format with the following style: "{BasedOnStyle: Google, IndentWidth: 4}"
- Attempted to make ProfileTimer thread-safe (temp fix until std::chrono works properly in Visual Studio)