为什么在线程未阻塞时仍调用 nativeWake()?

Why still calling nativeWake() when the thread not blocking?

为什么线程没有阻塞时仍然调用nativeWake()

当一个线程调用enqueueMessage()方法时,说明线程没有阻塞,为什么还要调用nativeWake()?

MessageQueue#enqueueMessage

boolean enqueueMessage(Message msg, long when) {

       ……
            if (needWake) {
                nativeWake(mPtr);
           }
     }

当所有消息都在等待时,您对其中之一调用入队,它只是检查头部,以防某些重要的东西刚刚安装在顶部。

        //Log.d("MessageQueue", "Enqueing: " + msg);
        Message p = mMessages;
        if (p == null || when == 0 || when < p.when) {
            msg.next = p;
            mMessages = msg;
            needWake = mBlocked; // new head, might need to wake up
        } else {
            Message prev = null;
            while (p != null && p.when <= when) {
                prev = p;
                p = p.next;
            }
            msg.next = prev.next;
            prev.next = msg;
            needWake = false; // still waiting on head, no need to wake up
        }
    }
    if (needWake) {
        nativeWake(mPtr);
    }

所以你跳过了重要的部分。