trema / trema-edge

Transient repository for Trema OF1.3 branch
27 stars 14 forks source link

Thread safe task passing to Trema #114

Closed rakshasa closed 10 years ago

rakshasa commented 10 years ago

Added support for thread safe passing of ruby blocks for execution in the Trema thread context.

yasuhito commented 10 years ago

Could you give us a code snippet that describes the use-cases of this functionality.

rakshasa commented 10 years ago
class Controller < Trema::Controller
  include TremaTasks
end

class DpInfo
  def add_flows(flows)
    return if flows.blank?
    @controller.pass_task {
      flows.each { |flow|
        @controller.send_flow_mod_add(@dpid, flow.to_trema_hash)
      }
    }
  end
end

By calling 'add_flows' any thread can safely pass a set of flows to the trema thread, in the context which the Controller is running.

yasuhito commented 10 years ago

I see. Thanks for the patch.