Skip to content

Commit

Permalink
Merge pull request #2549 from geky/thread-clarification
Browse files Browse the repository at this point in the history
Clean up confusion with deprecated constructors and callbacks in thread-spawning functions
  • Loading branch information
sg- authored Sep 9, 2016
2 parents b1aebba + 022f821 commit 3bb149c
Show file tree
Hide file tree
Showing 4 changed files with 1,424 additions and 222 deletions.
306 changes: 226 additions & 80 deletions TESTS/mbed_functional/callback/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,108 +8,230 @@ using namespace utest::v1;

// static functions
template <typename T>
T static_func0() { return 0; }
T static_func0()
{ return 0; }
template <typename T>
T static_func1(T a0) { return 0 | a0; }
T static_func1(T a0)
{ return 0 | a0; }
template <typename T>
T static_func2(T a0, T a1) { return 0 | a0 | a1; }
T static_func2(T a0, T a1)
{ return 0 | a0 | a1; }
template <typename T>
T static_func3(T a0, T a1, T a2) { return 0 | a0 | a1 | a2; }
T static_func3(T a0, T a1, T a2)
{ return 0 | a0 | a1 | a2; }
template <typename T>
T static_func4(T a0, T a1, T a2, T a3) { return 0 | a0 | a1 | a2 | a3; }
T static_func4(T a0, T a1, T a2, T a3)
{ return 0 | a0 | a1 | a2 | a3; }
template <typename T>
T static_func5(T a0, T a1, T a2, T a3, T a4) { return 0 | a0 | a1 | a2 | a3 | a4; }
T static_func5(T a0, T a1, T a2, T a3, T a4)
{ return 0 | a0 | a1 | a2 | a3 | a4; }

// class functions
template <typename T>
struct Thing {
T t;
Thing() : t(0x80) {}

T member_func0() { return t; }
T member_func1(T a0) { return t | a0; }
T member_func2(T a0, T a1) { return t | a0 | a1; }
T member_func3(T a0, T a1, T a2) { return t | a0 | a1 | a2; }
T member_func4(T a0, T a1, T a2, T a3) { return t | a0 | a1 | a2 | a3; }
T member_func5(T a0, T a1, T a2, T a3, T a4) { return t | a0 | a1 | a2 | a3 | a4; }

T const_member_func0() const { return t; }
T const_member_func1(T a0) const { return t | a0; }
T const_member_func2(T a0, T a1) const { return t | a0 | a1; }
T const_member_func3(T a0, T a1, T a2) const { return t | a0 | a1 | a2; }
T const_member_func4(T a0, T a1, T a2, T a3) const { return t | a0 | a1 | a2 | a3; }
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const { return t | a0 | a1 | a2 | a3 | a4; }

T volatile_member_func0() volatile { return t; }
T volatile_member_func1(T a0) volatile { return t | a0; }
T volatile_member_func2(T a0, T a1) volatile { return t | a0 | a1; }
T volatile_member_func3(T a0, T a1, T a2) volatile { return t | a0 | a1 | a2; }
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile { return t | a0 | a1 | a2 | a3; }
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile { return t | a0 | a1 | a2 | a3 | a4; }

T const_volatile_member_func0() const volatile { return t; }
T const_volatile_member_func1(T a0) const volatile { return t | a0; }
T const_volatile_member_func2(T a0, T a1) const volatile { return t | a0 | a1; }
T const_volatile_member_func3(T a0, T a1, T a2) const volatile { return t | a0 | a1 | a2; }
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile { return t | a0 | a1 | a2 | a3; }
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile { return t | a0 | a1 | a2 | a3 | a4; }
T member_func0()
{ return t; }
T member_func1(T a0)
{ return t | a0; }
T member_func2(T a0, T a1)
{ return t | a0 | a1; }
T member_func3(T a0, T a1, T a2)
{ return t | a0 | a1 | a2; }
T member_func4(T a0, T a1, T a2, T a3)
{ return t | a0 | a1 | a2 | a3; }
T member_func5(T a0, T a1, T a2, T a3, T a4)
{ return t | a0 | a1 | a2 | a3 | a4; }

T const_member_func0() const
{ return t; }
T const_member_func1(T a0) const
{ return t | a0; }
T const_member_func2(T a0, T a1) const
{ return t | a0 | a1; }
T const_member_func3(T a0, T a1, T a2) const
{ return t | a0 | a1 | a2; }
T const_member_func4(T a0, T a1, T a2, T a3) const
{ return t | a0 | a1 | a2 | a3; }
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const
{ return t | a0 | a1 | a2 | a3 | a4; }

T volatile_member_func0() volatile
{ return t; }
T volatile_member_func1(T a0) volatile
{ return t | a0; }
T volatile_member_func2(T a0, T a1) volatile
{ return t | a0 | a1; }
T volatile_member_func3(T a0, T a1, T a2) volatile
{ return t | a0 | a1 | a2; }
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile
{ return t | a0 | a1 | a2 | a3; }
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile
{ return t | a0 | a1 | a2 | a3 | a4; }

T const_volatile_member_func0() const volatile
{ return t; }
T const_volatile_member_func1(T a0) const volatile
{ return t | a0; }
T const_volatile_member_func2(T a0, T a1) const volatile
{ return t | a0 | a1; }
T const_volatile_member_func3(T a0, T a1, T a2) const volatile
{ return t | a0 | a1 | a2; }
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile
{ return t | a0 | a1 | a2 | a3; }
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile
{ return t | a0 | a1 | a2 | a3 | a4; }
};

// bound functions
template <typename T>
T bound_func0(Thing<T> *t) { return t->t; }
T bound_func0(Thing<T> *t)
{ return t->t; }
template <typename T>
T bound_func1(Thing<T> *t, T a0) { return t->t | a0; }
T bound_func1(Thing<T> *t, T a0)
{ return t->t | a0; }
template <typename T>
T bound_func2(Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
T bound_func2(Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; }
template <typename T>
T bound_func3(Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
T bound_func3(Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; }
template <typename T>
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }

// const bound functions
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T const_func0(const Thing<T> *t) { return t->t; }
T const_bound_func0(const Thing<T> *t)
{ return t->t; }
template <typename T>
T const_func1(const Thing<T> *t, T a0) { return t->t | a0; }
T const_bound_func1(const Thing<T> *t, T a0)
{ return t->t | a0; }
template <typename T>
T const_func2(const Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
T const_bound_func2(const Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; }
template <typename T>
T const_func3(const Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
T const_bound_func3(const Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; }
template <typename T>
T const_func4(const Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
T const_bound_func4(const Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T const_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }

// volatile bound functions
T const_bound_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T volatile_bound_func0(volatile Thing<T> *t)
{ return t->t; }
template <typename T>
T volatile_bound_func1(volatile Thing<T> *t, T a0)
{ return t->t | a0; }
template <typename T>
T volatile_bound_func2(volatile Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; }
template <typename T>
T volatile_bound_func3(volatile Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; }
template <typename T>
T volatile_bound_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T volatile_func0(volatile Thing<T> *t) { return t->t; }
T volatile_bound_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T volatile_func1(volatile Thing<T> *t, T a0) { return t->t | a0; }
T const_volatile_bound_func0(const volatile Thing<T> *t)
{ return t->t; }
template <typename T>
T volatile_func2(volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
T const_volatile_bound_func1(const volatile Thing<T> *t, T a0)
{ return t->t | a0; }
template <typename T>
T volatile_func3(volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
T const_volatile_bound_func2(const volatile Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; }
template <typename T>
T volatile_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
T const_volatile_bound_func3(const volatile Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; }
template <typename T>
T volatile_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
T const_volatile_bound_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; }
template <typename T>
T const_volatile_bound_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; }

// const volatile bound functions
// void functions
template <typename T>
T void_func0(void *t)
{ return static_cast<Thing<T>*>(t)->t; }
template <typename T>
T void_func1(void *t, T a0)
{ return static_cast<Thing<T>*>(t)->t | a0; }
template <typename T>
T void_func2(void *t, T a0, T a1)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1; }
template <typename T>
T void_func3(void *t, T a0, T a1, T a2)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2; }
template <typename T>
T void_func4(void *t, T a0, T a1, T a2, T a3)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3; }
template <typename T>
T void_func5(void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T const_void_func0(const void *t)
{ return static_cast<const Thing<T>*>(t)->t; }
template <typename T>
T const_void_func1(const void *t, T a0)
{ return static_cast<const Thing<T>*>(t)->t | a0; }
template <typename T>
T const_void_func2(const void *t, T a0, T a1)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1; }
template <typename T>
T const_void_func3(const void *t, T a0, T a1, T a2)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2; }
template <typename T>
T const_void_func4(const void *t, T a0, T a1, T a2, T a3)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3; }
template <typename T>
T const_void_func5(const void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T volatile_void_func0(volatile void *t)
{ return static_cast<volatile Thing<T>*>(t)->t; }
template <typename T>
T volatile_void_func1(volatile void *t, T a0)
{ return static_cast<volatile Thing<T>*>(t)->t | a0; }
template <typename T>
T volatile_void_func2(volatile void *t, T a0, T a1)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1; }
template <typename T>
T volatile_void_func3(volatile void *t, T a0, T a1, T a2)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2; }
template <typename T>
T volatile_void_func4(volatile void *t, T a0, T a1, T a2, T a3)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; }
template <typename T>
T volatile_void_func5(volatile void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; }
template <typename T>
T const_volatile_func0(const volatile Thing<T> *t) { return t->t; }
T const_volatile_void_func0(const volatile void *t)
{ return static_cast<const volatile Thing<T>*>(t)->t; }
template <typename T>
T const_volatile_func1(const volatile Thing<T> *t, T a0) { return t->t | a0; }
T const_volatile_void_func1(const volatile void *t, T a0)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0; }
template <typename T>
T const_volatile_func2(const volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
T const_volatile_void_func2(const volatile void *t, T a0, T a1)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1; }
template <typename T>
T const_volatile_func3(const volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
T const_volatile_void_func3(const volatile void *t, T a0, T a1, T a2)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2; }
template <typename T>
T const_volatile_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
T const_volatile_void_func4(const volatile void *t, T a0, T a1, T a2, T a3)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; }
template <typename T>
T const_volatile_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
T const_volatile_void_func5(const volatile void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; }


// function call and result verification
Expand Down Expand Up @@ -199,9 +321,13 @@ void test_dispatch0() {
Verifier<T>::verify0((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func0);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func0);
Verifier<T>::verify0(&thing, &bound_func0<T>);
Verifier<T>::verify0((const Thing<T>*)&thing, &const_func0<T>);
Verifier<T>::verify0((volatile Thing<T>*)&thing, &volatile_func0<T>);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &const_volatile_func0<T>);
Verifier<T>::verify0((const Thing<T>*)&thing, &const_bound_func0<T>);
Verifier<T>::verify0((volatile Thing<T>*)&thing, &volatile_bound_func0<T>);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &const_volatile_bound_func0<T>);
Verifier<T>::verify0(&thing, &void_func0<T>);
Verifier<T>::verify0((const Thing<T>*)&thing, &const_void_func0<T>);
Verifier<T>::verify0((volatile Thing<T>*)&thing, &volatile_void_func0<T>);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &const_volatile_void_func0<T>);
Verifier<T>::verify0(callback(static_func0<T>));

Callback<T()> cb(static_func0);
Expand All @@ -222,9 +348,13 @@ void test_dispatch1() {
Verifier<T>::verify1((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func1);
Verifier<T>::verify1((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func1);
Verifier<T>::verify1(&thing, &bound_func1<T>);
Verifier<T>::verify1((const Thing<T>*)&thing, &const_func1<T>);
Verifier<T>::verify1((volatile Thing<T>*)&thing, &volatile_func1<T>);
Verifier<T>::verify1((const volatile Thing<T>*)&thing, &const_volatile_func1<T>);
Verifier<T>::verify1((const Thing<T>*)&thing, &const_bound_func1<T>);
Verifier<T>::verify1((volatile Thing<T>*)&thing, &volatile_bound_func1<T>);
Verifier<T>::verify1((const volatile Thing<T>*)&thing, &const_volatile_bound_func1<T>);
Verifier<T>::verify1(&thing, &void_func1<T>);
Verifier<T>::verify1((const Thing<T>*)&thing, &const_void_func1<T>);
Verifier<T>::verify1((volatile Thing<T>*)&thing, &volatile_void_func1<T>);
Verifier<T>::verify1((const volatile Thing<T>*)&thing, &const_volatile_void_func1<T>);
Verifier<T>::verify1(callback(static_func1<T>));

Callback<T(T)> cb(static_func1);
Expand All @@ -245,9 +375,13 @@ void test_dispatch2() {
Verifier<T>::verify2((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func2);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func2);
Verifier<T>::verify2(&thing, &bound_func2<T>);
Verifier<T>::verify2((const Thing<T>*)&thing, &const_func2<T>);
Verifier<T>::verify2((volatile Thing<T>*)&thing, &volatile_func2<T>);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &const_volatile_func2<T>);
Verifier<T>::verify2((const Thing<T>*)&thing, &const_bound_func2<T>);
Verifier<T>::verify2((volatile Thing<T>*)&thing, &volatile_bound_func2<T>);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &const_volatile_bound_func2<T>);
Verifier<T>::verify2(&thing, &void_func2<T>);
Verifier<T>::verify2((const Thing<T>*)&thing, &const_void_func2<T>);
Verifier<T>::verify2((volatile Thing<T>*)&thing, &volatile_void_func2<T>);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &const_volatile_void_func2<T>);
Verifier<T>::verify2(callback(static_func2<T>));

Callback<T(T, T)> cb(static_func2);
Expand All @@ -268,9 +402,13 @@ void test_dispatch3() {
Verifier<T>::verify3((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func3);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func3);
Verifier<T>::verify3(&thing, &bound_func3<T>);
Verifier<T>::verify3((const Thing<T>*)&thing, &const_func3<T>);
Verifier<T>::verify3((volatile Thing<T>*)&thing, &volatile_func3<T>);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &const_volatile_func3<T>);
Verifier<T>::verify3((const Thing<T>*)&thing, &const_bound_func3<T>);
Verifier<T>::verify3((volatile Thing<T>*)&thing, &volatile_bound_func3<T>);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &const_volatile_bound_func3<T>);
Verifier<T>::verify3(&thing, &void_func3<T>);
Verifier<T>::verify3((const Thing<T>*)&thing, &const_void_func3<T>);
Verifier<T>::verify3((volatile Thing<T>*)&thing, &volatile_void_func3<T>);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &const_volatile_void_func3<T>);
Verifier<T>::verify3(callback(static_func3<T>));

Callback<T(T, T, T)> cb(static_func3);
Expand All @@ -291,9 +429,13 @@ void test_dispatch4() {
Verifier<T>::verify4((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func4);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func4);
Verifier<T>::verify4(&thing, &bound_func4<T>);
Verifier<T>::verify4((const Thing<T>*)&thing, &const_func4<T>);
Verifier<T>::verify4((volatile Thing<T>*)&thing, &volatile_func4<T>);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &const_volatile_func4<T>);
Verifier<T>::verify4((const Thing<T>*)&thing, &const_bound_func4<T>);
Verifier<T>::verify4((volatile Thing<T>*)&thing, &volatile_bound_func4<T>);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &const_volatile_bound_func4<T>);
Verifier<T>::verify4(&thing, &void_func4<T>);
Verifier<T>::verify4((const Thing<T>*)&thing, &const_void_func4<T>);
Verifier<T>::verify4((volatile Thing<T>*)&thing, &volatile_void_func4<T>);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &const_volatile_void_func4<T>);
Verifier<T>::verify4(callback(static_func4<T>));

Callback<T(T, T, T, T)> cb(static_func4);
Expand All @@ -314,9 +456,13 @@ void test_dispatch5() {
Verifier<T>::verify5((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func5);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func5);
Verifier<T>::verify5(&thing, &bound_func5<T>);
Verifier<T>::verify5((const Thing<T>*)&thing, &const_func5<T>);
Verifier<T>::verify5((volatile Thing<T>*)&thing, &volatile_func5<T>);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &const_volatile_func5<T>);
Verifier<T>::verify5((const Thing<T>*)&thing, &const_bound_func5<T>);
Verifier<T>::verify5((volatile Thing<T>*)&thing, &volatile_bound_func5<T>);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &const_volatile_bound_func5<T>);
Verifier<T>::verify5(&thing, &void_func5<T>);
Verifier<T>::verify5((const Thing<T>*)&thing, &const_void_func5<T>);
Verifier<T>::verify5((volatile Thing<T>*)&thing, &volatile_void_func5<T>);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &const_volatile_void_func5<T>);
Verifier<T>::verify5(callback(static_func5<T>));

Callback<T(T, T, T, T, T)> cb(static_func5);
Expand Down
Loading

0 comments on commit 3bb149c

Please sign in to comment.