<commit_before>/*
 * Copyright (C) 1994, Index Data.
 * See the file LICENSE for details.
 * <NAME>, <NAME>
 *
 * $Log: requestq.c,v $
 * Revision 1.3  1997-09-01 08:53:00  adam
 * New windows NT/95 port using MSV5.0. The test server 'ztest' was
 * moved a separate directory. MSV5.0 project server.dsp created.
 * As an option, the server can now operate as an NT service.
 *
 * Revision 1.2  1995/11/01 13:54:57  quinn
 * Minor adjustments
 *
 * Revision 1.1  1995/05/15  12:12:22  quinn
 * Request queue.
 *
 *
 */

/*
 * Simple queue management.
 *
 * We also use the request-freelist to store encoding buffers, rather than
 * freeing and xmalloc'ing them on each cycle.
 */

#include <stdlib.h>

#include <xmalloc.h>
#include "session.h"

void request_enq(request_q *q, request *r)
{
    if (q->tail)
    	q->tail->next = r;
    else
    	q->head = r;
    q->tail = r;
    q->num++;
}

request *request_head(request_q *q)
{
    return q->head;
}

request *request_deq(request_q *q)
{
    request *r = q->head;

    if (!r)
    	return 0;
    q->head = q->head->next;
    if (!q->head)
    	q->tail = 0;
    q->num--;
    return r;
}

void request_initq(request_q *q)
{
    q->head = q->tail = q->list = 0;
    q->num = 0;
}

void request_delq(request_q *q)
{
    request *r1, *r = q->list;
    while (r)
    {
        r1 = r;
        r = r->next;
        xfree (r1);
    }
}

request *request_get(request_q *q)
{
    request *r = q->list;

    if (r)
    	q->list = r->next;
    else
    {
    	if (!(r = xmalloc(sizeof(*r))))
	    abort();
	r->response = 0;<commit_msg>Fixed memory leak: member response wasn't freed when queue was destroyed.<commit_after>/*
 * Copyright (C) 1994, Index Data.
 * See the file LICENSE for details.
 * <NAME>, <NAME>
 *
 * $Log: requestq.c,v $
 * Revision 1.4  1997-10-27 13:55:03  adam
 * Fixed memory leak: member response wasn't freed when queue
 * was destroyed.
 *
 * Revision 1.3  1997/09/01 08:53:00  adam
 * New windows NT/95 port using MSV5.0. The test server 'ztest' was
 * moved a separate directory. MSV5.0 project server.dsp created.
 * As an option, the server can now operate as an NT service.
 *
 * Revision 1.2  1995/11/01 13:54:57  quinn
 * Minor adjustments
 *
 * Revision 1.1  1995/05/15  12:12:22  quinn
 * Request queue.
 *
 *
 */

/*
 * Simple queue management.
 *
 * We also use the request-freelist to store encoding buffers, rather than
 * freeing and xmalloc'ing them on each cycle.
 */

#include <stdlib.h>

#include <xmalloc.h>
#include "session.h"

void request_enq(request_q *q, request *r)
{
    if (q->tail)
    	q->tail->next = r;
    else
    	q->head = r;
    q->tail = r;
    q->num++;
}

request *request_head(request_q *q)
{
    return q->head;
}

request *request_deq(request_q *q)
{
    request *r = q->head;

    if (!r)
    	return 0;
    q->head = q->head->next;
    if (!q->head)
    	q->tail = 0;
    q->num--;
    return r;
}

void request_initq(request_q *q)
{
    q->head = q->tail = q->list = 0;
    q->num = 0;
}

void request_delq(request_q *q)
{
    request *r1, *r = q->list;
    while (r)
    {
	xfree (r->response);
        r1 = r;
        r = r->next;
        xfree (r1);
    }
}

request *request_get(request_q *q)
{
    request *r = q->list;

    if (r)
    	q->list = r->next;
    else
    {
    	if (!(r = xmalloc(sizeof(*r))))
	    abort();
	r->response = 0;
{'fraction_non_alphanumeric': 0.1542584871947588, 'fraction_numerical': 0.044073853484216795, 'mean_word_length': 2.4066937119675456, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6841320', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1300, 'n_words': 373}