Skip to content

Commit 12caec4

Browse files
committedJun 9, 2022
Shared: providing set/get method as alternative for operator overloading.
1 parent 4b8865c commit 12caec4

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed
 

‎src/threading/Shared.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class Shared
4040
{
4141
public:
4242

43+
T get();
44+
void set(T const & val);
45+
4346
operator T();
4447
void operator = (T const & other);
4548
inline T peek() const { return _val; }
@@ -57,7 +60,7 @@ class Shared
5760
**************************************************************************************/
5861

5962
template<class T, size_t QUEUE_SIZE>
60-
Shared<T,QUEUE_SIZE>::operator T()
63+
T Shared<T,QUEUE_SIZE>::get()
6164
{
6265
T * val_ptr = _mailbox.try_get_for(rtos::Kernel::wait_for_u32_forever);
6366
if (val_ptr)
@@ -70,7 +73,7 @@ Shared<T,QUEUE_SIZE>::operator T()
7073
}
7174

7275
template<class T, size_t QUEUE_SIZE>
73-
void Shared<T,QUEUE_SIZE>::operator = (T const & other)
76+
void Shared<T,QUEUE_SIZE>::set(T const & val)
7477
{
7578
/* If the mailbox is full we are discarding the
7679
* oldest element and then push the new one into
@@ -92,4 +95,16 @@ void Shared<T,QUEUE_SIZE>::operator = (T const & other)
9295
}
9396
}
9497

98+
template<class T, size_t QUEUE_SIZE>
99+
Shared<T,QUEUE_SIZE>::operator T()
100+
{
101+
return get();
102+
}
103+
104+
template<class T, size_t QUEUE_SIZE>
105+
void Shared<T,QUEUE_SIZE>::operator = (T const & other)
106+
{
107+
set(other);
108+
}
109+
95110
#endif /* ARDUINO_THREADS_SHARED_HPP_ */

0 commit comments

Comments
 (0)
Please sign in to comment.