Query regarding thread wait and notify in Haiku

Hi.

I’ve been trying to understand call flow in tcp packet recv/send flow. Particularly, I’m stuck on how threads work in Haiku kernel. In posix terms, I kinda understand threads but the syntax here is obviously different making it a lil confusing for me.

Here’s what I understand:

NIC —> rx_queue
NIC —> interrupt —> tcp_read_data → TCPEndpoint::ReadData

Now ReadData and works as per TCP RFC which says that we can wait till buffer is full before sending the data up to userspace. But how it does from code is where I have some doubts.

First call reaches here: _WaitForCondition From going into its definitions, looks like this kernel thread is blocked until condition finishes. If this is correct, does scheduler context switch to a different thread?

Then call goes below (pasting the code directly):

Here, NotifyAll presumably notifies other threads that queue is full. Does that mean we have multiple kernel threads working on ReadData/SendData flow?

	if (numBytes < fReceiveQueue.Available())
		fReceiveCondition.NotifyAll();

If there are articles on threads/scheduler, that would be helpful!

Yes, fReceiveCondition is a condition variable (a kind of synchronization primitive), which can be waited on. NotifyAll wakes up all other threads which are Waiting on it.

Here’s a page (should be in the API docs, but it seems there is a typo preventing it from showing up) describing synchronization primitives in the kernel: https://github.com/haiku/haiku/blob/da4dbfa47a47beb355289f3dd685797cee69ab77/docs/user/drivers/synchronization_primitives.dox

Yes, if the condition is not already satisfied, the thread will have to wait. So another thread can be run until then.

I think Notifyall was used for simplicity in writing the code, but in this case there will be only one thread trying to read data from the endpoint. So there are two threads: one adding data into the endpoint, and another one consuming said data.