Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library refactoring #55

Closed
wants to merge 12 commits into from
Closed

Conversation

troyane
Copy link
Contributor

@troyane troyane commented Jul 31, 2013

This is code for review.

Here you can find extended explanation of idea of usage 2 semaphores.

NOTE: DB is still locked while tranaction is open but not commited.
Added pause feature (according to Steven Boswell patch)
Added dao.cpp file.

This example is working in restricted conditions:
 - when you do library scanning you can pause it (by clicking pause
button);
 - when you cancel library scanning (by clicking pause button);
 - when you (ONLY!) add new playlist while library scanning in process
(no need to click pause button).
@daschuer
Copy link
Member

daschuer commented Aug 1, 2013

Thank you for the pull request.

Please merge from master and resolve the conflicts, so we will get a clean diff.

s_semaphoreTransaction.acquire("DAO::enterLockState");
qDebug() << "\t\t entering LockState transaction time = " << QString::number( static_cast<double>(t.elapsed()) / 1e9, 'f', 4);
}
++s_semaphoresLockedCount;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current implementation you have a possible race condition, if a thread switch occurs between checking the s_semaphoresLockedCount and incrementing it. Semaphores are already counting, will it be possible to use them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean already counting?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I miss-read your code. Why it is required that only the first call is locking? This means if we have three concurenting DAOs only one of them is blocked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is for LibraryScanner thread, so it is required to acquire semaphores only once. It is not used for simultaneous calls from other threads. Maybe method name is not clear, mean it to lock semaphores in library-scan time.

@kain88-de
Copy link
Member

I don't think this is the right way to go. I'd be more comfortable if we had just one thread for DB access that is decoupled from the GUI-thread. Their is still a good chance for short GUI freezes with your code. You are now adding code so that the trackdao will act differently according to what thread it is generated in. For good readability and maintenance a class should always behave the same way no matter what thread called it.

Also I don't see (from the code) that it is now possible to edit playlists/crates while libraray scanner is running unless the user clicks pause. I envisioned a solution that the libraryscanner runs in the background and mixxx automatically takes care of pausing transactions if the user wants to edit other parts of the DB.

Did you check how other programs handle the library access?

DAO::pauseSemaphore().acquire("TrackCollection");
}

if (transactionFinished) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can get rid of "transactionFinished" if you put the following code in the block above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that behavior is different from what you recommend. We open (reopen) transaction when it was finished before. It means, that once we tried to acquire pause semaphore and it was locked (we can't acquire it), so we are in pause -- need to close transaction, release transaction semaphore, say that we finished transaction and wait here for "end" of pause. Then, if we finished transaction we must reopen it...

Otherwise, if we acquire pause semaphore in DAO::pauseSemaphore().tryAcquire(), we just move on and do not close transaction.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong. Added new commit to apply Daniel's changes.

@troyane
Copy link
Contributor Author

troyane commented Aug 1, 2013

@daschuer I've done merge with trunk.

@troyane
Copy link
Contributor Author

troyane commented Aug 1, 2013

@kain88-de
This branch is just extended idea on how to leave most of code as it is,
but implement pause in library scanning process (and pause scanning process while
doing little queries). Also, here implements possibility
to interact DAOs with library scanner. Please, read my explanation on how does
this idea works here -- https://docs.google.com/document/d/19W8b9xvFRrfktYB9zr1V0zrh2zuVAxADyPBioEunzZI/pub.

Deriving TrackDAO's behavior to LibraryScanner's and just TrackDAO is
just for testing. I agree with you, that this kind of code is hard to
maintain, we must avoid id.

To avoid any freezing GUI we do really need to rewrite all database access
according to proposed prototype (please see https://github.com/troyane/lambdaConcurrent)
and explanation of this idea -- https://docs.google.com/document/d/1K2XpAmN68f5U6iv9SSZcmaDrpVjhp61S7GkQCMmLjm4/pub.

@troyane
Copy link
Contributor Author

troyane commented Aug 2, 2013

@kain88-de Here is blueprint on migration https://blueprints.launchpad.net/mixxx/+spec/qt5-c++11.

Problem on using C++11 is also presented in Windows, because Qt4 uses MinGW 4.4. We must discuss migration issue (at list to use C++11, but not Qt5).

By the way, that is interesting idea to use CLang instead of GCC.

@daschuer
Copy link
Member

Hi @troyane,
since you have issued #73, can we close this one?

@troyane
Copy link
Contributor Author

troyane commented Sep 26, 2013

Yes, right.

m0dB pushed a commit to m0dB/mixxx that referenced this pull request Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants