[chord] what is wrap

Emil Sit sit at MIT.EDU
Wed Dec 20 09:16:18 EST 2006


On Tue, 19 December 2006 at 13:51 (+0800), zkfzle wrote:
> In the process of reading code, I met with the function wrap.I looked it up in some books.However, I haven't found its meaning.What does this word mean?
> For example,in the line:
> dhash->retrieve(ID, wrap(&gotindirect_cb, (BLOCKSIZE/sha1::hashsize)*(i*BLOCKSIZE/20)));

wrap is a C++ tool we have developed to construct callbacks--- we
have certain operations (e.g., dhash->retrieve) that complete
asynchronously and callbacks allow us to specify where (and with
what arguments) execution should continue when that operation
is complete.

In this case, we instruct the dhash object to retrieve ID and
when it has done so, it should call back into a function called
gotindirect_cb, with the first argument being an offset into
the indirect block represented by ID.  This argument and the
function pointer are "wrapped" up for libasync to call back later.

A tutorial on libasync and its use of callbacks may be found at:

    http://pdos.csail.mit.edu/6.824-2004/async/

-- 
Emil Sit / MIT CSAIL PDOS / http://pdos.csail.mit.edu/chord/  



More information about the chord mailing list