[rkward-cvs] SF.net SVN: rkward:[4443] trunk/rkward
tfry at users.sourceforge.net
tfry at users.sourceforge.net
Fri Nov 23 11:48:29 UTC 2012
Revision: 4443
http://rkward.svn.sourceforge.net/rkward/?rev=4443&view=rev
Author: tfry
Date: 2012-11-23 11:48:28 +0000 (Fri, 23 Nov 2012)
Log Message:
-----------
When there is nothing to do for a script backend, make it wait on a mutex, instead of burning CPU cycles
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
trunk/rkward/rkward/scriptbackends/qtscriptbackend.h
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2012-11-23 11:25:10 UTC (rev 4442)
+++ trunk/rkward/ChangeLog 2012-11-23 11:48:28 UTC (rev 4443)
@@ -1,3 +1,4 @@
+- Reduce CPU usage of pluings while idle
- Fix conversion from Numeric to Factor in the data editor
- In the data.frame editor, columns containing invalid values are now highlighted in red
- Fixed: If none of the previous plugin maps could be found on startup, re-add the default
Modified: trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp
===================================================================
--- trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp 2012-11-23 11:25:10 UTC (rev 4442)
+++ trunk/rkward/rkward/scriptbackends/qtscriptbackend.cpp 2012-11-23 11:48:28 UTC (rev 4443)
@@ -2,7 +2,7 @@
qtscriptbackend - description
-------------------
begin : Mon Sep 28 2009
- copyright : (C) 2009, 2010 by Thomas Friedrichsmeier
+ copyright : (C) 2009, 2010, 2012 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -86,15 +86,21 @@
if (command_stack.first ()->complete) {
delete command_stack.takeFirst ();
- if (!command_stack.count ()) return;
+ if (command_stack.isEmpty ()) {
+ script_thread->goToSleep (true);
+ return;
+ }
}
RK_DO (qDebug ("submitting QtScript code: %s", command_stack.first ()->command.toLatin1 ().data ()), PHP, DL_DEBUG);
+ if (script_thread) script_thread->goToSleep (false);
script_thread->setCommand (command_stack.first ()->command);
busy = true;
command_stack.first ()->complete = true;
current_flags = command_stack.first ()->flags;
current_type = command_stack.first ()->type;
+ } else {
+ if (script_thread && command_stack.isEmpty ()) script_thread->goToSleep (true);
}
}
@@ -140,12 +146,26 @@
_commonfile = commonfile;
_scriptfile = scriptfile;
killed = false;
+ sleeping = false;
}
QtScriptBackendThread::~QtScriptBackendThread () {
RK_TRACE (PHP);
}
+void QtScriptBackendThread::goToSleep (bool sleep) {
+ RK_TRACE (PHP);
+ if (sleeping != sleep) {
+ if (sleep) {
+ sleep_mutex.lock (); // hold a mutex until it's time to wake up, again. Thread will then wait on this mutex.
+ sleeping = true;
+ } else {
+ sleeping = false;
+ sleep_mutex.unlock ();
+ }
+ }
+}
+
void QtScriptBackendThread::setCommand (const QString &command) {
RK_TRACE (PHP);
@@ -243,6 +263,10 @@
QString command;
while (1) {
if (killed) return;
+ if (sleeping) {
+ sleep_mutex.lock ();
+ sleep_mutex.unlock ();
+ }
mutex.lock ();
if (!_command.isNull ()) {
Modified: trunk/rkward/rkward/scriptbackends/qtscriptbackend.h
===================================================================
--- trunk/rkward/rkward/scriptbackends/qtscriptbackend.h 2012-11-23 11:25:10 UTC (rev 4442)
+++ trunk/rkward/rkward/scriptbackends/qtscriptbackend.h 2012-11-23 11:48:28 UTC (rev 4443)
@@ -2,7 +2,7 @@
qtscriptbackend - description
-------------------
begin : Mon Sep 28 2009
- copyright : (C) 2009 by Thomas Friedrichsmeier
+ copyright : (C) 2009, 2012 by Thomas Friedrichsmeier
email : tfry at users.sourceforge.net
***************************************************************************/
@@ -68,6 +68,7 @@
void setCommand (const QString &command);
void setData (const QString &data);
void kill () { killed = true; };
+ void goToSleep (bool sleep);
signals:
void commandDone (const QString &result);
void needData (const QString &identifier);
@@ -91,6 +92,9 @@
bool killed;
QMutex mutex;
+
+ QMutex sleep_mutex;
+ bool sleeping;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the rkward-tracker
mailing list