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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
   Copyright (c) 2018 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _TASKS_H_
#define _TASKS_H_

#include "Platform/Threading/Headers/ThreadPool.h"
#include "Platform/Headers/PlatformDefines.h"

namespace Divide {

class Application;

class TaskPool;

/**
 *@brief Using std::atomic for thread-shared data to avoid locking
 */
class Task : public GUIDWrapper, protected NonCopyable {
   public:
       static constexpr U16 MAX_CHILD_TASKS = to_base(std::numeric_limits<I8>::max());

       enum class TaskPriority : U32 {
           DONT_CARE = 0,
           LOW = 1,
           MEDIUM = 2,
           HIGH = 3,
           MAX = 4,
           REALTIME = 5, //<= not threaded
           REALTIME_WITH_CALLBACK = 6, //<= not threaded
           COUNT
       };

      enum class TaskFlags : U32 {
        PRINT_DEBUG_INFO = toBit(1),
        COUNT = 1,
      };

    Task();
    ~Task();

    void startTask(TaskPriority priority = TaskPriority::DONT_CARE,
                   U32 taskFlags = 0);

    void stopTask();

    void reset();

    bool isRunning() const;

    inline TaskPool& getOwningPool() noexcept {
        assert(_tp != nullptr);
        return *_tp;
    }

    inline I64 jobIdentifier() const noexcept {
        return _jobIdentifier;
    }

    inline U32 poolIndex() const noexcept {
        return _poolIndex;
    }

    inline bool stopRequested() const noexcept {
        return _stopRequested;
    }

    inline void threadedCallback(const DELEGATE_CBK<void, const Task&>& cbk, I64 jobIdentifier) {
        _callback = cbk;
        _jobIdentifier = jobIdentifier;
    }

    Task* addChildTask(Task* task);

    void wait();

   protected:
    friend class TaskPool;
    inline void setPoolIndex(TaskPool* const pool, U32 index) noexcept {
        _tp = pool;
        _poolIndex = index;
    }
   protected:
    void run();
    void runTaskWithDebugInfo();
    vectorAlg::vecSize childTaskCount() const;
    void removeChildTask(const Task& child);
    PoolTask getRunTask(TaskPriority priority, U32 taskFlags);

   private:
    mutable std::mutex _taskDoneMutex;
    std::condition_variable _taskDoneCV;

    I64 _jobIdentifier;

    std::atomic_bool _stopRequested;

    DELEGATE_CBK<void, const Task&> _callback;
    
    TaskPriority _priority;
    TaskPool* _tp;
    U32 _poolIndex;

    Task* _parentTask;

    mutable std::mutex _childTaskMutex;
    std::condition_variable _childTaskCV;

    vectorImpl<Task*> _childTasks;
    std::atomic<std::thread::id> _taskThread;
};

// A task object may be used for multiple jobs
struct TaskHandle {
    explicit TaskHandle(Task* task, I64 id)  noexcept
        : _task(task),
          _jobIdentifier(id)
    {
    }

    inline TaskHandle& startTask(Task::TaskPriority prio = Task::TaskPriority::DONT_CARE,
                                 U32 taskFlags = 0) {
        assert(_task != nullptr);
        _task->startTask(prio, taskFlags);
        return *this;
    }

    inline Task* addChildTask(const TaskHandle& taskHandle) {
        Task* task = taskHandle._task;
        assert(_task != nullptr);
        return _task->addChildTask(task);
    }

    inline TaskHandle& wait() {
        if (_task != nullptr) {
            _task->wait();
        }
        return *this;
    }

    Task* _task;
    I64 _jobIdentifier;
};


};  // namespace Divide

#endif

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

Diff revisions: vs.
Revision Author Commited Message
1029 Diff Diff IonutCava picture IonutCava Tue 30 Jan, 2018 17:28:39 +0000

[Ionut]
- Update copyright notices

1012 Diff Diff IonutCava picture IonutCava Mon 15 Jan, 2018 17:21:32 +0000

[Ionut]
- Update boost to v1.66
- Performance optimizations

993 Diff Diff IonutCava picture IonutCava Sun 10 Dec, 2017 20:07:57 +0000

[Ionut]
- Finished initial port of the old scene graph system to the new ECS based system.
- Finished converting 2 components to the new ECS system: Transform and RigidBody
- Fixed the “Deploy” build error with the CEGUI OpenGL renderer.
- Compilation now needs C++14 support (it’s sufficiently wide-spread now)

945 Diff Diff IonutCava picture IonutCava Wed 13 Sep, 2017 11:50:59 +0000

[Ionut]
- Rework Task <-> TaskPool work status signalling
- Add UniqueLock typedef

943 Diff Diff IonutCava picture IonutCava Tue 12 Sep, 2017 11:38:52 +0000

[IonutCava]
- Rework ThreadPool/Task system for clearer parent<->child relationship between tasks
— Disable Prio pool since it doesn’t work properly with the newest boost libraries
— Modify the C++11 threadpool to remove the boost dependency
- Reduce memory usage by allocating command buffers on use instead of on creation

909 Diff Diff IonutCava picture IonutCava Thu 29 Jun, 2017 23:57:18 +0000

[Ionut]
- Rework RenderTarget class
— RTAttachment now deal with textures directly
— RT size needs to be specified upfront
- Application class is no longer a Singleton but passed around in the PlatformContext

896 Diff Diff IonutCava picture IonutCava Thu 22 Jun, 2017 16:13:10 +0000

[Ionut]
- Add vs140 platform support
- Remove GPU sync options for tasks. This should be an API-level capability.

873 Diff Diff IonutCava picture IonutCava Thu 09 Mar, 2017 16:11:50 +0000

[IonutCava]
- Add support for swapping threadpool implementations
- Add 3 threadpool implementations: boost priority pool, boost fifo pool and CTPL (https://github.com/vit-vit/CTPL)

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.