author | Francesco Abbate <francesco.bbt@gmail.com> | 2012年03月29日 17:23:35 +0200 |
---|---|---|
committer | Francesco Abbate <francesco.bbt@gmail.com> | 2012年04月01日 22:57:19 +0200 |
commit | 5c80bf0af85627c0e62d0f097e9ed6679f6bed73 (patch) | |
tree | 53c88940049bef966c8994cf59f831c26061a8c2 /agg-plot | |
parent | e255825367665691584ae44755df5f2882a25c66 (diff) | |
download | gsl-shell-5c80bf0af85627c0e62d0f097e9ed6679f6bed73.tar.gz |
-rw-r--r-- | agg-plot/canvas-window-cpp.h | 8 | ||||
-rw-r--r-- | agg-plot/canvas-window.cpp | 20 | ||||
-rw-r--r-- | agg-plot/lua-graph.cpp | 18 | ||||
-rw-r--r-- | agg-plot/strpp.h | 48 | ||||
-rw-r--r-- | agg-plot/window-cpp.h | 3 | ||||
-rw-r--r-- | agg-plot/window.cpp | 9 |
diff --git a/agg-plot/canvas-window-cpp.h b/agg-plot/canvas-window-cpp.h index 36696c2e..bad27eba 100644 --- a/agg-plot/canvas-window-cpp.h +++ b/agg-plot/canvas-window-cpp.h @@ -16,6 +16,7 @@ extern "C" { #include "defs.h" #include "canvas.h" #include "utils.h" +#include "lua-gsl.h" class canvas_window : public platform_support_ext { protected: @@ -25,6 +26,7 @@ protected: agg::trans_affine m_matrix; pthread_t m_thread; + gsl_shell_state* m_gsl_shell; public: @@ -40,9 +42,10 @@ public: enum win_status_e status; - canvas_window(agg::rgba& bgcol) : + canvas_window(gsl_shell_state* gs, agg::rgba& bgcol) : platform_support_ext(agg::pix_format_bgr24, true), - m_canvas(NULL), m_bgcolor(bgcol), m_matrix(), status(not_ready) + m_canvas(NULL), m_bgcolor(bgcol), m_matrix(), m_gsl_shell(gs), + status(not_ready) { }; virtual ~canvas_window() @@ -55,6 +58,7 @@ public: virtual void on_resize(int sx, int sy); void shutdown_close(); + gsl_shell_state* state() { return m_gsl_shell; } bool start_new_thread (std::auto_ptr<thread_info>& inf); diff --git a/agg-plot/canvas-window.cpp b/agg-plot/canvas-window.cpp index 8d1f1b75..bcec7ac7 100644 --- a/agg-plot/canvas-window.cpp +++ b/agg-plot/canvas-window.cpp @@ -105,14 +105,16 @@ canvas_thread_function (void *_inf) win->unlock(); - pthread_mutex_lock (gsl_shell_shutdown_mutex); - if (!gsl_shell_shutting_down) + gsl_shell_state* gs = win->state(); + + pthread_mutex_lock (&gs->shutdown_mutex); + if (!gs->is_shutting_down) { - GSL_SHELL_LOCK(); - window_index_remove (inf->L, inf->window_id); - GSL_SHELL_UNLOCK(); + pthread_mutex_lock(&gs->exec_mutex); + window_index_remove (gs->L, inf->window_id); + pthread_mutex_unlock(&gs->exec_mutex); } - pthread_mutex_unlock (gsl_shell_shutdown_mutex); + pthread_mutex_unlock (&gs->shutdown_mutex); return NULL; } @@ -125,9 +127,11 @@ canvas_window::shutdown_close() { close_request(); unlock(); - pthread_mutex_unlock (gsl_shell_shutdown_mutex); + + gsl_shell_state* gs = this->m_gsl_shell; + pthread_mutex_unlock (&gs->shutdown_mutex); pthread_join(m_thread, NULL); - pthread_mutex_lock (gsl_shell_shutdown_mutex); + pthread_mutex_lock (&gs->shutdown_mutex); } else { diff --git a/agg-plot/lua-graph.cpp b/agg-plot/lua-graph.cpp index 6c3c7bc9..32174bde 100644 --- a/agg-plot/lua-graph.cpp +++ b/agg-plot/lua-graph.cpp @@ -59,13 +59,15 @@ register_graph (lua_State *L) } void -lua_close_with_graph (lua_State* L) +gsl_shell_close_with_graph (struct gsl_shell_state* gs) { - pthread_mutex_lock (gsl_shell_shutdown_mutex); - gsl_shell_shutting_down = 1; - GSL_SHELL_LOCK(); - graph_close_windows(L); - lua_close(L); - pthread_mutex_unlock (gsl_shell_shutdown_mutex); - GSL_SHELL_UNLOCK(); + pthread_mutex_lock (&gs->shutdown_mutex); + gs->is_shutting_down = 1; + pthread_mutex_lock(&gs->exec_mutex); + graph_close_windows(gs->L); + lua_close(gs->L); + pthread_mutex_unlock(&gs->shutdown_mutex); + pthread_mutex_unlock(&gs->exec_mutex); + + gsl_shell_close(gs); } diff --git a/agg-plot/strpp.h b/agg-plot/strpp.h deleted file mode 100644 index f1fdfe80..00000000 --- a/agg-plot/strpp.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef STRPP_H -#define STRPP_H - -#include "str.h" - -class str : public _str { -public: - str(int sz = 64) { str_init(this, sz); } - str(const char *s) { str_init_from_c(this, s); } - str(const str& s) { str_init_from_str(this, &s); } - - ~str() { str_free(this); } - - const str& operator = (const str& s) { - str_copy(this, &s); - return *this; - } - - const char* cstr() const { return CSTR(this); } - - void append(const str& s, int sep = 0) { str_append(this, &s, sep); } - void append(const char* s, int sep = 0) { str_append_c(this, s, sep); } - - void printf(const char* fmt, ...) { - va_list ap; - va_start (ap, fmt); - str_vprintf (this, fmt, 0, ap); - va_end (ap); - } - - void printf_add(const char* fmt, ...) { - va_list ap; - va_start (ap, fmt); - str_vprintf (this, fmt, 1, ap); - va_end (ap); - } - - static str print(const char* fmt, ...) { - va_list ap; - va_start (ap, fmt); - str s; - str_vprintf (&s, fmt, 0, ap); - va_end (ap); - return s; - } -}; - -#endif diff --git a/agg-plot/window-cpp.h b/agg-plot/window-cpp.h index 02f72987..73025489 100644 --- a/agg-plot/window-cpp.h +++ b/agg-plot/window-cpp.h @@ -60,7 +60,8 @@ private: ref::node* m_tree; public: - window(agg::rgba& bgcol) : canvas_window(bgcol), m_tree(0) + window(gsl_shell_state* gs, agg::rgba bgcol= colors::white): + canvas_window(gs, bgcol), m_tree(0) { this->split("."); }; diff --git a/agg-plot/window.cpp b/agg-plot/window.cpp index 4a412b7b..f48a725c 100644 --- a/agg-plot/window.cpp +++ b/agg-plot/window.cpp @@ -423,7 +423,14 @@ void window::start (lua_State *L, gslshell::ret_status& st) int window_new (lua_State *L) { - window *win = push_new_object<window>(L, GS_WINDOW, colors::white); + lua_getfield(L, LUA_REGISTRYINDEX, "__gsl_shell"); + gsl_shell_state* gs = (gsl_shell_state*) lua_touserdata(L, -1); + lua_pop(L, 1); + + if (unlikely(gs == NULL)) + return luaL_error(L, "cannot create window: not a GSL Shell state"); + + window *win = push_new_object<window>(L, GS_WINDOW, gs); const char *spec = lua_tostring (L, 1); gslshell::ret_status st; |