On Tue, Jun 18, 2013 at 8:25 PM, Stefan Hajnoczi <stefa...@gmail.com> wrote: > 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 > Will fix. >> @@ -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/ > Will fix >> + * 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. > So, here can I take the assumption that the deleters are serialized by biglock, and remove the lock following this comment?
>> @@ -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? Yes. Thx & regards, pingfan