Show
Ignore:
Timestamp:
03/10/09 18:51:05 (5 years ago)
Author:
robert
Message:

From Mathias Froehlich, "an other topic pointed out by some Microsoft verification tool:
On destruction of some static variables, the global referenced mutex is used
to lock access to the parent lists of state attributes, nodes and so on.
This even happens past the mutex is already destroyed.

This change to Referenced.cpp revision 9851 uses the same technique like the
DeleteHandlerPointer? already in Referenced.cpp to return an zero pointer for
the global referenced lock if it is already destroyed."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osg/Referenced.cpp

    r9549 r9893  
    3434 
    3535// specialized smart pointer, used to get round auto_ptr<>'s lack of the destructor reseting itself to 0. 
    36 struct DeleteHandlerPointer 
    37 { 
    38     DeleteHandlerPointer(): 
     36template<typename T> 
     37struct ResetPointer 
     38{ 
     39    ResetPointer(): 
    3940        _ptr(0) {} 
    4041 
    41     DeleteHandlerPointer(DeleteHandler* ptr): 
     42    ResetPointer(T* ptr): 
    4243        _ptr(ptr) {} 
    4344 
    44     ~DeleteHandlerPointer() 
     45    ~ResetPointer() 
    4546    { 
    4647        delete _ptr; 
     
    4849    } 
    4950 
    50     inline DeleteHandlerPointer& operator = (DeleteHandler* ptr) 
     51    inline ResetPointer& operator = (T* ptr) 
    5152    { 
    5253        if (_ptr==ptr) return *this; 
     
    5657    } 
    5758 
    58     void reset(DeleteHandler* ptr) 
     59    void reset(T* ptr) 
    5960    { 
    6061        if (_ptr==ptr) return; 
     
    6364    } 
    6465 
    65     inline DeleteHandler& operator*()  { return *_ptr; } 
    66  
    67     inline const DeleteHandler& operator*() const { return *_ptr; } 
    68  
    69     inline DeleteHandler* operator->() { return _ptr; } 
    70  
    71     inline const DeleteHandler* operator->() const   { return _ptr; } 
    72  
    73     DeleteHandler* get() { return _ptr; } 
    74  
    75     const DeleteHandler* get() const { return _ptr; } 
    76  
    77     DeleteHandler* _ptr; 
     66    inline T& operator*()  { return *_ptr; } 
     67 
     68    inline const T& operator*() const { return *_ptr; } 
     69 
     70    inline T* operator->() { return _ptr; } 
     71 
     72    inline const T* operator->() const   { return _ptr; } 
     73 
     74    T* get() { return _ptr; } 
     75 
     76    const T* get() const { return _ptr; } 
     77 
     78    T* _ptr; 
    7879}; 
    7980 
     81typedef ResetPointer<DeleteHandler> DeleteHandlerPointer; 
     82typedef ResetPointer<OpenThreads::Mutex> GlobalMutexPointer; 
     83 
    8084OpenThreads::Mutex* Referenced::getGlobalReferencedMutex() 
    8185{ 
    82     static OpenThreads::Mutex s_ReferencedGlobalMutext; 
    83     return &s_ReferencedGlobalMutext; 
     86    static GlobalMutexPointer s_ReferencedGlobalMutext = new OpenThreads::Mutex; 
     87    return s_ReferencedGlobalMutext.get(); 
    8488} 
    8589