Changeset 226

Show
Ignore:
Timestamp:
06/11/05 18:39:00 (3 years ago)
Author:
ged
Message:

- Moved locking methods that should have gone over to GameObject? with the mutex

move.

Location:
trunk/lib/fm
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/fm/entity.rb

    r213 r226  
    105105 
    106106 
     107    ######### 
     108    protected 
     109    ######### 
     110 
     111    ### Fallback event handler. The default implementation of this method 
     112    ### just raises an UnhandledEventError, so deriviatives will probably 
     113    ### want to override it. 
     114    def handleAnyEvent( event ) 
     115        raise FaerieMUD::UnhandledEventError, 
     116              "No handler defined for #{event.class.name}s" 
     117    end 
     118 
     119 
    107120    ### Get a handler as a callable object for the given +event+. 
    108121    def getHandlerForEvent( event ) 
     
    140153 
    141154 
    142     ### Fallback event handler. The default implementation of this method 
    143     ### just raises an UnhandledEventError, so deriviatives will probably 
    144     ### want to override it. 
    145     def handleAnyEvent( event ) 
    146         raise FaerieMUD::UnhandledEventError, 
    147               "No handler defined for #{event.class.name}s" 
    148     end 
    149  
    150  
    151155    ### Callback invoked whenever a singleton method is added to the 
    152156    ### receiver. Clears the event handler lookup cache if the method being 
     
    161165    alias_method :singleton_method_undefined, :singleton_method_added 
    162166 
    163  
    164     ############################################################# 
    165     ### L O C K I N G   M E T H O D S 
    166     ############################################################# 
    167  
    168     ### Obtain a shared lock on the receiver for the duration of the 
    169     ### block. The mutex object is passed as argument. 
    170     def readlocked 
    171         return unless block_given? 
    172         @mutex.synchronize( Sync::SH ) { 
    173             yield( @mutex ) 
    174         } 
    175     end 
    176  
    177  
    178     ######### 
    179     protected 
    180     ######### 
    181  
    182     ### Obtain an exclusive lock on the receiver for the durection of the 
    183     ### block. The mutex object is passed as argument. 
    184     def writelocked 
    185         return unless block_given? 
    186         @mutex.synchronize( Sync::EX ) { 
    187             yield( @mutex ) 
    188         } 
    189     end 
    190  
    191167end # class FaerieMUD::Entity 
    192168 
  • trunk/lib/fm/gameobject.rb

    r215 r226  
    198198 
    199199 
    200  
    201200    ### Return the number of contribution points for the given +author+ (a 
    202201    ### String) the object is worth. 
    203202    def contribution( author ) 
    204203        self.class.authors[ author ] 
     204    end 
     205 
     206 
     207    ### Obtain a shared lock on the receiver for the duration of the 
     208    ### block. The mutex object is passed as argument. 
     209    def readlocked 
     210        return unless block_given? 
     211        @mutex.synchronize( Sync::SH ) { 
     212            yield( @mutex ) 
     213        } 
    205214    end 
    206215 
     
    224233    protected 
    225234    ######### 
     235 
     236    ### Obtain an exclusive lock on the receiver for the durection of the 
     237    ### block. The mutex object is passed as argument. 
     238    def writelocked 
     239        return unless block_given? 
     240        @mutex.synchronize( Sync::EX ) { 
     241            yield( @mutex ) 
     242        } 
     243    end 
     244 
    226245 
    227246    ### Return an HTML fragment for the header part of the given object.