2013-04-13 15:05:13 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef ATOM_COMMON_NODE_BINDINGS_MAC_
|
|
|
|
#define ATOM_COMMON_NODE_BINDINGS_MAC_
|
|
|
|
|
|
|
|
#include "base/compiler_specific.h"
|
|
|
|
#include "common/node_bindings.h"
|
|
|
|
#include "vendor/node/deps/uv/include/uv.h"
|
|
|
|
|
2013-07-22 05:02:02 +00:00
|
|
|
namespace base {
|
|
|
|
class MessageLoop;
|
|
|
|
}
|
|
|
|
|
2013-04-13 15:05:13 +00:00
|
|
|
namespace atom {
|
|
|
|
|
|
|
|
class NodeBindingsMac : public NodeBindings {
|
|
|
|
public:
|
|
|
|
explicit NodeBindingsMac(bool is_browser);
|
|
|
|
virtual ~NodeBindingsMac();
|
|
|
|
|
|
|
|
virtual void PrepareMessageLoop() OVERRIDE;
|
|
|
|
virtual void RunMessageLoop() OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Run the libuv loop for once.
|
|
|
|
void UvRunOnce();
|
|
|
|
|
2013-07-22 05:02:02 +00:00
|
|
|
// Make the main thread run libuv loop.
|
|
|
|
void WakeupMainThread();
|
|
|
|
|
2013-04-13 15:05:13 +00:00
|
|
|
// Thread to poll uv events.
|
|
|
|
static void EmbedThreadRunner(void *arg);
|
|
|
|
|
|
|
|
// Called when uv's watcher queue changes.
|
|
|
|
static void OnWatcherQueueChanged(uv_loop_t* loop);
|
|
|
|
|
2013-07-22 05:02:02 +00:00
|
|
|
// Main thread's MessageLoop.
|
|
|
|
base::MessageLoop* message_loop_;
|
|
|
|
|
|
|
|
// Main thread's libuv loop.
|
|
|
|
uv_loop_t* uv_loop_;
|
2013-04-13 15:05:13 +00:00
|
|
|
|
2013-04-19 13:21:04 +00:00
|
|
|
// Kqueue to poll for uv's backend fd.
|
|
|
|
int kqueue_;
|
|
|
|
|
2013-04-13 15:05:13 +00:00
|
|
|
// Dummy handle to make uv's loop not quit.
|
|
|
|
uv_async_t dummy_uv_handle_;
|
|
|
|
|
|
|
|
// Thread for polling events.
|
|
|
|
uv_thread_t embed_thread_;
|
|
|
|
|
|
|
|
// Whether we're done.
|
|
|
|
bool embed_closed_;
|
|
|
|
|
|
|
|
// Semaphore to wait for main loop in the embed thread.
|
|
|
|
uv_sem_t embed_sem_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(NodeBindingsMac);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace atom
|
|
|
|
|
|
|
|
#endif // ATOM_COMMON_NODE_BINDINGS_MAC_
|