Aw: Broken locking in old AddOnManager
Marcus Overhagen <[email protected]> Fri, 23 Jan 2004 09:42:05 +0100 (CET)
| Newsgroups | gmane.os.openbeos.mediakit |
|---|---|
| Message-ID | <32791804.1074847326773.JavaMail.ngmail@webmail01.arcor-online.net> |
> Hi there,
>
> just to note it here, since I forgot to put it into the CVS change
> message:
>
> Both AddOnManager::RegisterReader()/Decoder() had a broken locking
> strategy:
>
> void
> AddOnManager::RegisterReader()
> {
> 1) lock
> check if the reader already exists
> unlock
>
> ... initialize reader ...
>
> 2) lock
> add reader
> unlock
> }
>
> When you lock again in 2), the same reader could have been added in the
> meantime; you would have to check for its existence again.
> It's better in this case to hold the lock during the whole time, given
> that the whole process is relatively light-weight.
>
Well the idea was that RegisterReader() is only called from RegisterAddOns()
which is only executed once during startup (and only from a single thread).
The lock is only used to preserve list integrity (Rewind() changes internal list pointer).
As soon as we implement node watching to dynamically register/unregister plugins,
will get more complicated, but I still think this locking is ok.
Marcus