Published using Google Docs
Library refactoring: prototype
Updated automatically every 5 minutes

Library refactoring: prototype

Nazar Gerasymchuk, nazar.gerasymchuk@gmail

All described below is linked to project https://github.com/troyane/lambdaConcurrent.

This project is billet for for handling asynchronous db access.

First of all, no one write-access queries can be applied at the same time. Somebody must wait (or be blocked).

ThreadDAO

Take a look at pushButton activity (but not btnSendQuery).

Please, mark, that there is class ThreadDAO, inherited from QThread. This thread is sleeping all the time except when it got some work.

This work will be send to ThreadDAO's callSync as parameter lambda. If it is more easy to understand, lambda is functor.

This callSync method will be executed in UI thread. Here we can lock-unlock UI, because we are executed in UI thread.

On other side of that call is lambda, which goes inside ThreadDAO and places for execution in its run cycle.

So, we got, that lambda will be executed in ThreadDAO's thread. While it is executing, we are waiting in callSync (but not just waiting as it is now in Mixxx). We do lock nothing -- we do qApp->processEvents( QEventLoop::AllEvents );

We accept all events and give green light to repainting all UI.

If we are waiting too long, we show progress indicator and lock UI (so, if query executes too quick -- there will be no blinking lock-unlock -- as it is done in libraryscannerdlg).

 

After executing lambda in ThreadDAO's thread,  in callSync function (UI thread) we can unlock UI (if it was locked).

In ThreadDAO we'll hold connection to DB, and I'm thinking on -- do we need to hold all DAO's here.

QProgressIndicator

You can find this widget at http://qt-apps.org/content/show.php/QProgressIndicator?content=115762.

This is nice and very easy widget that can be used to show progress indicator over QWidget.

That is just a thought.

C++0x

To use lambdas we must enable C++0x flag. Using lambdas can give us more reliable understanding of logic inside scope of function. By using other variants we fall into lots of overhead.

Since there is opened blueprint https://blueprints.launchpad.net/mixxx/+spec/qt5-c++11, think that it can be helpful to start implement this blueprint.

As I found, there is only one problem with C++0x -- on Windows, using MinGW, since for Qt 4 there is used GCC 4.4.

Here, I added https://github.com/troyane/mixxx/commit/b4196e7bffcdf5271a72e07838d2e5644be7aef3 C++0x support, so We can compile Mixxx (on supported platforms) using C++0x features.