Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable coroutine support on every platform #68

Merged
merged 2 commits into from
May 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ else()
set(NANOGUI_LIBRARY_TYPE "STATIC")
endif()

if (APPLE)
if (APPLE OR CMAKE_SYSTEM MATCHES "Linux")
# Include coroutine support for running the mainloop in detached mode
add_definitions(-DCORO_SJLJ)
include_directories(ext/coro)
Expand Down
16 changes: 9 additions & 7 deletions python/python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include <nanogui/nanogui.h>
#include <nanogui/opengl.h>
#include <thread>
#include <mutex>
#include <condition_variable>
#include "python.h"

#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__linux__)
#include <coro.h>
#endif

Expand Down Expand Up @@ -48,7 +50,7 @@ DECLARE_WIDGET(ColorPicker);
/// Make pybind aware of the ref-counted wrapper type
PYBIND11_DECLARE_HOLDER_TYPE(T, ref<T>);

#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__linux__)
namespace {
class semaphore {
public:
Expand Down Expand Up @@ -85,7 +87,7 @@ class MainloopHandle {
int refresh = 0;
std::thread thread;

#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__linux__)
coro_context ctx_helper, ctx_main, ctx_thread;
coro_stack stack;
semaphore sema;
Expand All @@ -100,7 +102,7 @@ class MainloopHandle {
if (!detached)
return;

#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__linux__)
/* Release GIL and disassociate from thread state (which was originally
associated with the main Python thread) */
py::gil_scoped_release thread_state(true);
Expand All @@ -118,7 +120,7 @@ class MainloopHandle {
thread.join();
detached = false;

#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__linux__)
/* Reacquire GIL and reassociate with thread state
[via RAII destructor in 'thread_state'] */
#endif
Expand All @@ -142,7 +144,7 @@ PYBIND11_PLUGIN(nanogui) {
handle->detached = true;
handle->refresh = refresh;

#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__linux__)
/* Release GIL and completely disassociate the calling thread
from its associated Python thread state data structure */
py::gil_scoped_release thread_state(true);
Expand Down Expand Up @@ -194,7 +196,7 @@ PYBIND11_PLUGIN(nanogui) {
});
#endif

#if defined(__APPLE__)
#if defined(__APPLE__) || defined(__linux__)
/* Reacquire GIL and reassociate with thread state on newly
created thread [via RAII destructor in 'thread_state'] */
#endif
Expand Down