[vlc-devel] commit: Qt4: store input_item_t* in plitem and handle metadata in model ( Ilkka Ollakka )

Jakob Leben jakob.leben at gmail.com
Thu Aug 13 23:52:29 CEST 2009

On Thu, Aug 13, 2009 at 6:30 PM, Jakob Leben <jakob.leben at gmail.com> wrote:

> My idea was to not have another hierarchy for the Qt4 model at all, to
> really just use p_playlist_t and p_playlist_item_t.
> We would use
> QModelIndex index = createIndex (row, 0, *(playlist_item_t *)* item);
> Then for example:
> int rowCount( QModelIndex index)
>> {
>>     return static_cast<playlist_item_t*>( index.internalPointer()
>> )->i_children;
>> }
I see a big problem here that I just can't see a solution to:

Suppose we hand out playlist_item_t * in a QModelIndex to a Qt view. It
might happen that another thread messes with the data of the playlist_item_t
before the view uses that QModelIndex, that is before the view calls a
function with it as an argument, so that the function could lock the
playlist. Basically there is time between handing out a QModelIndex and it
being used when the thread which handed out the QModelIndex doesn't hold the
playlist lock.

Now if the other thread simply deleted some items and we have reference
counting, our pointers to them would still be valid. But imagine that in the
time when we don't hold the lock the other thread adds a child to the
playlist item, so changes it's pp_children field, but then unreferences both
the item and its new child, before we could add a reference to the child!
The former item will still exist as we had a reference to it, but with wrong
reference to a child that got already deleted, as we didn't add a reference
for it.

The whole problem is that we don't control the qt view's code that obtains
the QModelIndex, so we can't hold a lock for the whole time when that
QModelIndex exists.

Any idea?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20090813/7011c459/attachment.html>

More information about the vlc-devel mailing list