Mercurial > hg > octave-avbm
changeset 13478:a51ad78b51c5
Fetching variables was not threadsafe, now it is.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Thu, 21 Apr 2011 12:30:30 +0200 |
parents | ca767e4055c5 |
children | 37d12b4531c5 |
files | gui//src/MainWindow.h gui//src/OctaveLink.cpp gui//src/OctaveLink.h |
diffstat | 3 files changed, 37 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/gui//src/MainWindow.h +++ b/gui//src/MainWindow.h @@ -162,7 +162,7 @@ while(m_mainWindow->isRunning()) { // Get a full variable list. - QList<SymbolRecord> symbolTable = OctaveLink::instance()->workspace(); + QList<SymbolRecord> symbolTable = OctaveLink::instance()->currentSymbolTable(); if(symbolTable.size()) { m_mainWindow->variablesDockWidget()->setVariablesList(symbolTable); }
--- a/gui//src/OctaveLink.cpp +++ b/gui//src/OctaveLink.cpp @@ -83,22 +83,34 @@ //************************************************************************* OctaveLink::OctaveLink() - : m_previousHistoryLength(0) { + : QObject(), + m_previousHistoryLength(0) { + m_symbolTableSemaphore = new QSemaphore(1); } OctaveLink::~OctaveLink() { } -/******************************************************************************* - ******************************************************************************* - * CLIENT SIDE FUNCTIONS - ******************************************************************************* - *******************************************************************************/ +void OctaveLink::fetchSymbolTable() { + m_symbolTableSemaphore->acquire(); + m_symbolTableBuffer.clear(); + std::list<SymbolRecord> allVariables = symbol_table::all_variables(); + std::list<SymbolRecord>::iterator iterator; + for(iterator = allVariables.begin(); iterator != allVariables.end(); iterator++) + m_symbolTableBuffer.append(*iterator); + m_symbolTableSemaphore->release(); +} -//************************************************************************* -QList<SymbolRecord> OctaveLink::workspace() { - QMutexLocker mutexLocker(&m_internalAccessMutex); - return m_variableSymbolTableList; +QList<SymbolRecord> OctaveLink::currentSymbolTable() { + QList<SymbolRecord> m_symbolTableCopy; + + // Generate a deep copy of the current symbol table. + m_symbolTableSemaphore->acquire(); + foreach(SymbolRecord symbolRecord, m_symbolTableBuffer) + m_symbolTableCopy.append(symbolRecord); + m_symbolTableSemaphore->release(); + + return m_symbolTableCopy; } @@ -193,24 +205,16 @@ //************************************************************************* int OctaveLink::processOctaveServerData(void) { QMutexLocker mutexLocker(&m_internalAccessMutex); - process_breakpoint_action(); processBreakpointAndRemoveModify(); processRequestedVariables(); - retrieveVariables(); + fetchSymbolTable(); setHistoryList(); setBreakPointList(); return 0; } -//************************************************************************* -void OctaveLink::retrieveVariables() { - m_variableSymbolTableList.clear(); - std::list<SymbolRecord> allVariables = symbol_table::all_variables(); - std::list<SymbolRecord>::iterator iterator; - for(iterator = allVariables.begin(); iterator != allVariables.end(); iterator++) - m_variableSymbolTableList.append(*iterator); -} + //*************************************************************************
--- a/gui//src/OctaveLink.h +++ b/gui//src/OctaveLink.h @@ -72,6 +72,8 @@ #include <QList> #include <QString> #include <QVector> +#include <QSemaphore> +#include <QObject> typedef symbol_table::symbol_record SymbolRecord; typedef octave_value OctaveValue; @@ -80,8 +82,9 @@ * \class OctaveLink * Manages a link to an octave instance. */ -class OctaveLink +class OctaveLink : QObject { + Q_OBJECT public: static OctaveLink *instance() { return &m_singleton; } static int readlineEventHook(void); @@ -150,8 +153,7 @@ /** TODO: Describe. */ int setBreakpointAction(BreakPointAction action); - /** Variable related methods. */ - QList<SymbolRecord> workspace(void); + QList<SymbolRecord> currentSymbolTable(); /** TODO: Describe. */ QList<RequestedVariable> requestedVariables(void); @@ -183,7 +185,7 @@ * process_breakpoint_add_remove_modify * set_current_breakpoint * set_breakpoint_list - * ... + * ...http://oregano.gforge.lug.fi.uba.ar/ * Release lock */ int processOctaveServerData(void); @@ -204,7 +206,7 @@ /** Variable related methods. */ /** Retrieves all variables from Octave. */ - void retrieveVariables(void); + void fetchSymbolTable(void); /** TODO: Describe. */ int processRequestedVariables(void); @@ -213,6 +215,9 @@ /** TODO: Describe. */ int setHistoryList(void); +signals: + void symbolTableChanged(); + private: OctaveLink(); ~OctaveLink(); @@ -229,7 +234,8 @@ BreakPointAction m_breakPointAction; /** Variable related member variables. */ - QList<SymbolRecord> m_variableSymbolTableList; + QSemaphore *m_symbolTableSemaphore; + QList<SymbolRecord> m_symbolTableBuffer; QList<QString> m_variablesRequestList; // NOTE: Create an overloaded operator<< for octave_value to do the