You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@mesos.apache.org by Michael Park <mc...@gmail.com> on 2015/06/14 04:20:59 UTC
Re: Review Request 35395: Improvements to the synchronized macro.
-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/35395/
-----------------------------------------------------------
(Updated June 14, 2015, 2:20 a.m.)
Review request for mesos, Benjamin Hindman and Joris Van Remoortere.
Summary (updated)
-----------------
Improvements to the synchronized macro.
Repository: mesos
Description
-------
(1) Simplify introducing new synchronization primitives.
Before:
```cpp
template <>
class Synchronized<bufferevent>
{
public:
Synchronized(bufferevent* _bev) : bev(CHECK_NOTNULL(_bev))
{
bufferevent_lock(bev);
}
Synchronized(bufferevent** _bev) : Synchronized(*CHECK_NOTNULL(_bev)) {}
~Synchronized()
{
bufferevent_unlock(bev);
}
operator bool() const { return true; }
private:
bufferevent* bev;
};
```
After:
```cpp
Synchronized<bufferevent> synchronize(bufferevent* bev) {
return {
bev,
[](bufferevent* bev) { bufferevent_lock(bev); }
[](bufferevent* bev) { bufferevent_unlock(bev); }
};
}
```
(2) Enable `return` within `synchronized` and avoid the `control reaches end of non-void function` warning.
```cpp
int foo()
{
int x = 42;
std::mutex m;
synchronized (m) {
return x;
}
}
```
Diffs
-----
3rdparty/libprocess/3rdparty/stout/include/stout/synchronized.hpp 60eaf263f220b4990aefe4e5d6d2aa1296891e57
Diff: https://reviews.apache.org/r/35395/diff/
Testing
-------
`make check`
Thanks,
Michael Park