bt_gatt_write_without_response_cb / bt_gatt_notify: how to prevent blocking

Hello,

calls to the above functions block the caller if internal queues become full.  Because my application is running in a big loop, I need those functions without blocking (a specific return code would suffice).

Is there any way to prevent those functions from blocking?  Or is there another non-blocking API doing similar things?

Thanks & regards

Hardy

PS: my current workaround is a small extra thread for packet transmission which is allowed to block (extra buffer, extra stack, extra copy operation).  But this seems to be like using a sledge-hammer to crack a nut

Parents Reply Children
  • I was looking for a place to raise the same issue. This just cost me some time and it's not very clear that this can block in such a manner. The blocks can become extremely long as well as you've said.

    In our use case we really want to maximize throughput while minimizing latency. I will probably add a separate thread (workqueue) to handle the sends.

    Also a very important note:

    Adding the send work to the system work queue will make the send (partially) non-blocking. This means that if no TX buffer is available, the send will fail instead of waiting until it can get a buffer and sending at that time. So if you use the system workqueue, make sure you are resubmitting failed sends to the queue if you want them to get through.

    This is not the case when using a different workqueue. In that case, the send (inside the workqueue) will block until the buffer is acquired. But since the buffer is freed inside the workqueue, the ATT system makes an exception for the system workqueue because it would never acquire the buffer. 

    This is something I noticed because I first did not realise this system was blocking and started debugging until I found that the block usually occurs in tx_meta_data_alloc inside att.c, which has a comment explaining the above.

Related