lkml.org 
[lkml]   [2005]   [Mar]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: Documentation for krefs
Date
From

Hi Corey,

> Here is the documentation for krefs, with the kref_checked stuff
> removed and a few other things cleaned up.

Great, more documentation. :-) A few minor points...

> +To use a kref, add a one to your data structures like:

s/a one/one/

> +You must initialize the kref after you allocate it. To do this, call
> +kref init as so:

s/kref init/kref_init/

> +Once you have a refcount, you must follow the following rules:

s/refcount/initialised kref/

> + if (task == ERR_PTR(-ENOMEM)) {
> + rv = -ENOMEM;
> + kref_put(&data->refcount);

s/)/, data_release)/

> + goto out;
> + }
> +
> + .
> + . do stuff with data here
> + .
> + out:
> + kref_put(data, data_release);

s/data/\&data->refcount/ ?

> + return rv;
> +}
> +
> +This way, it doesn't matter what order the two threads handle the
> +data, the put handles knowing when the data is free and releasing it.

s/put/kref_put()/

> +The kref_get() does not require a lock, since we already have a valid
> +pointer that we own a refcount for. The put needs no lock because
> +nothing tries to get the data without already holding a pointer.

Cheers,


Ralph.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:10    [W:0.057 / U:0.512 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site