ymoona wrote:
> 
> I tried making it static, but then I get an access violation when I try to
> acquire a lock.
> I made it static like this: OsBSem* OsTimerTask::sLock;
> 
> But then the constructor is not called causing an access violation
> 
> when I put a break point print on the original
> initialisation, I see that it is called twice.
> Function: `dynamic initializer for 'OsTimerTask::sLock''(void), Thread:
> 0xA80 OsFileBase::touch, Caller _initterm, Address 0x101F7740
> Function: `dynamic initializer for 'OsTimerTask::sLock''(void), Thread:
> 0xA80 OsFileBase::touch, Caller _initterm, Address 0x00449580
> 
> How do I make sLock static?
> 

I had a look at OsBSem* OsTimerTask::sLock again and it cannot be made
"static" static member because it is derived from OsBSemWnt, which has
in acquire(const OsTime& rTimeout = OsTime::OS_INFINITY);
OsTime::OS_INFINITY which is also a static member and might be
uninitialized during sLock uninitialization.


so having OsBSem OsTimerTask::sLock; in cpp file will not work.

You cant have just OsBSem* OsTimerTask::sLock; in cpp file as its just a
static pointer without an object, so when u access it you get access
violation.

That's why sLock is initialized using new, and never freed. It's
actually easy to get rid of this initialziation problem in sipxportlib
without any compiler tricks, but across libraries its more dificult.

The solution is :
- introduce init/shutdown methods for each library, init will create
singletons/static members and shutdown delete them. Each library would
have a counter in init/shutdown so it only initializes once and also
shutdowns only once (in case we get init, init, shutdown, shutdown).
Init and shutdown would make sure singletons are initialized and deleted
in the right order. Then init function would simply call static methods
Initialize and Shutdown of all classes that have some static members.
This is the cleanest solution.


We would only call sipxInitialize:

1.)sipxInitialize (would also initialize any global dynamic variables if
counter is 0, it would initialize all required libraries, increase
reference counter)
2.)SipXTackLib::Init() (if counter is 0, initialize all required
libraries - portlib, then initialize static members and singletons,
increase counter)
3.) SipXPortLib::Init() (called from tacklib init, if counter is 0,
initialize all static members and singletons, increase counter)
4.) SipXCallLib::Init() (it would initialize the same portlib again, but
this time singletons are already created and nothing new would be created)
5.) SipXPortLib::Init() (called from calllib)
6.) SipXMediaLib::Init() (it would initialize the same portlib again)
7.) SipXPortLib::Init() (called from medialib)

...

sipxUnInitialize (decrease counter, would delete global dynamic objects
if referece counter reaches 0, and also shutdown libraries)
8.)SipXTackLib::Shutdown() (decrease counter, if 0 then shutdown portlib)
9.)SipXPortLib::Shutdown() (called from tacklib, decrease counter, not
0, dont shutdown)
10.)SipXCallLib::Shutdown() (decrease counter, if 0 then shutdown portlib)
11.)SipXPortLib::Shutdown() (called from calllib, decrease counter, not
0, dont shutdown)
12.)SipXMediaLib::Shutdown() (decrease counter, if 0 then shutdown portlib)
13.)SipXPortLib::Shutdown() (called from media lib, decrease counter,
this time counter is 0, its safe to delete static members and singletons)

sipxsdplib and mediaadapterlib would also be initialized/uninitialized

Initialize and Shutdown would call public static methods Initialize and
Shutdown of all classes that have static members or singleton.

What do you guys think?

Jaroslav Libak
_______________________________________________
sipxtapi-dev mailing list
[email protected]
List Archive: http://list.sipfoundry.org/archive/sipxtapi-dev/

Reply via email to