Solving a dependency circle
"Christian, Martin, OPEE45" <[email protected]>
| Newsgroups | gmane.comp.micro-kernel.l4.l4ka.general |
|---|---|
| Message-ID | <[email protected]> |
This is not really a L4 question! However, it's a real problem for me,
while adapting the PowerPC arch to NICTAs L4.N1 API. The include files
create a circle of dependency. There are common solutions to this,
however this ones seems to be special or at least out of my mind.
I created this simple example:
<Alpha.h>
#ifndef ALPHA_H_
#define ALPHA_H_
#include "Alpha_inline.h"
class Beta;
class Alpha {
public:
inline void doSomething( Beta* b );
};
#endif /*ALPHA_H_*/
</Alpha.h>
<Alpha_inline.h>
#ifndef A_INLINE_H_
#define A_INLINE_H_
#include "Alpha.h"
#include "Beta.h"
/* Inline methods */
inline void Alpha::doSomething( Beta* b ) {
b->helpAlpha();
}
#endif /*A_INLINE_H_*/
</Alpha_inline.h>
<Beta.h>
#ifndef BETA_H_
#define BETA_H_
#include "Alpha.h"
class Beta {
private:
Alpha alpha;
public:
inline Alpha* getAlpha();
inline void useInline();
inline void helpAlpha();
};
/* Inline methods */
inline Alpha* Beta::getAlpha() {
return α
}
inline void Beta::useInline() {
this->getAlpha()->doSomething( this );
}
inline void Beta::helpAlpha() {
for ( volatile int i=0; i<1000; i++ );
}
#endif /*BETA_H_*/
</Beta.h>
<main.cpp>
#include "Beta.h"
int main( int argc, char** argv ) {
Beta b;
b.useInline();
return 0;
}
</main.cpp>
Compile with: gcc -Wall main.cpp -o dependency
The solution would be to include "Alpha_inline." in main.cpp. However,
the file belongs to the "API", which means I can't change it.
For the real problem, use this mapping for arch=powerpc:
Alpha -> GLUE(pgent.h)
Alpha_inline -> GLUE(pgent_inline.h)
Beta -> GLUE(space.h)
main.cpp -> i. e. API(exregs.cc)
Would someone know a solution? For some reason I haven't discovered,
L4Ka::Pistachio avoids this problem.
Cheers,
Martin.