@@ -44,7 +44,8 @@ namespace bi = boost::interprocess;
44
44
45
45
// / Struct holding the representation of a message queue inside the shared
46
46
// / memory.
47
- // / \param size Total size of the message queue.
47
+ // / \param size Total size of the message queue. Considered invalid after
48
+ // / MessageQueue::LoadFromSharedMemory. Check DLIS-8378 for additional details.
48
49
// / \param mutex Handle of the mutex variable protecting index.
49
50
// / \param index Used element index.
50
51
// / \param sem_empty Semaphore object counting the number of empty buffer slots.
@@ -118,13 +119,15 @@ class MessageQueue {
118
119
int head_idx = Head ();
119
120
// Additional check to avoid out of bounds read/write. Check DLIS-8378 for
120
121
// additional details.
121
- if (head_idx < 0 || static_cast <size_t >(head_idx) >= Size ()) {
122
- constexpr const char * error_msg =
123
- " Message queue head index out of bounds" ;
122
+ if (head_idx < 0 || static_cast <uint32_t >(head_idx) >= Size ()) {
123
+ std::string error_msg =
124
+ " internal error: message queue head index out of bounds. Expects "
125
+ " positive integer less than the size of message queue " +
126
+ std::to_string (Size ()) + " but got " + std::to_string (head_idx);
124
127
#ifdef TRITON_PB_STUB
125
128
LOG_ERROR << error_msg;
126
129
#else
127
- LOG_MESSAGE (TRITONSERVER_LOG_ERROR, error_msg);
130
+ LOG_MESSAGE (TRITONSERVER_LOG_ERROR, error_msg. c_str () );
128
131
#endif
129
132
return ;
130
133
}
@@ -166,13 +169,15 @@ class MessageQueue {
166
169
int head_idx = Head ();
167
170
// Additional check to avoid out of bounds read/write. Check DLIS-8378 for
168
171
// additional details.
169
- if (head_idx < 0 || static_cast <size_t >(head_idx) >= Size ()) {
170
- constexpr const char * error_msg =
171
- " Message queue head index out of bounds" ;
172
+ if (head_idx < 0 || static_cast <uint32_t >(head_idx) >= Size ()) {
173
+ std::string error_msg =
174
+ " internal error: message queue head index out of bounds. Expects "
175
+ " positive integer less than the size of message queue " +
176
+ std::to_string (Size ()) + " but got " + std::to_string (head_idx);
172
177
#ifdef TRITON_PB_STUB
173
178
LOG_ERROR << error_msg;
174
179
#else
175
- LOG_MESSAGE (TRITONSERVER_LOG_ERROR, error_msg);
180
+ LOG_MESSAGE (TRITONSERVER_LOG_ERROR, error_msg. c_str () );
176
181
#endif
177
182
return ;
178
183
}
@@ -275,7 +280,7 @@ class MessageQueue {
275
280
}
276
281
277
282
private:
278
- std:: size_t & Size () { return mq_shm_ptr_-> size ; }
283
+ uint32_t Size () { return size_ ; }
279
284
const bi::interprocess_mutex& Mutex () { return mq_shm_ptr_->mutex ; }
280
285
bi::interprocess_mutex* MutexMutable () { return &(mq_shm_ptr_->mutex ); }
281
286
int & Head () { return mq_shm_ptr_->head ; }
@@ -304,6 +309,7 @@ class MessageQueue {
304
309
MessageQueueShm* mq_shm_ptr_;
305
310
T* mq_buffer_shm_ptr_;
306
311
bi::managed_external_buffer::handle_t mq_handle_;
312
+ uint32_t size_;
307
313
308
314
// / Create/load a Message queue.
309
315
// / \param mq_shm Message queue representation in shared memory.
@@ -315,6 +321,7 @@ class MessageQueue {
315
321
mq_buffer_shm_ptr_ = mq_buffer_shm_.data_ .get ();
316
322
mq_shm_ptr_ = mq_shm_.data_ .get ();
317
323
mq_handle_ = mq_shm_.handle_ ;
324
+ size_ = mq_shm_ptr_->size ;
318
325
}
319
326
};
320
327
}}} // namespace triton::backend::python
0 commit comments