Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
source/EventQueue/detail/Thunk.impl.h@0:1c7da5f83647, 2016-11-29 (annotated)
- Committer:
- sarahmarshy
- Date:
- Tue Nov 29 06:29:10 2016 +0000
- Revision:
- 0:1c7da5f83647
Initial commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| sarahmarshy | 0:1c7da5f83647 | 1 | /* |
| sarahmarshy | 0:1c7da5f83647 | 2 | * Copyright (c) 2016, ARM Limited, All Rights Reserved |
| sarahmarshy | 0:1c7da5f83647 | 3 | * SPDX-License-Identifier: Apache-2.0 |
| sarahmarshy | 0:1c7da5f83647 | 4 | * |
| sarahmarshy | 0:1c7da5f83647 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| sarahmarshy | 0:1c7da5f83647 | 6 | * not use this file except in compliance with the License. |
| sarahmarshy | 0:1c7da5f83647 | 7 | * You may obtain a copy of the License at |
| sarahmarshy | 0:1c7da5f83647 | 8 | * |
| sarahmarshy | 0:1c7da5f83647 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| sarahmarshy | 0:1c7da5f83647 | 10 | * |
| sarahmarshy | 0:1c7da5f83647 | 11 | * Unless required by applicable law or agreed to in writing, software |
| sarahmarshy | 0:1c7da5f83647 | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| sarahmarshy | 0:1c7da5f83647 | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| sarahmarshy | 0:1c7da5f83647 | 14 | * See the License for the specific language governing permissions and |
| sarahmarshy | 0:1c7da5f83647 | 15 | * limitations under the License. |
| sarahmarshy | 0:1c7da5f83647 | 16 | */ |
| sarahmarshy | 0:1c7da5f83647 | 17 | #ifndef EVENTQUEUE_DETAIL_THUNK_IMPL_H_ |
| sarahmarshy | 0:1c7da5f83647 | 18 | #define EVENTQUEUE_DETAIL_THUNK_IMPL_H_ |
| sarahmarshy | 0:1c7da5f83647 | 19 | |
| sarahmarshy | 0:1c7da5f83647 | 20 | #include <new> |
| sarahmarshy | 0:1c7da5f83647 | 21 | #include "ThunkVTableGenerator.h" |
| sarahmarshy | 0:1c7da5f83647 | 22 | |
| sarahmarshy | 0:1c7da5f83647 | 23 | namespace eq { |
| sarahmarshy | 0:1c7da5f83647 | 24 | |
| sarahmarshy | 0:1c7da5f83647 | 25 | /** |
| sarahmarshy | 0:1c7da5f83647 | 26 | * Thunk constructor Implementation. |
| sarahmarshy | 0:1c7da5f83647 | 27 | * Due to the way templates and forwarding work in C++, it was not possible to |
| sarahmarshy | 0:1c7da5f83647 | 28 | * provide this implementation in Thunk.h |
| sarahmarshy | 0:1c7da5f83647 | 29 | */ |
| sarahmarshy | 0:1c7da5f83647 | 30 | template<typename F> |
| sarahmarshy | 0:1c7da5f83647 | 31 | Thunk::Thunk(const F& f) : |
| sarahmarshy | 0:1c7da5f83647 | 32 | _storage(), |
| sarahmarshy | 0:1c7da5f83647 | 33 | _vtable(&detail::ThunkVTableGenerator<F>::vtable) { |
| sarahmarshy | 0:1c7da5f83647 | 34 | typedef __attribute__((unused)) char F_is_too_big_for_the_Thunk[sizeof(F) <= sizeof(_storage) ? 1 : -1]; |
| sarahmarshy | 0:1c7da5f83647 | 35 | new(_storage.get_storage(0)) F(f); |
| sarahmarshy | 0:1c7da5f83647 | 36 | } |
| sarahmarshy | 0:1c7da5f83647 | 37 | |
| sarahmarshy | 0:1c7da5f83647 | 38 | /** |
| sarahmarshy | 0:1c7da5f83647 | 39 | * Specialization for function pointers. |
| sarahmarshy | 0:1c7da5f83647 | 40 | * This overload will be chosen when the tyope in input is a reference to a function. |
| sarahmarshy | 0:1c7da5f83647 | 41 | * @param f The function to transform in Thunk. |
| sarahmarshy | 0:1c7da5f83647 | 42 | */ |
| sarahmarshy | 0:1c7da5f83647 | 43 | inline Thunk::Thunk(void (*f)()) : |
| sarahmarshy | 0:1c7da5f83647 | 44 | _storage(), |
| sarahmarshy | 0:1c7da5f83647 | 45 | _vtable(&detail::ThunkVTableGenerator<void(*)()>::vtable) { |
| sarahmarshy | 0:1c7da5f83647 | 46 | typedef void(*F)(); |
| sarahmarshy | 0:1c7da5f83647 | 47 | typedef __attribute__((unused)) char F_is_too_big_for_the_Thunk[sizeof(F) <= sizeof(_storage) ? 1 : -1]; |
| sarahmarshy | 0:1c7da5f83647 | 48 | new(_storage.get_storage(0)) F(f); |
| sarahmarshy | 0:1c7da5f83647 | 49 | } |
| sarahmarshy | 0:1c7da5f83647 | 50 | |
| sarahmarshy | 0:1c7da5f83647 | 51 | /** |
| sarahmarshy | 0:1c7da5f83647 | 52 | * Thunk empty constructor Implementation. |
| sarahmarshy | 0:1c7da5f83647 | 53 | * Due to the way templates and forwarding work in C++, it was not possible to |
| sarahmarshy | 0:1c7da5f83647 | 54 | * provide this implementation in Thunk.h |
| sarahmarshy | 0:1c7da5f83647 | 55 | */ |
| sarahmarshy | 0:1c7da5f83647 | 56 | inline Thunk::Thunk() : |
| sarahmarshy | 0:1c7da5f83647 | 57 | _storage(), |
| sarahmarshy | 0:1c7da5f83647 | 58 | _vtable(&detail::ThunkVTableGenerator<void(*)()>::vtable) { |
| sarahmarshy | 0:1c7da5f83647 | 59 | typedef void(*F)(); |
| sarahmarshy | 0:1c7da5f83647 | 60 | typedef __attribute__((unused)) char F_is_too_big_for_the_Thunk[sizeof(F) <= sizeof(_storage) ? 1 : -1]; |
| sarahmarshy | 0:1c7da5f83647 | 61 | new(_storage.get_storage(0)) F(empty_thunk); |
| sarahmarshy | 0:1c7da5f83647 | 62 | } |
| sarahmarshy | 0:1c7da5f83647 | 63 | |
| sarahmarshy | 0:1c7da5f83647 | 64 | } // namespace eq |
| sarahmarshy | 0:1c7da5f83647 | 65 | |
| sarahmarshy | 0:1c7da5f83647 | 66 | #endif /* EVENTQUEUE_DETAIL_THUNK_IMPL_H_ */ |