I have another idea: What about the coalescing calls in the uv_async_send to be optional?
So we can choose if the calls will coalesce or not. This could be set in uv_async_init. Because in some cases it is useful, as when the worker thread wants just to notify progress to the main thread. libuv behavior: When coalescing is ON: -libuv will NOT use a mutex and the value passed in the uv_async_send is put in the async_t->data When coalescing is OFF: -libuv will put the data pointer into a queue inside the async_t, using a mutex Let's review the use cases: ASYNCHRONOUS CALL + COALESCING ENABLED: -the worker thread will just send the return value to the main thread. The uv_async_send will be called just once. -the worker thread will send update notifications to the main thread as a single integer value, like a percent status. -the worker thread will send update notifications to the main thread as a pointer to a struct or string that is statically allocated and the content will not be modified. ASYNCHRONOUS CALL + COALESCING DISABLED: -the worker thread will send update notifications to the main thread as a pointer to a struct or string that is dynamically allocated (and must be free'd by the main thread). SYNCHRONOUS CALL: -the worker thread will send update notifications to the main thread as a pointer to a struct or string that is statically allocated but the content can be modified. It can be configured like this: uv_async_init(loop, &async, my_callback, LIBUV_COALESCE); uv_async_init(loop, &async, my_callback, LIBUV_NO_COALESCE); uv_async_init(loop, &async, my_callback, LIBUV_SYNCHRONOUS); Or maybe setting it in the async struct. In this case we can use a default value and for backwards compatibility it can be with the coalescing of calls enabled. If we need to change the option, the usage would be something like this: async.options = LIBUV_NO_COALESCE; If for some reason the call coalescing cannot be disabled, we just rename the options like: LIBUV_COALESCE -> LIBUV_ASYNC_NO_QUEUE or ... LIBUV_NO_COALESCE -> LIBUV_ASYNC_USE_QUEUE or ... And then when the callback is fired the libuv retrieves all the items from the queue and calls the callback function for each returned value. WDYT? -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
