lkml.org 
[lkml]   [2012]   [May]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    SubjectRe: [PATCH v3 12/16] Closures
    From
    Date
    On Fri, 2012-05-25 at 13:25 -0700, Kent Overstreet wrote:
    > Asynchronous refcounty thingies; they embed a refcount and a work
    > struct. Extensive documentation follows in include/linux/closure.h
    []
    > diff --git a/include/linux/closure.h b/include/linux/closure.h
    []
    > +enum closure_type {
    > + TYPE_closure = 0,

    I still think these should be
    CLOSURE_TYPE_closure
    etc.

    > +#define __CLOSURE_TYPE(cl, _t) \
    > + __builtin_types_compatible_p(typeof(cl), struct _t) \
    > + ? TYPE_ ## _t : \
    CLOSURE_TYPE_##_t

    > +#define __closure_type(cl) \
    > +( \
    > + __CLOSURE_TYPE(cl, closure) \
    > + __CLOSURE_TYPE(cl, closure_with_waitlist) \
    > + __CLOSURE_TYPE(cl, closure_with_timer) \
    > + __CLOSURE_TYPE(cl, closure_with_waitlist_and_timer) \
    > + invalid_closure_type() \
    > +)

    You should still feel dirty about this...

    > +#define continue_at(_cl, _fn, _wq, ...) \
    > +do { \
    > + BUG_ON(!(_cl) || object_is_on_stack(_cl)); \
    > + closure_set_ip(_cl); \
    > + set_closure_fn(_cl, _fn, _wq); \
    > + closure_sub(_cl, CLOSURE_RUNNING + 1); \
    > + return __VA_ARGS__; \
    > +} while (0)

    Does this have to be a macro?

    > diff --git a/lib/closure.c b/lib/closure.c
    []
    > +#define CL_FIELD(type, field) \
    > + case TYPE_ ## type: \
    > + return &container_of(cl, struct type, cl)->field
    > +
    > +static struct closure_waitlist *closure_waitlist(struct closure *cl)
    > +{
    > + switch (cl->type) {
    > + CL_FIELD(closure_with_waitlist, wait);
    > + CL_FIELD(closure_with_waitlist_and_timer, wait);
    > + default:
    > + return NULL;
    > + }
    > +}

    Here:

    static struct closure_waitlist *closure_waitlist(struct closure *cl)
    {
    switch (cl->type) {
    case CLOSURE_TYPE_closure_with_waitlist:
    return &container_of(cl, struct closure_with_waitlist, cl)->wait;
    case CLOSURE_TYPE_closure_with_waitlist_and_timer:
    return &container_of(cl, struct closure_with_waitlist_and_timer, cl)->wait;
    }

    return NULL;
    }




    \
     
     \ /
      Last update: 2012-05-25 23:41    [W:4.257 / U:0.076 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site