File: taskmessage.h

package info (click to toggle)
wsclean 3.6-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,296 kB
  • sloc: cpp: 129,246; python: 22,066; sh: 360; ansic: 230; makefile: 185
file content (52 lines) | stat: -rw-r--r-- 1,419 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef TASK_MESSAGE_H
#define TASK_MESSAGE_H

#include <aocommon/io/serialistream.h>
#include <aocommon/io/serialostream.h>

namespace wsclean {

struct TaskMessage {
  enum class Type {
    kInvalid,
    /**
     * A 'kStart' message corresponds to a GriddingTaskManager::Start() call.
     * The main node sends it to all workers before sending Predict tasks, so
     * the workers can initialize their (local) writer locks.
     */
    kStart,
    /**
     * Using a 'kFinish' message, the main node signals the workers that all
     * work is done and the workers can exit.
     */
    kFinish,
    /** Message from the main node to a worker, containing a gridding task. */
    kGriddingRequest,
    /**
     * Message from a worker to the main node, containing the result of a
     * gridding task.
     */
    kGriddingResult,
  } type;
  union {
    size_t n_writer_groups;  // For kStart type.
    size_t body_size;        // For kGridding* types.
  };

  TaskMessage() : type(Type::kInvalid), body_size(0) {}
  TaskMessage(Type type_, size_t payload) : type(type_), body_size(payload) {}

  constexpr static size_t kSerializedSize = 12;

  void Serialize(aocommon::SerialOStream& stream) const {
    stream.UInt32(static_cast<std::uint32_t>(type)).UInt64(body_size);
  }

  void Unserialize(aocommon::SerialIStream& stream) {
    stream.UInt32(type).UInt64(body_size);
  }
};

}  // namespace wsclean

#endif