On Thu, Jun 13, 2013 at 05:03:02PM +0800, Liu Ping Fan wrote: > @@ -67,6 +67,10 @@ struct NetClientState { > NetClientInfo *info; > int link_down; > QTAILQ_ENTRY(NetClientState) next; > + /* protect the race access of peer only between reader and writer. > + * to resolve the writer's race condition, resort on biglock. > + */
Indentation > @@ -301,6 +303,38 @@ static void qemu_free_net_client(NetClientState *nc) > } > } > > +/* elimate the reference and sync with exit of rx/tx action. s/elimate/Eliminate/ > + * And flush out peer's queue. > + */ > +static void qemu_net_client_detach_flush(NetClientState *nc) > +{ > + NetClientState *peer; > + > + /* reader of self's peer field , fixme? the deleters are not concurrent, > + * so this pair lock can save. > + */ Indentation, also please resolve the fixme. > @@ -394,6 +433,28 @@ int qemu_can_send_packet(NetClientState *sender) > return 1; > } > > +int qemu_can_send_packet(NetClientState *sender) > +{ > + int ret = 1; > + > + qemu_mutex_lock(&sender->peer_lock); > + if (!sender->peer) { > + goto unlock; > + } > + > + if (sender->peer->receive_disabled) { > + ret = 0; > + goto unlock; > + } else if (sender->peer->info->can_receive && > + !sender->peer->info->can_receive(sender->peer)) { > + ret = 0; > + goto unlock; > + } Just call qemu_can_send_packet_nolock() instead of duplicating code?