net: Avoid extra wakeups of threads blocked in wait_for_packet()
[deliverable/linux.git] / net / core / datagram.c
index d0de644b378d5a71e161a905c85d847622df49d2..b01a76abe1d2f99dc577064037e4b4a1cb9ecd82 100644 (file)
@@ -64,13 +64,25 @@ static inline int connection_based(struct sock *sk)
        return sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM;
 }
 
+static int receiver_wake_function(wait_queue_t *wait, unsigned mode, int sync,
+                                 void *key)
+{
+       unsigned long bits = (unsigned long)key;
+
+       /*
+        * Avoid a wakeup if event not interesting for us
+        */
+       if (bits && !(bits & (POLLIN | POLLERR)))
+               return 0;
+       return autoremove_wake_function(wait, mode, sync, key);
+}
 /*
  * Wait for a packet..
  */
 static int wait_for_packet(struct sock *sk, int *err, long *timeo_p)
 {
        int error;
-       DEFINE_WAIT(wait);
+       DEFINE_WAIT_FUNC(wait, receiver_wake_function);
 
        prepare_to_wait_exclusive(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE);
 
This page took 0.027043 seconds and 5 git commands to generate.