mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
Loading...
Searching...
No Matches
request_queue.h File Reference
#include "gen_tile.h"
#include "render_config.h"
#include <pthread.h>

Go to the source code of this file.

Classes

struct  stats_struct
 Cumulative render request counts and elapsed render durations tracked by request_queue. More...
struct  item_idx
 Hash bucket chain node mapping a metatile hash key to an active or queued struct item. More...
struct  request_queue
 Thread-safe multi-priority metatile render queue with hash-based duplicate coalescing. More...

Macros

#define HASHIDX_SIZE   2213
 Prime bucket count for the hash table indexing queued and in-flight metatile render requests.

Functions

struct request_queue * request_queue_init ()
 Allocate and initialize a new request_queue with empty circular queues and hash index.
void request_queue_close (struct request_queue *queue)
 Destroy the request queue mutex and free the hash index and queue structure.
struct item * request_queue_fetch_request (struct request_queue *queue)
 Pop the highest-priority pending request from queue and move it to the active render list.
enum protoCmd request_queue_add_request (struct request_queue *queue, struct item *request)
 Enqueue a new tile render request or coalesce it with an existing pending item.
void request_queue_remove_request (struct request_queue *queue, struct item *request, int render_time)
 Unlink a completed request from the active render list, remove it from the hash index, and record render timing statistics.
void request_queue_clear_requests_by_fd (struct request_queue *queue, int fd)
 Invalidate all queued/rendering references to a disconnected client socket fd.
int request_queue_no_requests_queued (struct request_queue *queue, enum protoCmd)
 Query the current number of pending items in a specific priority sub-queue.
void request_queue_copy_stats (struct request_queue *queue, stats_struct *stats)
 Copy a thread-safe snapshot of the queue's cumulative render statistics.

Macro Definition Documentation

◆ HASHIDX_SIZE

#define HASHIDX_SIZE   2213

Prime bucket count for the hash table indexing queued and in-flight metatile render requests.

Function Documentation

◆ request_queue_add_request()

enum protoCmd request_queue_add_request ( struct request_queue * queue,
struct item * item )

Enqueue a new tile render request or coalesce it with an existing pending item.

Deduplicates item via pending(). If unique, places item onto the queue matching item->req.cmd (reqHead, reqPrioHead, reqLowHead, or reqBulkHead) when below REQ_LIMIT, or falls back to dirtyHead (with fd = FD_INVALID) when below DIRTY_LIMIT. Drops and frees item if both limits are saturated.

Parameters
queueRequest queue instance (must not be NULL).
itemHeap-allocated request item (ownership transferred to queue or freed on drop).
Returns
cmdIgnore if queued for synchronous client notification (or coalesced as a duplicate), or cmdNotDone if relegated to dirtyHead, dropped, or already dirty/bulk.

◆ request_queue_clear_requests_by_fd()

void request_queue_clear_requests_by_fd ( struct request_queue * queue,
int fd )

Invalidate all queued/rendering references to a disconnected client socket fd.

Walks the interactive and active render queues (reqHead, renderHead, reqPrioHead, reqBulkHead, reqLowHead) plus any attached duplicates chains, setting matching fd fields to FD_INVALID so worker threads do not attempt to write responses to a closed or reused descriptor. (dirtyHead items already hold FD_INVALID.)

Parameters
queueRequest queue instance.
fdClient socket file descriptor that was closed or errored.

◆ request_queue_close()

void request_queue_close ( struct request_queue * queue)

Destroy the request queue mutex and free the hash index and queue structure.

Parameters
queueRequest queue instance to tear down.

◆ request_queue_copy_stats()

void request_queue_copy_stats ( struct request_queue * queue,
stats_struct * stats )

Copy a thread-safe snapshot of the queue's cumulative render statistics.

Parameters
queueRequest queue instance.
statsDestination stats_struct buffer populated under queue->qLock.

◆ request_queue_fetch_request()

struct item * request_queue_fetch_request ( struct request_queue * queue)

Pop the highest-priority pending request from queue and move it to the active render list.

Blocks on queue->qCond until at least one pending queue is non-empty. Dequeues in strict priority order:

  1. reqPrioHead (cmdRenderPrio)
  2. reqHead (cmdRender)
  3. reqLowHead (cmdRenderLow)
  4. dirtyHead (cmdDirty)
  5. reqBulkHead (cmdRenderBulk)

Moves the selected item onto renderHead with inQueue = queueRender while keeping it registered in the hash index so incoming duplicate requests still coalesce with it.

Parameters
queueRequest queue instance.
Returns
Pointer to the dequeued struct item now marked queueRender.

◆ request_queue_init()

struct request_queue * request_queue_init ( )

Allocate and initialize a new request_queue with empty circular queues and hash index.

Initializes qLock, qCond, all six circular doubly-linked list sentinel heads (reqHead, reqPrioHead, reqLowHead, reqBulkHead, dirtyHead, renderHead), zeroed statistics counters, and the HASHIDX_SIZE-bucket hash table.

Returns
Newly allocated struct request_queue, or NULL if memory or pthread initialization fails.

◆ request_queue_no_requests_queued()

int request_queue_no_requests_queued ( struct request_queue * queue,
enum protoCmd priority )

Query the current number of pending items in a specific priority sub-queue.

Parameters
queueRequest queue instance.
priorityCommand enum identifying the sub-queue (cmdRenderPrio, cmdRender, cmdRenderLow, cmdDirty, or cmdRenderBulk).
Returns
Current item count in the requested sub-queue, or -1 if priority is unrecognized.

◆ request_queue_remove_request()

void request_queue_remove_request ( struct request_queue * queue,
struct item * request,
int render_time )

Unlink a completed request from the active render list, remove it from the hash index, and record render timing statistics.

Does not free request itself (the caller frees request and any chained duplicates after sending responses).

Parameters
queueRequest queue instance.
requestCompleted request item currently on renderHead.
render_timeElapsed render duration in milliseconds (recorded if > 0).