-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from atom/master
Update from original
- Loading branch information
Showing
179 changed files
with
5,035 additions
and
2,979 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) 2015 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "atom/app/uv_task_runner.h" | ||
|
||
#include "base/stl_util.h" | ||
|
||
namespace atom { | ||
|
||
UvTaskRunner::UvTaskRunner(uv_loop_t* loop) : loop_(loop) { | ||
} | ||
|
||
UvTaskRunner::~UvTaskRunner() { | ||
for (auto& iter : tasks_) { | ||
uv_unref(reinterpret_cast<uv_handle_t*>(iter.first)); | ||
delete iter.first; | ||
} | ||
} | ||
|
||
bool UvTaskRunner::PostDelayedTask(const tracked_objects::Location& from_here, | ||
const base::Closure& task, | ||
base::TimeDelta delay) { | ||
uv_timer_t* timer = new uv_timer_t; | ||
timer->data = this; | ||
uv_timer_init(loop_, timer); | ||
uv_timer_start(timer, UvTaskRunner::OnTimeout, delay.InMilliseconds(), 0); | ||
tasks_[timer] = task; | ||
return true; | ||
} | ||
|
||
bool UvTaskRunner::RunsTasksOnCurrentThread() const { | ||
return true; | ||
} | ||
|
||
bool UvTaskRunner::PostNonNestableDelayedTask( | ||
const tracked_objects::Location& from_here, | ||
const base::Closure& task, | ||
base::TimeDelta delay) { | ||
return PostDelayedTask(from_here, task, delay);; | ||
} | ||
|
||
// static | ||
void UvTaskRunner::OnTimeout(uv_timer_t* timer) { | ||
UvTaskRunner* self = static_cast<UvTaskRunner*>(timer->data); | ||
if (!ContainsKey(self->tasks_, timer)) | ||
return; | ||
|
||
self->tasks_[timer].Run(); | ||
self->tasks_.erase(timer); | ||
uv_unref(reinterpret_cast<uv_handle_t*>(timer)); | ||
delete timer; | ||
} | ||
|
||
} // namespace atom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2015 GitHub, Inc. | ||
// Use of this source code is governed by the MIT license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ATOM_APP_UV_TASK_RUNNER_H_ | ||
#define ATOM_APP_UV_TASK_RUNNER_H_ | ||
|
||
#include <map> | ||
|
||
#include "base/callback.h" | ||
#include "base/single_thread_task_runner.h" | ||
#include "vendor/node/deps/uv/include/uv.h" | ||
|
||
namespace atom { | ||
|
||
// TaskRunner implementation that posts tasks into libuv's default loop. | ||
class UvTaskRunner : public base::SingleThreadTaskRunner { | ||
public: | ||
explicit UvTaskRunner(uv_loop_t* loop); | ||
~UvTaskRunner() override; | ||
|
||
// base::SingleThreadTaskRunner: | ||
bool PostDelayedTask(const tracked_objects::Location& from_here, | ||
const base::Closure& task, | ||
base::TimeDelta delay) override; | ||
bool RunsTasksOnCurrentThread() const override; | ||
bool PostNonNestableDelayedTask( | ||
const tracked_objects::Location& from_here, | ||
const base::Closure& task, | ||
base::TimeDelta delay) override; | ||
|
||
private: | ||
static void OnTimeout(uv_timer_t* timer); | ||
|
||
uv_loop_t* loop_; | ||
|
||
std::map<uv_timer_t*, base::Closure> tasks_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(UvTaskRunner); | ||
}; | ||
|
||
} // namespace atom | ||
|
||
#endif // ATOM_APP_UV_TASK_RUNNER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.