| 1134 | } |
| 1135 | |
| 1136 | DDS::ReturnCode_t |
| 1137 | WriteDataContainer::obtain_buffer(DataSampleElement*& element, |
| 1138 | DDS::InstanceHandle_t handle) |
| 1139 | { |
| 1140 | DBG_ENTRY_LVL("WriteDataContainer","obtain_buffer", 6); |
| 1141 | |
| 1142 | remove_excess_durable(); |
| 1143 | |
| 1144 | PublicationInstance_rch instance = get_handle_instance(handle); |
| 1145 | |
| 1146 | if (!instance) { |
| 1147 | return DDS::RETCODE_BAD_PARAMETER; |
| 1148 | } |
| 1149 | |
| 1150 | ACE_NEW_MALLOC_RETURN( |
| 1151 | element, |
| 1152 | static_cast<DataSampleElement*>( |
| 1153 | sample_list_element_allocator_.malloc( |
| 1154 | sizeof(DataSampleElement))), |
| 1155 | DataSampleElement(publication_id_, |
| 1156 | this->writer_, |
| 1157 | instance), |
| 1158 | DDS::RETCODE_ERROR); |
| 1159 | |
| 1160 | // Extract the current instance queue. |
| 1161 | InstanceDataSampleList& instance_list = instance->samples_; |
| 1162 | DDS::ReturnCode_t ret = DDS::RETCODE_OK; |
| 1163 | |
| 1164 | bool set_timeout = true; |
| 1165 | MonotonicTimePoint timeout; |
| 1166 | |
| 1167 | //max_num_samples_ covers ResourceLimitsQosPolicy max_samples and |
| 1168 | //max_instances and max_instances * depth |
| 1169 | ThreadStatusManager& thread_status_manager = TheServiceParticipant->get_thread_status_manager(); |
| 1170 | while ((instance_list.size() >= max_samples_per_instance_) || |
| 1171 | ((this->max_num_samples_ > 0) && |
| 1172 | ((CORBA::Long) this->num_all_samples () >= this->max_num_samples_))) { |
| 1173 | |
| 1174 | if (this->writer_->qos_.reliability.kind == DDS::RELIABLE_RELIABILITY_QOS) { |
| 1175 | if (instance_list.size() >= history_depth_) { |
| 1176 | if (DCPS_debug_level >= 2) { |
| 1177 | ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) WriteDataContainer::obtain_buffer") |
| 1178 | ACE_TEXT(" instance %d attempting to remove") |
| 1179 | ACE_TEXT(" its oldest sample (reliable)\n"), |
| 1180 | handle)); |
| 1181 | } |
| 1182 | bool oldest_released = false; |
| 1183 | ret = remove_oldest_sample(instance_list, oldest_released); |
| 1184 | if (oldest_released) { |
| 1185 | break; |
| 1186 | } |
| 1187 | } |
| 1188 | // Reliable writers can wait |
| 1189 | if (set_timeout) { |
| 1190 | timeout = MonotonicTimePoint::now() + TimeDuration(max_blocking_time_); |
| 1191 | set_timeout = false; |
| 1192 | } |
| 1193 | if (!shutdown_ && MonotonicTimePoint::now() < timeout) { |