diff --git a/events/Event.h b/events/Event.h index ecce6e983f..79cc7fb2d0 100644 --- a/events/Event.h +++ b/events/Event.h @@ -47,41 +47,17 @@ public: */ template Event(EventQueue *q, F f) { - struct local { - static int post(struct event *e) { - typedef EventQueue::context00 C; - struct local { - static void call(void *p) { (*static_cast(p))(); } - static void dtor(void *p) { static_cast(p)->~C(); } - }; - - void *p = equeue_alloc(e->equeue, sizeof(C)); - if (!p) { - return 0; - } - - new (p) C(*reinterpret_cast(e+1)); - equeue_event_delay(p, e->delay); - equeue_event_period(p, e->period); - equeue_event_dtor(p, &local::dtor); - return equeue_post(e->equeue, &local::call, p); - } - - static void dtor(struct event *e) { - reinterpret_cast(e+1)->~F(); - } - }; - _event = static_cast( equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F))); + if (_event) { _event->equeue = &q->_equeue; _event->id = 0; _event->delay = 0; _event->period = -1; - _event->post = &local::post; - _event->dtor = &local::dtor; + _event->post = &Event::event_post; + _event->dtor = &Event::event_dtor; new (_event+1) F(f); @@ -222,6 +198,38 @@ private: // F follows } *_event; + // Event attributes + template + static int event_post(struct event *e) { + typedef EventQueue::context00 C; + void *p = equeue_alloc(e->equeue, sizeof(C)); + if (!p) { + return 0; + } + + new (p) C(*(F*)(e + 1)); + equeue_event_delay(p, e->delay); + equeue_event_period(p, e->period); + equeue_event_dtor(p, &Event::function_dtor); + return equeue_post(e->equeue, &Event::function_call, p); + } + + template + static void event_dtor(struct event *e) { + ((F*)(e + 1))->~F(); + } + + // Function attributes + template + static void function_call(void *p) { + (*(F*)p)(); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + public: /** Create an event * @see Event::Event @@ -443,41 +451,17 @@ public: */ template Event(EventQueue *q, F f) { - struct local { - static int post(struct event *e, A0 a0) { - typedef EventQueue::context10 C; - struct local { - static void call(void *p) { (*static_cast(p))(); } - static void dtor(void *p) { static_cast(p)->~C(); } - }; - - void *p = equeue_alloc(e->equeue, sizeof(C)); - if (!p) { - return 0; - } - - new (p) C(*reinterpret_cast(e+1), a0); - equeue_event_delay(p, e->delay); - equeue_event_period(p, e->period); - equeue_event_dtor(p, &local::dtor); - return equeue_post(e->equeue, &local::call, p); - } - - static void dtor(struct event *e) { - reinterpret_cast(e+1)->~F(); - } - }; - _event = static_cast( equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F))); + if (_event) { _event->equeue = &q->_equeue; _event->id = 0; _event->delay = 0; _event->period = -1; - _event->post = &local::post; - _event->dtor = &local::dtor; + _event->post = &Event::event_post; + _event->dtor = &Event::event_dtor; new (_event+1) F(f); @@ -618,6 +602,38 @@ private: // F follows } *_event; + // Event attributes + template + static int event_post(struct event *e, A0 a0) { + typedef EventQueue::context10 C; + void *p = equeue_alloc(e->equeue, sizeof(C)); + if (!p) { + return 0; + } + + new (p) C(*(F*)(e + 1), a0); + equeue_event_delay(p, e->delay); + equeue_event_period(p, e->period); + equeue_event_dtor(p, &Event::function_dtor); + return equeue_post(e->equeue, &Event::function_call, p); + } + + template + static void event_dtor(struct event *e) { + ((F*)(e + 1))->~F(); + } + + // Function attributes + template + static void function_call(void *p) { + (*(F*)p)(); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + public: /** Create an event * @see Event::Event @@ -839,41 +855,17 @@ public: */ template Event(EventQueue *q, F f) { - struct local { - static int post(struct event *e, A0 a0, A1 a1) { - typedef EventQueue::context20 C; - struct local { - static void call(void *p) { (*static_cast(p))(); } - static void dtor(void *p) { static_cast(p)->~C(); } - }; - - void *p = equeue_alloc(e->equeue, sizeof(C)); - if (!p) { - return 0; - } - - new (p) C(*reinterpret_cast(e+1), a0, a1); - equeue_event_delay(p, e->delay); - equeue_event_period(p, e->period); - equeue_event_dtor(p, &local::dtor); - return equeue_post(e->equeue, &local::call, p); - } - - static void dtor(struct event *e) { - reinterpret_cast(e+1)->~F(); - } - }; - _event = static_cast( equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F))); + if (_event) { _event->equeue = &q->_equeue; _event->id = 0; _event->delay = 0; _event->period = -1; - _event->post = &local::post; - _event->dtor = &local::dtor; + _event->post = &Event::event_post; + _event->dtor = &Event::event_dtor; new (_event+1) F(f); @@ -1014,6 +1006,38 @@ private: // F follows } *_event; + // Event attributes + template + static int event_post(struct event *e, A0 a0, A1 a1) { + typedef EventQueue::context20 C; + void *p = equeue_alloc(e->equeue, sizeof(C)); + if (!p) { + return 0; + } + + new (p) C(*(F*)(e + 1), a0, a1); + equeue_event_delay(p, e->delay); + equeue_event_period(p, e->period); + equeue_event_dtor(p, &Event::function_dtor); + return equeue_post(e->equeue, &Event::function_call, p); + } + + template + static void event_dtor(struct event *e) { + ((F*)(e + 1))->~F(); + } + + // Function attributes + template + static void function_call(void *p) { + (*(F*)p)(); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + public: /** Create an event * @see Event::Event @@ -1235,41 +1259,17 @@ public: */ template Event(EventQueue *q, F f) { - struct local { - static int post(struct event *e, A0 a0, A1 a1, A2 a2) { - typedef EventQueue::context30 C; - struct local { - static void call(void *p) { (*static_cast(p))(); } - static void dtor(void *p) { static_cast(p)->~C(); } - }; - - void *p = equeue_alloc(e->equeue, sizeof(C)); - if (!p) { - return 0; - } - - new (p) C(*reinterpret_cast(e+1), a0, a1, a2); - equeue_event_delay(p, e->delay); - equeue_event_period(p, e->period); - equeue_event_dtor(p, &local::dtor); - return equeue_post(e->equeue, &local::call, p); - } - - static void dtor(struct event *e) { - reinterpret_cast(e+1)->~F(); - } - }; - _event = static_cast( equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F))); + if (_event) { _event->equeue = &q->_equeue; _event->id = 0; _event->delay = 0; _event->period = -1; - _event->post = &local::post; - _event->dtor = &local::dtor; + _event->post = &Event::event_post; + _event->dtor = &Event::event_dtor; new (_event+1) F(f); @@ -1410,6 +1410,38 @@ private: // F follows } *_event; + // Event attributes + template + static int event_post(struct event *e, A0 a0, A1 a1, A2 a2) { + typedef EventQueue::context30 C; + void *p = equeue_alloc(e->equeue, sizeof(C)); + if (!p) { + return 0; + } + + new (p) C(*(F*)(e + 1), a0, a1, a2); + equeue_event_delay(p, e->delay); + equeue_event_period(p, e->period); + equeue_event_dtor(p, &Event::function_dtor); + return equeue_post(e->equeue, &Event::function_call, p); + } + + template + static void event_dtor(struct event *e) { + ((F*)(e + 1))->~F(); + } + + // Function attributes + template + static void function_call(void *p) { + (*(F*)p)(); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + public: /** Create an event * @see Event::Event @@ -1631,41 +1663,17 @@ public: */ template Event(EventQueue *q, F f) { - struct local { - static int post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3) { - typedef EventQueue::context40 C; - struct local { - static void call(void *p) { (*static_cast(p))(); } - static void dtor(void *p) { static_cast(p)->~C(); } - }; - - void *p = equeue_alloc(e->equeue, sizeof(C)); - if (!p) { - return 0; - } - - new (p) C(*reinterpret_cast(e+1), a0, a1, a2, a3); - equeue_event_delay(p, e->delay); - equeue_event_period(p, e->period); - equeue_event_dtor(p, &local::dtor); - return equeue_post(e->equeue, &local::call, p); - } - - static void dtor(struct event *e) { - reinterpret_cast(e+1)->~F(); - } - }; - _event = static_cast( equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F))); + if (_event) { _event->equeue = &q->_equeue; _event->id = 0; _event->delay = 0; _event->period = -1; - _event->post = &local::post; - _event->dtor = &local::dtor; + _event->post = &Event::event_post; + _event->dtor = &Event::event_dtor; new (_event+1) F(f); @@ -1806,6 +1814,38 @@ private: // F follows } *_event; + // Event attributes + template + static int event_post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3) { + typedef EventQueue::context40 C; + void *p = equeue_alloc(e->equeue, sizeof(C)); + if (!p) { + return 0; + } + + new (p) C(*(F*)(e + 1), a0, a1, a2, a3); + equeue_event_delay(p, e->delay); + equeue_event_period(p, e->period); + equeue_event_dtor(p, &Event::function_dtor); + return equeue_post(e->equeue, &Event::function_call, p); + } + + template + static void event_dtor(struct event *e) { + ((F*)(e + 1))->~F(); + } + + // Function attributes + template + static void function_call(void *p) { + (*(F*)p)(); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + public: /** Create an event * @see Event::Event @@ -2027,41 +2067,17 @@ public: */ template Event(EventQueue *q, F f) { - struct local { - static int post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { - typedef EventQueue::context50 C; - struct local { - static void call(void *p) { (*static_cast(p))(); } - static void dtor(void *p) { static_cast(p)->~C(); } - }; - - void *p = equeue_alloc(e->equeue, sizeof(C)); - if (!p) { - return 0; - } - - new (p) C(*reinterpret_cast(e+1), a0, a1, a2, a3, a4); - equeue_event_delay(p, e->delay); - equeue_event_period(p, e->period); - equeue_event_dtor(p, &local::dtor); - return equeue_post(e->equeue, &local::call, p); - } - - static void dtor(struct event *e) { - reinterpret_cast(e+1)->~F(); - } - }; - _event = static_cast( equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F))); + if (_event) { _event->equeue = &q->_equeue; _event->id = 0; _event->delay = 0; _event->period = -1; - _event->post = &local::post; - _event->dtor = &local::dtor; + _event->post = &Event::event_post; + _event->dtor = &Event::event_dtor; new (_event+1) F(f); @@ -2202,6 +2218,38 @@ private: // F follows } *_event; + // Event attributes + template + static int event_post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + typedef EventQueue::context50 C; + void *p = equeue_alloc(e->equeue, sizeof(C)); + if (!p) { + return 0; + } + + new (p) C(*(F*)(e + 1), a0, a1, a2, a3, a4); + equeue_event_delay(p, e->delay); + equeue_event_period(p, e->period); + equeue_event_dtor(p, &Event::function_dtor); + return equeue_post(e->equeue, &Event::function_call, p); + } + + template + static void event_dtor(struct event *e) { + ((F*)(e + 1))->~F(); + } + + // Function attributes + template + static void function_call(void *p) { + (*(F*)p)(); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + public: /** Create an event * @see Event::Event diff --git a/platform/Callback.h b/platform/Callback.h index 9d5cd56024..e39f2252da 100644 --- a/platform/Callback.h +++ b/platform/Callback.h @@ -707,24 +707,10 @@ private: // Generate operations for function object template void generate(const F &f) { - struct local { - static R call(const void *p) { - return (*(F*)p)(); - } - - static void move(void *d, const void *p) { - new (d) F(*(F*)p); - } - - static void dtor(void *p) { - ((F*)p)->~F(); - } - }; - static const ops ops = { - &local::call, - &local::move, - &local::dtor, + &Callback::function_call, + &Callback::function_move, + &Callback::function_dtor, }; MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); @@ -732,6 +718,22 @@ private: _ops = &ops; } + // Function attributes + template + static R function_call(const void *p) { + return (*(F*)p)(); + } + + template + static void function_move(void *d, const void *p) { + new (d) F(*(F*)p); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + // Wrappers for functions with context template struct method_context { @@ -1411,24 +1413,10 @@ private: // Generate operations for function object template void generate(const F &f) { - struct local { - static R call(const void *p, A0 a0) { - return (*(F*)p)(a0); - } - - static void move(void *d, const void *p) { - new (d) F(*(F*)p); - } - - static void dtor(void *p) { - ((F*)p)->~F(); - } - }; - static const ops ops = { - &local::call, - &local::move, - &local::dtor, + &Callback::function_call, + &Callback::function_move, + &Callback::function_dtor, }; MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); @@ -1436,6 +1424,22 @@ private: _ops = &ops; } + // Function attributes + template + static R function_call(const void *p, A0 a0) { + return (*(F*)p)(a0); + } + + template + static void function_move(void *d, const void *p) { + new (d) F(*(F*)p); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + // Wrappers for functions with context template struct method_context { @@ -2115,24 +2119,10 @@ private: // Generate operations for function object template void generate(const F &f) { - struct local { - static R call(const void *p, A0 a0, A1 a1) { - return (*(F*)p)(a0, a1); - } - - static void move(void *d, const void *p) { - new (d) F(*(F*)p); - } - - static void dtor(void *p) { - ((F*)p)->~F(); - } - }; - static const ops ops = { - &local::call, - &local::move, - &local::dtor, + &Callback::function_call, + &Callback::function_move, + &Callback::function_dtor, }; MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); @@ -2140,6 +2130,22 @@ private: _ops = &ops; } + // Function attributes + template + static R function_call(const void *p, A0 a0, A1 a1) { + return (*(F*)p)(a0, a1); + } + + template + static void function_move(void *d, const void *p) { + new (d) F(*(F*)p); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + // Wrappers for functions with context template struct method_context { @@ -2819,24 +2825,10 @@ private: // Generate operations for function object template void generate(const F &f) { - struct local { - static R call(const void *p, A0 a0, A1 a1, A2 a2) { - return (*(F*)p)(a0, a1, a2); - } - - static void move(void *d, const void *p) { - new (d) F(*(F*)p); - } - - static void dtor(void *p) { - ((F*)p)->~F(); - } - }; - static const ops ops = { - &local::call, - &local::move, - &local::dtor, + &Callback::function_call, + &Callback::function_move, + &Callback::function_dtor, }; MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); @@ -2844,6 +2836,22 @@ private: _ops = &ops; } + // Function attributes + template + static R function_call(const void *p, A0 a0, A1 a1, A2 a2) { + return (*(F*)p)(a0, a1, a2); + } + + template + static void function_move(void *d, const void *p) { + new (d) F(*(F*)p); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + // Wrappers for functions with context template struct method_context { @@ -3523,24 +3531,10 @@ private: // Generate operations for function object template void generate(const F &f) { - struct local { - static R call(const void *p, A0 a0, A1 a1, A2 a2, A3 a3) { - return (*(F*)p)(a0, a1, a2, a3); - } - - static void move(void *d, const void *p) { - new (d) F(*(F*)p); - } - - static void dtor(void *p) { - ((F*)p)->~F(); - } - }; - static const ops ops = { - &local::call, - &local::move, - &local::dtor, + &Callback::function_call, + &Callback::function_move, + &Callback::function_dtor, }; MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); @@ -3548,6 +3542,22 @@ private: _ops = &ops; } + // Function attributes + template + static R function_call(const void *p, A0 a0, A1 a1, A2 a2, A3 a3) { + return (*(F*)p)(a0, a1, a2, a3); + } + + template + static void function_move(void *d, const void *p) { + new (d) F(*(F*)p); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + // Wrappers for functions with context template struct method_context { @@ -4227,24 +4237,10 @@ private: // Generate operations for function object template void generate(const F &f) { - struct local { - static R call(const void *p, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { - return (*(F*)p)(a0, a1, a2, a3, a4); - } - - static void move(void *d, const void *p) { - new (d) F(*(F*)p); - } - - static void dtor(void *p) { - ((F*)p)->~F(); - } - }; - static const ops ops = { - &local::call, - &local::move, - &local::dtor, + &Callback::function_call, + &Callback::function_move, + &Callback::function_dtor, }; MBED_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F)); @@ -4252,6 +4248,22 @@ private: _ops = &ops; } + // Function attributes + template + static R function_call(const void *p, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) { + return (*(F*)p)(a0, a1, a2, a3, a4); + } + + template + static void function_move(void *d, const void *p) { + new (d) F(*(F*)p); + } + + template + static void function_dtor(void *p) { + ((F*)p)->~F(); + } + // Wrappers for functions with context template struct method_context {