diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:17:24 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-04-17 07:21:24 +0300 |
commit | e12c08e8d170b7ca40f204a5b0423c23a9fbc2c1 (patch) | |
tree | 8cf3453d12edb177a218ef8009357518ec6cab6a /intern/cycles/util/util_task.h | |
parent | b3dabc200a4b0399ec6b81f2ff2730d07b44fcaa (diff) |
ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.
For details on usage and instructions for migrating branches
without conflicts, see:
https://wiki.blender.org/wiki/Tools/ClangFormat
Diffstat (limited to 'intern/cycles/util/util_task.h')
-rw-r--r-- | intern/cycles/util/util_task.h | 216 |
1 files changed, 111 insertions, 105 deletions
diff --git a/intern/cycles/util/util_task.h b/intern/cycles/util/util_task.h index a7e19d1ab75..fd30a33d8ef 100644 --- a/intern/cycles/util/util_task.h +++ b/intern/cycles/util/util_task.h @@ -48,15 +48,18 @@ typedef function<void(int thread_id)> TaskRunFunction; * * Base class for tasks to be executed in threads. */ -class Task -{ -public: - Task() {}; - explicit Task(const TaskRunFunction& run_) : run(run_) {} - - virtual ~Task() {} - - TaskRunFunction run; +class Task { + public: + Task(){}; + explicit Task(const TaskRunFunction &run_) : run(run_) + { + } + + virtual ~Task() + { + } + + TaskRunFunction run; }; /* Task Pool @@ -68,54 +71,53 @@ public: * The run callback that actually executes the task may be created like this: * function_bind(&MyClass::task_execute, this, _1, _2) */ -class TaskPool -{ -public: - struct Summary { - /* Time spent to handle all tasks. */ - double time_total; +class TaskPool { + public: + struct Summary { + /* Time spent to handle all tasks. */ + double time_total; - /* Number of all tasks handled by this pool. */ - int num_tasks_handled; + /* Number of all tasks handled by this pool. */ + int num_tasks_handled; - /* A full multiline description of the state of the pool after - * all work is done. - */ - string full_report() const; - }; + /* A full multiline description of the state of the pool after + * all work is done. + */ + string full_report() const; + }; - TaskPool(); - ~TaskPool(); + TaskPool(); + ~TaskPool(); - void push(Task *task, bool front = false); - void push(const TaskRunFunction& run, bool front = false); + void push(Task *task, bool front = false); + void push(const TaskRunFunction &run, bool front = false); - void wait_work(Summary *stats = NULL); /* work and wait until all tasks are done */ - void cancel(); /* cancel all tasks, keep worker threads running */ - void stop(); /* stop all worker threads */ - bool finished(); /* check if all work has been completed */ + void wait_work(Summary *stats = NULL); /* work and wait until all tasks are done */ + void cancel(); /* cancel all tasks, keep worker threads running */ + void stop(); /* stop all worker threads */ + bool finished(); /* check if all work has been completed */ - bool canceled(); /* for worker threads, test if canceled */ + bool canceled(); /* for worker threads, test if canceled */ -protected: - friend class TaskScheduler; + protected: + friend class TaskScheduler; - void num_decrease(int done); - void num_increase(); + void num_decrease(int done); + void num_increase(); - thread_mutex num_mutex; - thread_condition_variable num_cond; + thread_mutex num_mutex; + thread_condition_variable num_cond; - int num; - bool do_cancel; + int num; + bool do_cancel; - /* ** Statistics ** */ + /* ** Statistics ** */ - /* Time time stamp of first task pushed. */ - double start_time; + /* Time time stamp of first task pushed. */ + double start_time; - /* Number of all tasks handled by this pool. */ - int num_tasks_handled; + /* Number of all tasks handled by this pool. */ + int num_tasks_handled; }; /* Task Scheduler @@ -123,41 +125,46 @@ protected: * Central scheduler that holds running threads ready to execute tasks. A singe * queue holds the task from all pools. */ -class TaskScheduler -{ -public: - static void init(int num_threads = 0); - static void exit(); - static void free_memory(); - - /* number of threads that can work on task */ - static int num_threads() { return threads.size(); } - - /* test if any session is using the scheduler */ - static bool active() { return users != 0; } - -protected: - friend class TaskPool; - - struct Entry { - Task *task; - TaskPool *pool; - }; - - static thread_mutex mutex; - static int users; - static vector<thread*> threads; - static bool do_exit; - - static list<Entry> queue; - static thread_mutex queue_mutex; - static thread_condition_variable queue_cond; - - static void thread_run(int thread_id); - static bool thread_wait_pop(Entry& entry); - - static void push(Entry& entry, bool front); - static void clear(TaskPool *pool); +class TaskScheduler { + public: + static void init(int num_threads = 0); + static void exit(); + static void free_memory(); + + /* number of threads that can work on task */ + static int num_threads() + { + return threads.size(); + } + + /* test if any session is using the scheduler */ + static bool active() + { + return users != 0; + } + + protected: + friend class TaskPool; + + struct Entry { + Task *task; + TaskPool *pool; + }; + + static thread_mutex mutex; + static int users; + static vector<thread *> threads; + static bool do_exit; + + static list<Entry> queue; + static thread_mutex queue_mutex; + static thread_condition_variable queue_cond; + + static void thread_run(int thread_id); + static bool thread_wait_pop(Entry &entry); + + static void push(Entry &entry, bool front); + static void clear(TaskPool *pool); }; /* Dedicated Task Pool @@ -167,42 +174,41 @@ protected: * The run callback that actually executes the task may be created like this: * function_bind(&MyClass::task_execute, this, _1, _2) */ -class DedicatedTaskPool -{ -public: - DedicatedTaskPool(); - ~DedicatedTaskPool(); +class DedicatedTaskPool { + public: + DedicatedTaskPool(); + ~DedicatedTaskPool(); - void push(Task *task, bool front = false); - void push(const TaskRunFunction& run, bool front = false); + void push(Task *task, bool front = false); + void push(const TaskRunFunction &run, bool front = false); - void wait(); /* wait until all tasks are done */ - void cancel(); /* cancel all tasks, keep worker thread running */ - void stop(); /* stop worker thread */ + void wait(); /* wait until all tasks are done */ + void cancel(); /* cancel all tasks, keep worker thread running */ + void stop(); /* stop worker thread */ - bool canceled(); /* for worker thread, test if canceled */ + bool canceled(); /* for worker thread, test if canceled */ -protected: - void num_decrease(int done); - void num_increase(); + protected: + void num_decrease(int done); + void num_increase(); - void thread_run(); - bool thread_wait_pop(Task*& entry); + void thread_run(); + bool thread_wait_pop(Task *&entry); - void clear(); + void clear(); - thread_mutex num_mutex; - thread_condition_variable num_cond; + thread_mutex num_mutex; + thread_condition_variable num_cond; - list<Task*> queue; - thread_mutex queue_mutex; - thread_condition_variable queue_cond; + list<Task *> queue; + thread_mutex queue_mutex; + thread_condition_variable queue_cond; - int num; - bool do_cancel; - bool do_exit; + int num; + bool do_cancel; + bool do_exit; - thread *worker_thread; + thread *worker_thread; }; CCL_NAMESPACE_END |