lpereira / lwan

Experimental, scalable, high performance HTTP server
https://lwan.ws
GNU General Public License v2.0
5.92k stars 549 forks source link

I miss function coro_get_data() #233

Closed sjnam closed 6 years ago

sjnam commented 6 years ago

I remember there was a function coro_get_data() in the past, but now I can not find it in the source code. When I started to create an application with lwan's coroutine, I needed that function. Do you intend to revive the coro_get_data() function again? And why did you remove the function?

Thank you.

lpereira commented 6 years ago

The data parameter is now passed to the coroutine entry point, which previously only received a pointer to a coroutine struct. This was done to remove one void* from the coroutine struct, to reduce its size. Without increasing the size of the coroutine struct, it's not possible to implement coro_get_data() again; however, the functionality isn't lost, it's just been replaced by something else.

To illustrate, the uses in Lwan were similar to the following:

int some_coroutine(struct coro *c)
{
           struct private_data *pd = coro_get_data(c);

           while (...) {
                 ...
           }
}

Whereas it's now like this:

int some_coroutine(struct coro *c, void *data)
{
           struct private_data *pd = data;

           while (...) {
                 ...
           }
}

So, as you can see, it's not much different, but this saves ~8 bytes per coroutine struct on a 64-bit machine.