2014-03-07 19:40 GMT+01:00 Iñaki Baz Castillo <[email protected]>: > I have a working solution that I just don't like: > > --------------------------------------------- > std::function<void(uv_idle_t*, int)> callback; > > void wrapper(uv_idle_t* handle, int status) { > callback(handle, status); > } > > > Worker::Worker() { > this->number = 42; > > this->loop = new uv_loop_t; > uv_loop_init(this->loop); > > this->idle = new uv_idle_t; > uv_idle_init(this->loop, this->idle); > > auto callback = std::bind(&Worker::Callback, this, std::placeholders::_1, > std::placeholders::_2); > uv_idle_start(this->loop, wrapper); // Note that here I pass wrapper > instead of callback. > > uv_run(this->loop, UV_RUN_DEFAULT); > } > > > // Callback to be called by the UV idle. > void Worker::Callback(uv_idle_t* handle, int status) { > // do something with Worker instance members: > printf("my number is %d\n", this->number); > } > ---------------------------------------------
Well, this second "working" solution is not thread safe at all, so also invalid. I've been told in the libuv IRC channel that, indeed, std::bind returns a C++ object, something that cannot be "casted" into a function pointer, and thus, my first approach is just not possible. So I must play with the handle's data structure and store there my "this" pointer. Best regards. -- Iñaki Baz Castillo <[email protected]> -- 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 http://groups.google.com/group/libuv. For more options, visit https://groups.google.com/d/optout.
