improved thread/exception-safety for window creation and show function - 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>2011年01月03日 14:30:43 +0100
committerfrancesco <francesco.bbt@gmail.com>2011年01月03日 20:56:08 +0100
commit1d0382f13c23443d26a330fcb89742a7befe0450 (patch)
tree6733bb5bb062875205cde819ff14d291923e694a /agg-plot/canvas-window.cpp
parent7f73acc24c47f7e0ef6f367db12a184a23e5faa2 (diff)
downloadgsl-shell-1d0382f13c23443d26a330fcb89742a7befe0450.tar.gz
improved thread/exception-safety for window creation and show function
Signed-off-by: francesco-ST <francesco.abbate@st.com>
Diffstat (limited to 'agg-plot/canvas-window.cpp')
-rw-r--r--agg-plot/canvas-window.cpp 48
1 files changed, 16 insertions, 32 deletions
diff --git a/agg-plot/canvas-window.cpp b/agg-plot/canvas-window.cpp
index 911d504b..f5a1bdaf 100644
--- a/agg-plot/canvas-window.cpp
+++ b/agg-plot/canvas-window.cpp
@@ -18,13 +18,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include <memory>
-
-extern "C" {
-#include "lua.h"
-#include "lauxlib.h"
-}
-
#include "defs.h"
#include "canvas-window-cpp.h"
#include "resource-manager.h"
@@ -45,13 +38,6 @@ 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)
{
@@ -70,13 +56,10 @@ canvas_window::on_init()
this->on_resize(width(), height());
}
-void
-canvas_window::start_new_thread (lua_State *L)
+bool canvas_window::start_new_thread (std::auto_ptr<canvas_window::thread_info>& inf)
{
if (status != not_ready && status != closed)
- return;
-
- this->id = object_index_add (L, -1);
+ return false;
pthread_attr_t attr[1];
pthread_t win_thread[1];
@@ -84,29 +67,30 @@ canvas_window::start_new_thread (lua_State *L)
pthread_attr_init (attr);
pthread_attr_setdetachstate (attr, PTHREAD_CREATE_DETACHED);
- this->lock();
-
this->status = canvas_window::starting;
- canvas_thread_info *inf = new canvas_thread_info(L, this);
- if (pthread_create(win_thread, attr, canvas_thread_function, (void*) inf))
+ void *user_data = (void *) inf.get();
+ if (pthread_create(win_thread, attr, canvas_thread_function, user_data))
{
- delete inf;
- object_index_remove (L, this->id);
- pthread_attr_destroy (attr);
-
this->status = canvas_window::error;
-
- luaL_error(L, "error creating thread");
+ pthread_attr_destroy (attr);
+ return false;
+ }
+ else
+ {
+ inf.release();
+ pthread_attr_destroy (attr);
}
- pthread_attr_destroy (attr);
+ return true;
}
void *
canvas_thread_function (void *_inf)
{
- std::auto_ptr<canvas_thread_info> inf((canvas_thread_info *) _inf);
+ typedef canvas_window::thread_info thread_info;
+
+ std::auto_ptr<thread_info> inf((thread_info *) _inf);
platform_support_ext::prepare();
canvas_window *win = inf->win;
@@ -125,7 +109,7 @@ canvas_thread_function (void *_inf)
win->unlock();
GSL_SHELL_LOCK();
- object_index_remove (inf->L, win->id);
+ object_index_remove (inf->L, inf->window_id);
GSL_SHELL_UNLOCK();
return NULL;
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月15日 23:07:57 +0000

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