Skip to content

Commit 9df46e7

Browse files
Merge pull request #28 from andreiavrammsd/stream-order
Stream order
2 parents a12ef2c + f8daa14 commit 9df46e7

16 files changed

+103
-73
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(cpp_channel)
3-
set(PROJECT_VERSION 0.7.3)
3+
set(PROJECT_VERSION 0.8.0)
44

55
set(CMAKE_CXX_STANDARD 11)
66
set(CMAKE_CXX_STANDARD_REQUIRED YES)

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
### Thread-safe container for sharing data between threads. Header-only.
66

77
* Thread-safe push and fetch.
8-
* Use stream operators to push (>>) and fetch (<<) items.
8+
* Use stream operators to push (<<) and fetch (>>) items.
99
* Blocking (forever waiting to fetch).
1010
* Range-based for loop supported.
1111
* Close to prevent pushing and stop waiting to fetch.
1212
* Integrates well with STL algorithms. Eg: std::move(ch.begin(), ch.end(), ...).
13-
* Tested with GCC and Clang.
13+
* Tested with GCC, Clang, and MSVC.
1414

1515
## Requirements
1616

@@ -36,10 +36,10 @@ int main() {
3636
int out = 0;
3737

3838
// Send to channel
39-
in >> chan;
39+
chan << in;
4040

4141
// Read from channel
42-
out << chan;
42+
chan >> out;
4343

4444
assert(out == 1);
4545
}
@@ -51,12 +51,10 @@ int main() {
5151
int main() {
5252
msd::channel<int> chan{2}; // buffered
5353

54-
int in = 1;
55-
5654
// Send to channel
57-
in >> chan;
58-
in >> chan;
59-
in >> chan; // blocking because capacity is 2 (and no one reads from channel)
55+
chan << 1;
56+
chan << 2;
57+
chan << 3; // blocking because capacity is 2 (and no one reads from channel)
6058
}
6159
```
6260

@@ -70,13 +68,13 @@ int main() {
7068
int out = 0;
7169

7270
// Send to channel
73-
in >> chan;
74-
in >> chan;
71+
chan << in;
72+
chan << in;
7573

7674
// Read from channel
77-
out << chan;
78-
out << chan;
79-
out << chan; // blocking because channel is empty (and no one writes on it)
75+
chan >> out;
76+
chan >> out;
77+
chan >> out; // blocking because channel is empty (and no one writes on it)
8078
}
8179
```
8280

@@ -89,12 +87,11 @@ int main() {
8987
msd::channel<int> chan;
9088

9189
int in1 = 1;
92-
in1 >> chan;
93-
9490
int in2 = 2;
95-
in2 >> chan;
9691

97-
for (const auto out : chan) { // blocking: forever waiting for channel items
92+
chan << in1 << in2;
93+
94+
for (const auto out : chan) { // blocking: forever waiting for channel items
9895
std::cout << out << '\n';
9996
}
10097
}

examples/basic.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ int main()
99
int in{};
1010

1111
in = 1;
12-
in >> ch;
12+
ch << in;
1313

1414
in = 2;
15-
in >> ch;
15+
ch << in;
1616

1717
in = 3;
18-
in >> ch;
18+
ch << in;
1919

2020
for (auto out : ch) {
2121
std::cout << out << '\n';

examples/close.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main()
1717
break;
1818
}
1919

20-
++i >> ch;
20+
ch << ++i;
2121
std::cout << "in: " << i << "\n";
2222

2323
std::this_thread::sleep_for(std::chrono::milliseconds{ms});

examples/cmake-project/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ target_link_libraries(cmake_project)
1414

1515
include(FetchContent)
1616
if (NOT channel_POPULATED)
17-
FetchContent_Declare(channel URL https://github.com/andreiavrammsd/cpp-channel/archive/v0.7.3.zip)
17+
FetchContent_Declare(channel URL https://github.com/andreiavrammsd/cpp-channel/archive/v0.8.0.zip)
1818
FetchContent_Populate(channel)
1919
include_directories(${channel_SOURCE_DIR}/include)
2020
# OR

examples/cmake-project/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ CMAKE=cmake
44

55
build:
66
$(CMAKE) -B $(BUILD_PATH) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
7-
$(CMAKE) --build $(BUILD_PATH) --target cmake-project -- -j
7+
$(CMAKE) --build $(BUILD_PATH) --target cmake_project -- -j
88

99
run:
10-
$(BUILD_PATH)/cmake-project
10+
$(BUILD_PATH)/cmake_project
1111

1212
release:
1313
make BUILD_TYPE=release

examples/cmake-project/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ using chan = msd::channel<int>;
1111
{
1212
while (true) {
1313
static int i = 0;
14-
++i >> incoming;
14+
incoming << ++i;
1515
}
1616
}
1717

@@ -27,7 +27,7 @@ void Transform(chan& incoming, chan& outgoing)
2727
{
2828
for (auto in : incoming) {
2929
auto result = Add(in, 2);
30-
result >> outgoing;
30+
outgoing << result;
3131
}
3232
}
3333

examples/move.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ int main()
4141
msd::channel<Data> ch{10};
4242

4343
auto in1 = Data{1};
44-
in1 >> ch;
44+
ch << in1;
4545

46-
Data{2} >> ch;
46+
ch << Data{2};
4747

4848
auto in3 = Data{3};
49-
std::move(in3) >> ch;
49+
ch << std::move(in3);
5050

5151
for (auto out : ch) {
5252
std::cout << out.getI() << '\n';

examples/multithreading.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ int main()
2929
const auto in = [](msd::channel<std::int64_t>& ch) {
3030
while (true) {
3131
static std::int64_t i = 0;
32-
++i >> ch;
32+
ch << ++i;
3333
}
3434
};
3535

examples/streaming.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int main()
2323
}
2424

2525
++i;
26-
std::string{std::to_string(i) + " from: " + std::to_string(thread)} >> ch;
26+
ch << std::string{std::to_string(i) + " from: " + std::to_string(thread)};
2727

2828
std::this_thread::sleep_for(pause);
2929
}

0 commit comments

Comments
 (0)