Thanks, as explained I am indeed porting old code.
No on the AA (as noted above). The mutex *is* created on
demand. Every Object can have a mutex, and it's only created
when you synchronize it for the first time.
Yes alright. I think the dev made a design mistake because he
called synchronized( OpenAL.mutex ) when it should be more of a
global, non OpenAL specific, mutex. I mean in the code there were
things like (pseudo-code)
---
System {
private int[] buffer
func() {
synch (openal.mutex)
{
openal.dosmthg (buffer)
buffer.change() // buffer being the member of System
openal.dosmthg(buffer)
}
}
}
---
Basically, it's the entire buffers handling ( the 3 statements)
which should be done the "atomic" way, not just the calls to
openAL. So the mutex should be a member variable of System at
worse. I just replaced
synchronized ( openal.mutex ) {
by
synchronized { // create a global mutex
Of course synchronized (open.mutex) would probably work, but
getting the mutex of an abstract class which is used only in part
of the calls looks like a design error to me!
I would say the AA initialization is standard D. Using the
class as a namespace isn't standard or necessary. If anything,
it should be a struct, or you can use a template. But I can't
see why you can't just use a module.
I replaced the AA entirely (by a switch in a nested function!).
Got rid of the static init() then.
I replaced 'class' by 'struct', which does not oblige me to
change the entire code using the syntax "OpenAL.smthg" . But I
was tempted to go to the next step:
import OpenAL = ...openal; // should not have to change any code
either if it works!
I just have to verify all the imports in the other modules and I
can delete the "struct OpenAL" scope. I don't have enough
experience in D2 to think about the impact of such a change
though, ie from *****
---
// openal.d file
module a.b.OpenAL
struct OpenAL{ void dosmthg()}
// another file
import a.b.OpenAL
OpenAL.dosmthg()
---
******** to *******
---
// openal.d file
module a.b.OpenAL
void dosmthg()
// another file
import OpenAL = a.b.OpenAL
OpenAL.dosmthg()
---
Thanks again for all the info so far. Learning a lot.