gsl-shell.git - gsl-shell

index : gsl-shell.git
gsl-shell
summary refs log tree commit diff
path: root/agg-plot/canvas-window.cpp
diff options
context:
space:
mode:
authorfrancesco-ST <francesco.abbate@st.com>2010年12月28日 16:52:42 +0100
committerfrancesco-ST <francesco.abbate@st.com>2010年12月28日 16:52:42 +0100
commitab7fc91161b8cb493b418bfdd2871e45c4537a26 (patch)
treeea400f746489d587d153f0b6b6677c6a17bf916f /agg-plot/canvas-window.cpp
parent978986bb98f1ae622be3f430f4e729fbb598afb8 (diff)
downloadgsl-shell-ab7fc91161b8cb493b418bfdd2871e45c4537a26.tar.gz
changed window closing unref main lock strategy
A global lock is used now to guard the main loop. The plot windows directly unrefs the window by just waiting the main lock. Simplified also the window index code since plot are not indexed since many versions now. The windows are not explicitely closed when the main loop terminates.
Diffstat (limited to 'agg-plot/canvas-window.cpp')
-rw-r--r--agg-plot/canvas-window.cpp 33
1 files changed, 22 insertions, 11 deletions
diff --git a/agg-plot/canvas-window.cpp b/agg-plot/canvas-window.cpp
index e5b87376..911d504b 100644
--- a/agg-plot/canvas-window.cpp
+++ b/agg-plot/canvas-window.cpp
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include <memory>
+
extern "C" {
#include "lua.h"
#include "lauxlib.h"
@@ -43,6 +45,13 @@ static void * canvas_thread_function (void *_win);
__END_DECLS
+struct canvas_thread_info {
+ lua_State *L;
+ canvas_window *win;
+
+ canvas_thread_info (lua_State *L, canvas_window *win) : L(L), win(win) {};
+};
+
void
canvas_window::on_resize(int sx, int sy)
{
@@ -67,7 +76,7 @@ canvas_window::start_new_thread (lua_State *L)
if (status != not_ready && status != closed)
return;
- this->id = object_index_add (L, OBJECT_WINDOW, -1);
+ this->id = object_index_add (L, -1);
pthread_attr_t attr[1];
pthread_t win_thread[1];
@@ -79,11 +88,13 @@ canvas_window::start_new_thread (lua_State *L)
this->status = canvas_window::starting;
- if (pthread_create(win_thread, attr, canvas_thread_function, (void*) this))
+ canvas_thread_info *inf = new canvas_thread_info(L, this);
+ if (pthread_create(win_thread, attr, canvas_thread_function, (void*) inf))
{
- object_index_remove (L, OBJECT_WINDOW, this->id);
-
+ delete inf;
+ object_index_remove (L, this->id);
pthread_attr_destroy (attr);
+
this->status = canvas_window::error;
luaL_error(L, "error creating thread");
@@ -93,11 +104,11 @@ canvas_window::start_new_thread (lua_State *L)
}
void *
-canvas_thread_function (void *_win)
+canvas_thread_function (void *_inf)
{
+ std::auto_ptr<canvas_thread_info> inf((canvas_thread_info *) _inf);
platform_support_ext::prepare();
-
- canvas_window *win = (canvas_window *) _win;
+ canvas_window *win = inf->win;
win->caption("GSL shell plot");
if (win->init(480, 480, agg::window_resize))
@@ -110,12 +121,12 @@ canvas_thread_function (void *_win)
{
win->status = canvas_window::error;
}
-
- GSL_SHELL_LOCK();
- gsl_shell_unref_plot (win->id);
- GSL_SHELL_UNLOCK();
win->unlock();
+ GSL_SHELL_LOCK();
+ object_index_remove (inf->L, win->id);
+ GSL_SHELL_UNLOCK();
+
return NULL;
}
generated by cgit v1.2.3 (git 2.25.1) at 2025年09月17日 12:25:44 +0000

AltStyle によって変換されたページ (->オリジナル) /