Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: preventing plugin from locking gui (Read 3836 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

preventing plugin from locking gui

Hi all,

I'm new here and trying to develop a plugin that tries to automatically predict the genre of a soong by calculating some features of the audio data.

At the moment I can call by plugin from mainmenu and tell it to calculate for all songs in database, but it locks the gui, until it finished and wrote the prediction to metadata. On a large databese ths can take a few hours foobar won't respond.

So my question:

Is there a way to run the plugin in background, to prevent it from locking the gui?

Thanks for your help.
Peter

preventing plugin from locking gui

Reply #1
Quote
Is there a way to run the plugin in background, to prevent it from locking the gui?

Yes, you can create a new thread and do the calculation in this thread.

preventing plugin from locking gui

Reply #2
Thank you Ganymed,

I tried this before but the gui still gets locked.
What I did:

Code: [Select]
virtual void perform_command(unsigned n)
    {
 if (n==0 && core_api::assert_main_thread())
 {    
     HANDLE hThread;
     
     DWORD id;
     SetThreadPriority(hThread, -1);
     hThread = CreateThread(0,0,g_ThreadFunc,this,0,&id);
     
 }
    }


Any idea what is wrong?

preventing plugin from locking gui

Reply #3
Does your worker thread lock the database?

preventing plugin from locking gui

Reply #4
Quote
Does your worker thread lock the database?
[a href="index.php?act=findpost&pid=364983"][{POST_SNAPBACK}][/a]


Yes, it did. Thank you.

Now I can scroll the playlist for a few seconds, before the gui locks again.
Any other suggestion?

Another question:
Is it safe not to lock databease when doing meta data operations?

preventing plugin from locking gui

Reply #5
Quote
[a href="index.php?act=findpost&pid=364986"][{POST_SNAPBACK}][/a]

That depends on what exactly you are doing. If you just need to query the list of items in the database, you don't need to lock it. If you need to query path and subsong from metadb_handles, then you don't need to lock it either, since these values are guaranteed to be constant during the lifetime of metadb_handle.

You can get a copy of the metadata associated with a metadb_handle by using the query_info() method. If you do not want to copy the metadata, you an get a reference to it via query_info_locked(); as the name indicates, you have to lock the database when you use this method.

If you want to update metadata, well, I do not remember how this was done in 0.9, so I would have to look it up.

As a rule of thumb, every method that has "locked" in its name can only be used while you hold the required lock. If a method can only be used from the main thread or requires other special synchronization, there should be comment on the method, on the class it is in or at the start of the file it is declared in.