MCPcopy Create free account
hub / github.com/acl-dev/acl / push

Method push

lib_acl_cpp/include/acl_cpp/stdlib/tbox_array.hpp:87–120  ·  view source on GitHub ↗

* Send message object. This process unlocks first then notifies after adding * object * @param t {T*} Non-empty message object * @param notify_first {bool} If true, notify first then unlock, otherwise * unlock first * then notify. Note the difference between the two * @return {bool} * @override */

Source from the content-addressed store, hash-verified

85 * @override
86 */
87 bool push(T* t, bool notify_first = false) {
88 if (! lock_.lock()) { abort(); }
89
90 if (off_next_ == capacity_) {
91 if (off_curr_ >= 10000) {
92#if 1
93 size_t n = 0;
94 for (size_t i = off_curr_; i < off_next_; i++) {
95 array_[n++] = array_[i];
96 }
97#else
98 memmove(array_, array_ + off_curr_,
99 (off_next_ - off_curr_) * sizeof(T*));
100#endif
101
102 off_next_ -= off_curr_;
103 off_curr_ = 0;
104 } else {
105 capacity_ += 10000;
106 array_ = (T**) realloc(array_, sizeof(T*) * capacity_);
107 }
108 }
109 array_[off_next_++] = t;
110
111 if (notify_first) {
112 if (! cond_.notify()) { abort(); }
113 if (! lock_.unlock()) { abort(); }
114 } else {
115 if (! lock_.unlock()) { abort(); }
116 if (! cond_.notify()) { abort(); }
117 }
118
119 return true;
120 }
121
122 /**
123 * Receive message object

Callers

nothing calls this directly

Calls 4

reallocFunction · 0.85
lockMethod · 0.45
notifyMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected