Is it the right way to pass an argument to callback?
| From: | Ruslan Osmanov | Date: | Sun, 06 Nov 2011 15:37:11 +0000 |
| Subject: | Is it the right way to pass an argument to callback? | ||
| Groups: | php.pecl.dev | ||
| Request: | Send a blank email to pecl-dev+get-8811@lists.php.net to get a copy of this message | ||
Hello.
I wonder if I pass a callback argument here the right way:
http://susepaste.org/99481533
It generally works as follows.
<?php
function mycb($d, $r) { echo "mycb\n"; }
eio_nop(0, "mycb", "some data"); while (eio_nreqs()) eio_poll();
?>
eio_nop calls an external library function with the same name.
The latter allocates data for a new thread, and eventually calls pthread_create().
http://susepaste.org/14228605 (etp_submit() creates a thread).
eio_nreqs() checks if there is something queued.
eio_poll() makes some of the queued tasks to execute, and calls callbacks for each task
(in our case the only, eio_nop with callback php_eio_res_cb).
When the program flow goes into php_eio_res_cb(eio_req *req), the argument (req)
looses it's value! Why and where? eio_poll() internally calls it like
/* here req is correct */
int res = EIO_FINISH (req); /* php_eio_res_cb(req) { !!! req is incorrect here !!! } */
/* here req is correct again! */
I tried to disassemble the code. Didn't found what makes it to behave such a weird way.
The extension is my first experience in PECL. So I'm asking for help of you, guru,
who will notice my dumb fault.
Thank you.