@ -309,6 +309,12 @@ int queue_data_put(struct ll_queue* q, struct ll_entry* entry) {
queue_check_thread ( q ) ;
# endif
if ( entry - > prev | | entry - > next | | q - > head = = entry | | q - > tail = = entry ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " [%s] double put detected! entry=%p prev=%p next=%p len=%u " ,
q - > name , ( void * ) entry , ( void * ) entry - > prev , ( void * ) entry - > next , entry - > len ) ;
abort ( ) ;
}
if ( q - > hash_size > 0 ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " [%s] Put no-hash data to hash queue " , q - > name ) ;
queue_dgram_free ( entry ) ;
@ -350,6 +356,12 @@ int queue_data_put_with_index(struct ll_queue* q, struct ll_entry* entry) {
queue_check_thread ( q ) ;
# endif
if ( entry - > prev | | entry - > next | | q - > head = = entry | | q - > tail = = entry ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " [%s] double put_with_index detected! entry=%p prev=%p next=%p " ,
q - > name , ( void * ) entry , ( void * ) entry - > prev , ( void * ) entry - > next ) ;
abort ( ) ;
}
if ( q - > index_size = = 0 | | ( size_t ) q - > index_offset + q - > index_size > ( size_t ) entry - > size ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " [%s] invalid index: offset=%u size=%u (data_size=%u) " , q - > name , q - > index_offset , q - > index_size , entry - > size ) ;
queue_dgram_free ( entry ) ;
@ -393,6 +405,12 @@ int queue_data_put_first(struct ll_queue* q, struct ll_entry* entry) {
queue_check_thread ( q ) ;
# endif
if ( entry - > prev | | entry - > next | | q - > head = = entry | | q - > tail = = entry ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " [%s] double put_first detected! entry=%p prev=%p next=%p " ,
q - > name , ( void * ) entry , ( void * ) entry - > prev , ( void * ) entry - > next ) ;
abort ( ) ;
}
if ( q - > hash_size > 0 ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " [%s] Put no-hash data to hash queue " , q - > name ) ;
queue_dgram_free ( entry ) ;
@ -426,6 +444,12 @@ int queue_data_put_first_with_index(struct ll_queue* q, struct ll_entry* entry)
queue_check_thread ( q ) ;
# endif
if ( entry - > prev | | entry - > next | | q - > head = = entry | | q - > tail = = entry ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " [%s] double put_first_with_index detected! entry=%p prev=%p next=%p " ,
q - > name , ( void * ) entry , ( void * ) entry - > prev , ( void * ) entry - > next ) ;
abort ( ) ;
}
if ( q - > index_size = = 0 | | ( size_t ) q - > index_offset + q - > index_size > ( size_t ) entry - > size ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " [%s] invalid index: offset=%u size=%u (data_size=%u) " , q - > name , q - > index_offset , q - > index_size , entry - > size ) ;
queue_dgram_free ( entry ) ;
@ -505,14 +529,27 @@ int queue_entry_count(struct ll_queue* q) {
// Функция проверки консистентности count и total_bytes
// Возвращает 0 если ok, -1 если есть несоответствия
int queue_check_consistency ( struct ll_queue * q ) {
if ( ! q ) return - 1 ; // Недопустимая очередь
if ( ! q ) return - 1 ;
// Проверка: если count > 0, то head не должен быть NULL
if ( q - > count > 0 & & ! q - > head ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " Queue '%s': count=%d but head is NULL! " ,
q - > name ? q - > name : " unknown " , q - > count ) ;
return - 1 ;
}
// Floyd cycle detection — за O(N) без риска зависания
{
struct ll_entry * slow = q - > head , * fast = q - > head ;
while ( fast & & fast - > next ) {
slow = slow - > next ;
fast = fast - > next - > next ;
if ( slow = = fast ) {
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " Queue '%s': CYCLE detected! entry=%p count=%d " ,
q - > name ? q - > name : " unknown " , ( void * ) slow , q - > count ) ;
abort ( ) ;
}
}
}
int actual_count = 0 ;
size_t actual_bytes = 0 ;
@ -523,7 +560,6 @@ int queue_check_consistency(struct ll_queue* q) {
actual_bytes + = current - > int_len ;
if ( current - > next ) {
if ( current - > next - > prev ! = current ) {
// Несоответствие в связях prev/next
DEBUG_ERROR ( DEBUG_CATEGORY_LL_QUEUE , " Queue '%s': prev/next error at entry %p != %p entries: %d!=%d bytes: %zu!=%zu " ,
q - > name ? q - > name : " unknown " , ( void * ) current , ( void * ) current - > next - > prev , actual_count , q - > count , actual_bytes , q - > total_bytes ) ;
return - 1 ;