1/**
2 * Copyright (c) 2017-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9#pragma once
10
11#include "gloo/algorithm.h"
12#include "gloo/context.h"
13#include "gloo/transport/unbound_buffer.h"
14
15namespace gloo {
16
17class Barrier : public Algorithm {
18 public:
19 explicit Barrier(const std::shared_ptr<Context>& context)
20 : Algorithm(context) {}
21
22 virtual ~Barrier(){};
23};
24
25class BarrierOptions {
26 public:
27 explicit BarrierOptions(const std::shared_ptr<Context>& context);
28
29 void setTag(uint32_t tag) {
30 this->tag = tag;
31 }
32
33 void setTimeout(std::chrono::milliseconds timeout) {
34 this->timeout = timeout;
35 }
36
37 protected:
38 std::shared_ptr<Context> context;
39 std::unique_ptr<transport::UnboundBuffer> buffer;
40
41 // Tag for this operation.
42 // Must be unique across operations executing in parallel.
43 uint32_t tag = 0;
44
45 // End-to-end timeout for this operation.
46 std::chrono::milliseconds timeout;
47
48 friend void barrier(BarrierOptions&);
49};
50
51void barrier(BarrierOptions& opts);
52
53} // namespace gloo
54