OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 WTF_MAKE_FAST_ALLOCATED; | 42 WTF_MAKE_FAST_ALLOCATED; |
43 public: | 43 public: |
44 ExecutionContextTask() { } | 44 ExecutionContextTask() { } |
45 virtual ~ExecutionContextTask() { } | 45 virtual ~ExecutionContextTask() { } |
46 virtual void performTask(ExecutionContext*) = 0; | 46 virtual void performTask(ExecutionContext*) = 0; |
47 // Certain tasks get marked specially so that they aren't discarded, and are
executed, when the context is shutting down its message queue. | 47 // Certain tasks get marked specially so that they aren't discarded, and are
executed, when the context is shutting down its message queue. |
48 virtual bool isCleanupTask() const { return false; } | 48 virtual bool isCleanupTask() const { return false; } |
49 virtual String taskNameForInstrumentation() const { return String(); } | 49 virtual String taskNameForInstrumentation() const { return String(); } |
50 }; | 50 }; |
51 | 51 |
52 class CallClosureTask FINAL : public ExecutionContextTask { | 52 class CallClosureTask final : public ExecutionContextTask { |
53 public: | 53 public: |
54 // Do not use |create| other than in createCrossThreadTask and | 54 // Do not use |create| other than in createCrossThreadTask and |
55 // createSameThreadTask. | 55 // createSameThreadTask. |
56 // See http://crbug.com/390851 | 56 // See http://crbug.com/390851 |
57 static PassOwnPtr<CallClosureTask> create(const Closure& closure) | 57 static PassOwnPtr<CallClosureTask> create(const Closure& closure) |
58 { | 58 { |
59 return adoptPtr(new CallClosureTask(closure)); | 59 return adoptPtr(new CallClosureTask(closure)); |
60 } | 60 } |
61 virtual void performTask(ExecutionContext*) OVERRIDE { m_closure(); } | 61 virtual void performTask(ExecutionContext*) override { m_closure(); } |
62 | 62 |
63 private: | 63 private: |
64 explicit CallClosureTask(const Closure& closure) : m_closure(closure) { } | 64 explicit CallClosureTask(const Closure& closure) : m_closure(closure) { } |
65 Closure m_closure; | 65 Closure m_closure; |
66 }; | 66 }; |
67 | 67 |
68 // Create tasks passed within a single thread. | 68 // Create tasks passed within a single thread. |
69 // When posting tasks within a thread, use |createSameThreadTask| instead | 69 // When posting tasks within a thread, use |createSameThreadTask| instead |
70 // of using |bind| directly to state explicitly that there is no need to care | 70 // of using |bind| directly to state explicitly that there is no need to care |
71 // about thread safety when posting the task. | 71 // about thread safety when posting the task. |
72 // When posting tasks across threads, use |createCrossThreadTask|. | 72 // When posting tasks across threads, use |createCrossThreadTask|. |
73 template<typename FunctionType, typename... P> | 73 template<typename FunctionType, typename... P> |
74 PassOwnPtr<ExecutionContextTask> createSameThreadTask( | 74 PassOwnPtr<ExecutionContextTask> createSameThreadTask( |
75 FunctionType function, const P&... parameters) | 75 FunctionType function, const P&... parameters) |
76 { | 76 { |
77 return CallClosureTask::create(bind(function, parameters...)); | 77 return CallClosureTask::create(bind(function, parameters...)); |
78 } | 78 } |
79 | 79 |
80 } // namespace | 80 } // namespace |
81 | 81 |
82 #endif | 82 #endif |
OLD | NEW |