Mailinglist Archive: yast-commit (687 mails)

< Previous Next >
[yast-commit] r43494 - in /trunk/core/libyui/src: YUI.h YUIComponent.cc YUI_core.cc
  • From: sh-sh-sh@xxxxxxxxxxxxxxxx
  • Date: Wed, 09 Jan 2008 13:46:09 -0000
  • Message-id: <20080109134609.F04D012E114@xxxxxxxxxxxxxxxx>
Author: sh-sh-sh
Date: Wed Jan 9 14:46:09 2008
New Revision: 43494

URL: http://svn.opensuse.org/viewcvs/yast?rev=43494&view=rev
Log:
proper thread shutdown

Modified:
trunk/core/libyui/src/YUI.h
trunk/core/libyui/src/YUIComponent.cc
trunk/core/libyui/src/YUI_core.cc

Modified: trunk/core/libyui/src/YUI.h
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YUI.h?rev=43494&r1=43493&r2=43494&view=diff
==============================================================================
--- trunk/core/libyui/src/YUI.h (original)
+++ trunk/core/libyui/src/YUI.h Wed Jan 9 14:46:09 2008
@@ -85,7 +85,7 @@
/**
* Constructor.
**/
- YUI( bool with_threads );
+ YUI( bool withThreads );

friend class Y2UIFunction;

@@ -97,6 +97,13 @@
virtual ~YUI();

/**
+ * Shut down multithreading. This needs to be called before the destructor
+ * if the UI was created with threads. If the UI was created without
+ * threads, this does nothing.
+ **/
+ void shutdownThreads();
+
+ /**
* Access the global UI.
**/
static YUI * ui();
@@ -254,7 +261,7 @@
/**
* Running with threads?
**/
- bool runningWithThreads() const { return with_threads; }
+ bool runningWithThreads() const { return _withThreads; }

/**
* Call a UI builtin function in the correct thread (the UI thread).
@@ -662,12 +669,12 @@
/**
* true if a seperate UI thread is created
**/
- bool with_threads;
+ bool _withThreads;

/**
* Handle to the ui thread.
**/
- pthread_t ui_thread;
+ pthread_t _uiThread;

/**
* Inter-thread communication between the YCP thread and the UI thread:

Modified: trunk/core/libyui/src/YUIComponent.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YUIComponent.cc?rev=43494&r1=43493&r2=43494&view=diff
==============================================================================
--- trunk/core/libyui/src/YUIComponent.cc (original)
+++ trunk/core/libyui/src/YUIComponent.cc Wed Jan 9 14:46:09 2008
@@ -52,14 +52,17 @@
}

y2debug ("Setting UI component to '%s'", name().c_str());
- _uiComponent = this;
+ _uiComponent = this;
}


YUIComponent::~YUIComponent()
{
if ( _ui )
+ {
+ _ui->shutdownThreads(); // cannot be called in the UI's destructor
delete _ui;
+ }
}


@@ -164,9 +167,11 @@
void YUIComponent::result( const YCPValue & /*result*/ )
{
if ( _ui )
+ {
+ _ui->shutdownThreads(); // cannot be called in the UI's destructor
delete _ui;
-
- _ui = 0;
+ _ui = 0;
+ }
}



Modified: trunk/core/libyui/src/YUI_core.cc
URL:
http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YUI_core.cc?rev=43494&r1=43493&r2=43494&view=diff
==============================================================================
--- trunk/core/libyui/src/YUI_core.cc (original)
+++ trunk/core/libyui/src/YUI_core.cc Wed Jan 9 14:46:09 2008
@@ -55,8 +55,9 @@
extern void *start_ui_thread( void * yui );


-YUI::YUI( bool with_threads )
- : with_threads( with_threads )
+YUI::YUI( bool withThreads )
+ : _withThreads( withThreads )
+ , _uiThread( 0 )
, _moduleName( "yast2" )
, _productName( "SUSE Linux" )
, macroRecorder (0)
@@ -70,13 +71,11 @@

YUI::~YUI()
{
- if ( with_threads )
+ if ( _withThreads && _uiThread )
{
- terminateUIThread();
- close( pipe_to_ui[0] );
- close( pipe_to_ui[1] );
- close( pipe_from_ui[0] );
- close( pipe_from_ui[1] );
+ y2error( "shutdownThreads() was never called!" );
+ y2error( "shutting down now - this might segfault" );
+ shutdownThreads();
}

if ( YDialog::openDialogsCount() > 0 )
@@ -156,7 +155,7 @@
// method. It must be called at the end of the constructor of the specific
// UI (the Qt UI or the NCurses UI).

- if ( with_threads )
+ if ( _withThreads )
{
if ( pipe( pipe_from_ui ) == 0 &&
pipe( pipe_to_ui ) == 0 )
@@ -168,7 +167,7 @@
if ( fcntl( pipe_to_ui[0], F_SETFL, arg | O_NONBLOCK ) < 0 )
{
y2error( "Couldn't set O_NONBLOCK: errno=%d: %m", errno );
- with_threads = false;
+ _withThreads = false;
close( pipe_to_ui[0] );
close( pipe_to_ui[1] );
close( pipe_from_ui[0] );
@@ -197,7 +196,7 @@
{
pthread_attr_t attr;
pthread_attr_init( & attr );
- pthread_create( & ui_thread, & attr, start_ui_thread, this );
+ pthread_create( & _uiThread, & attr, start_ui_thread, this );
}


@@ -208,11 +207,25 @@
signalUIThread();
y2debug( "Waiting for UI thread to shut down" );
waitForUIThread();
- pthread_join( ui_thread, 0 );
+ pthread_join( _uiThread, 0 );
y2debug( "UI thread shut down correctly" );
}


+void YUI::shutdownThreads()
+{
+ if ( _uiThread )
+ {
+ terminateUIThread();
+ _uiThread = 0;
+ close( pipe_to_ui[0] );
+ close( pipe_to_ui[1] );
+ close( pipe_from_ui[0] );
+ close( pipe_from_ui[1] );
+ }
+}
+
+
extern YCPValue UIUserInput ();
extern YCPValue UITimeoutUserInput( const YCPInteger& timeout );
extern YCPValue UIWaitForEvent();

--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages