I was thinking about something along this way:
// myplugin.c
plugin_t *current;
struct privateData {
// instance-specific data
};
Lock(plugin_t *plugin) {
acquire_mutex();
current = plugin;
}
Unlock() {
release_mutex();
}
DoSomething() {
printf("Hi, %s", ((privateData*) (current->pluginData))->someData);
}
// somewhere.c
Lock(pluginHandle);
DoSomething();
DoSomethingElse();
Unlock();
Lock(anotherHandle);
DoSomethingElse();
DoYetAnotherThing();
Unlock();
The idea is to keep a pointer to the current data, to avoid passing it each
time a function is called. I'll continue working with these.
EL
Le 7 Janvier 2001 11:06, vous avez écrit :
>
> Umm, won't that still affect the variables?
>
> MyPlugin a, b;
> Thread 1:
> a.DoWhatever();
> a.DoOtherStuff()
> Thread 2.
> b.DoWhatever();
>
> MyPlugin.DoWhatever() {
> acquire_mutex();
> // modify variables
> release_mutex();
> }
>
> MyPlugin.DoOtherStuff() {
> // modify yet another variable,
> // depending on the ones in DoWhatever()
> }
>
> Let's say the system decided to run your code like this:
> a.DoWhatever();
> b.DoWhatever();
> a.DoOtherStuff();
> Oops, seems like we're using the wrong values of a's variables.
>
> Or, did I get something wrong? This is at least what you have to think
> of in BeOS kernel programming; multithreaded, re-entrant kernel.
>
>
> --
> Mikael J @ http://hem.spray.se/tic_khr
> Registered and Proud BeOS Developer