<ax:aspect xmlns:cpp="http://www.sdml.info/srcML/cpp" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ax="http://control.ee.ethz.ch/XWeaver/AspectX" xmlns:util="http://www.pnp-software.com/util" xmlns:src="http://www.sdml.info/srcML/src" xmlns:java="http://www.sdml.info/srcML/java" name="ThreadSafety">
  
<ax:pointcut constraint="contains(src:name,'set') or contains(src:name, 'increase') or contains(src:name, 'decrease')" name="MethodsToBeLocked" type="src:function">
    
<ax:restriction type="within">
      
<ax:pointcut type="src:unit">
        
<ax:restriction type="isDefinitionOf">
          
<ax:pointcutRef aspect="ThreadSafety" ref="ClassesToBeLocked" type="src:class" />
        
</ax:restriction>
      
</ax:pointcut>
    
</ax:restriction>
  
</ax:pointcut>
  
<ax:pointcut constraint="src:name='Datapool'" name="ClassesToBeLocked" type="src:class">
    
<ax:description>Classes for which thread safety shall be added</ax:description>
  
</ax:pointcut>
  
<ax:pointcut name="Constructors" type="src:constructor">
    
<ax:restriction type="within">
      
<ax:pointcut type="src:unit">
        
<ax:restriction type="isDefinitionOf">
          
<ax:pointcutRef aspect="ThreadSafety" ref="ClassesToBeLocked" type="src:class" />
        
</ax:restriction>
      
</ax:pointcut>
    
</ax:restriction>
  
</ax:pointcut>
  
<ax:pointcut name="Destructors" type="src:destructor">
    
<ax:restriction type="within">
      
<ax:pointcut type="src:unit">
        
<ax:restriction type="isDefinitionOf">
          
<ax:pointcutRef aspect="ThreadSafety" ref="ClassesToBeLocked" type="src:class" />
        
</ax:restriction>
      
</ax:pointcut>
    
</ax:restriction>
  
</ax:pointcut>
  
<ax:advice name="LockMutex" type="begin">
    
<ax:description>Adds pthrea_locker</ax:description>
    
<ax:pointcutRef aspect="ThreadSafety" ref="MethodsToBeLocked" type="src:function" />
    
<ax:codeModifier type="codeFragment">
      
<ax:text>pthread_mutex_lock(&amp;_mutex);</ax:text>
    
</ax:codeModifier>
  
</ax:advice>
  
<ax:advice name="UnlockMutex" type="end">
    
<ax:description>Adds pthrea_locker</ax:description>
    
<ax:pointcutRef aspect="ThreadSafety" ref="MethodsToBeLocked" type="src:function" />
    
<ax:codeModifier type="codeFragment">
      
<ax:text>pthread_mutex_unlock(&amp;_mutex);</ax:text>
    
</ax:codeModifier>
  
</ax:advice>
  
<ax:advice name="AddMutexMember" type="add">
    
<ax:pointcutRef aspect="ThreadSafety" ref="ClassesToBeLocked" type="src:class" />
    
<ax:codeModifier type="declaration">
      
<ax:accessModifier type="private" />
      
<ax:text />
      
<ax:text>/**</ax:text>
      
<ax:text> * The mutex that is used to protect </ax:text>
      
<ax:text> * setter and increase/decrease methods</ax:text>
      
<ax:text> * from simultaneous access</ax:text>
      
<ax:text> */</ax:text>
      
<ax:text>pthread_mutex_t _mutex;</ax:text>
    
</ax:codeModifier>
  
</ax:advice>
  
<ax:advice name="InitMutexInConstructor" type="begin">
    
<ax:pointcutRef aspect="ThreadSafety" ref="Constructors" type="src:constructor" />
    
<ax:codeModifier type="codeFragment">
      
<ax:text>pthread_mutex_init(&amp;_mutex, NULL);</ax:text>
    
</ax:codeModifier>
  
</ax:advice>
  
<ax:advice name="DestroyMutexInDestructor" type="begin">
    
<ax:description>Calls <code>pthread_mutex_destroy()</code> on the _mutex object.</ax:description>
    
<ax:pointcutRef aspect="ThreadSafety" ref="Destructors" type="src:destructor" />
    
<ax:codeModifier type="codeFragment">
      
<ax:text>pthread_mutex_destroy(&amp;_mutex);</ax:text>
    
</ax:codeModifier>
  
</ax:advice>
  
<ax:advice name="AddIncludes" type="add">
    
<ax:pointcut type="src:unit">
      
<ax:restriction type="contain">
        
<ax:pointcutRef aspect="ThreadSafety" ref="ClassesToBeLocked" type="src:class" />
      
</ax:restriction>
    
</ax:pointcut>
    
<ax:codeModifier type="include">
      
<ax:text>#include &lt;pthread.h&gt;</ax:text>
      
<ax:text>#include &lt;stdio.h&gt;</ax:text>
    
</ax:codeModifier>
  
</ax:advice>
  
<ax:advice name="CommentConstructor" type="end">
    
<ax:pointcut type="src:comment">
      
<ax:restriction type="followedBy">
        
<ax:pointcut type="src:constructor_decl">
          
<ax:restriction type="within">
            
<ax:pointcutRef aspect="ThreadSafety" ref="ClassesToBeLocked" type="src:class" />
          
</ax:restriction>
        
</ax:pointcut>
      
</ax:restriction>
    
</ax:pointcut>
    
<ax:codeModifier type="comment">
      
<ax:text />
      
<ax:text>ThreadSafety Aspect:</ax:text>
      
<ax:text> - Initializes the _mutex member variable.</ax:text>
    
</ax:codeModifier>
  
</ax:advice>
  
<ax:advice name="CommentDestructor" type="end">
    
<ax:description>Calls <code>pthread_mutex_destroy()</code> on the _mutex object.</ax:description>
    
<ax:pointcut type="src:comment">
      
<ax:restriction type="followedBy">
        
<ax:pointcut type="src:destructor_decl" />
      
</ax:restriction>
    
</ax:pointcut>
    
<ax:codeModifier type="comment">
      
<ax:text />
      
<ax:text>ThreadSafety Aspect:</ax:text>
      
<ax:text> - Destroys the _mutex member variable.</ax:text>
    
</ax:codeModifier>
  
</ax:advice>
  
<ax:advice name="CommentMethods" type="end">
    
<ax:pointcut type="src:comment">
      
<ax:restriction type="followedBy">
        
<ax:pointcut constraint="contains(src:name,'set') or contains(src:name, 'increase') or contains(src:name, 'decrease')" type="src:function_decl">
          
<ax:restriction type="within">
            
<ax:pointcutRef aspect="ThreadSafety" ref="ClassesToBeLocked" type="src:class" />
          
</ax:restriction>
        
</ax:pointcut>
      
</ax:restriction>
    
</ax:pointcut>
    
<ax:codeModifier type="comment">
      
<ax:text />
      
<ax:text>ThreadSafety Aspect:</ax:text>
      
<ax:text> - Protected against simultaneous access from threads.</ax:text>
    
</ax:codeModifier>
  
</ax:advice>
</ax:aspect>






































v