|
mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
|
#include <glib.h>#include <pthread.h>#include <stdint.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include "g_logger.h"#include "gen_tile.h"#include "protocol.h"#include "render_config.h"#include "request_queue.h"Functions | |
| static int | calcHashKey (struct request_queue *queue, struct item *item) |
| Compute a hash bucket index for a metatile render request item. | |
| static struct item * | lookup_item_idx (struct request_queue *queue, struct item *item) |
| Look up an existing queued or in-flight request matching (mx, my, z, xmlname). | |
| static void | insert_item_idx (struct request_queue *queue, struct item *item) |
| Insert a request item into the queue's hash table index for O(1) duplicate lookup. | |
| static void | remove_item_idx (struct request_queue *queue, struct item *item) |
| Remove a request item from the queue's hash table index. | |
| static enum protoCmd | pending (struct request_queue *queue, struct item *test) |
| Check whether a matching metatile request is already queued or being rendered. | |
| 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. | |
| void | request_queue_clear_requests_by_fd (struct request_queue *queue, int fd) |
| Invalidate all queued/rendering references to a disconnected client socket fd. | |
| 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. | |
| 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. | |
| 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. | |
| void | request_queue_copy_stats (struct request_queue *queue, stats_struct *stats) |
| Copy a thread-safe snapshot of the queue's cumulative render statistics. | |
| 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. | |
|
static |
Compute a hash bucket index for a metatile render request item.
Combines a byte-sum hash of item->req.xmlname (9 bits), zoom level z (4 bits), metatile X coordinate mx (24 bits), and metatile Y coordinate my (24 bits) into a 64-bit integer and reduces it modulo queue->hashidxSize.
| queue | Request queue containing hashidxSize. |
| item | Render request item whose style name and (mx, my, z) are hashed. |
|
static |
Insert a request item into the queue's hash table index for O(1) duplicate lookup.
Stores item directly in the inline head slot item_hashidx[key] if empty, or appends a heap-allocated struct item_idx node to the bucket's collision chain. Caller must hold queue->qLock.
| queue | Request queue owning the hash index. |
| item | Request item to index. |
|
static |
Look up an existing queued or in-flight request matching (mx, my, z, xmlname).
Caller must hold queue->qLock.
| queue | Request queue whose hash index will be searched. |
| item | Candidate request item to match against. |
|
static |
Check whether a matching metatile request is already queued or being rendered.
If an identical request is actively rendering (queueRender) or waiting in an interactive queue (queueRequest, queueRequestPrio, queueRequestLow), attaches test to the existing item's duplicates list so all waiting clients receive a response when rendering completes, and returns cmdIgnore.
If an identical request is in queueDirty or queueRequestBulk (where clients do not block on completion), returns cmdNotDone so the caller immediately releases test. Caller must hold queue->qLock.
| queue | Request queue to inspect. |
| test | Newly arrived request item to deduplicate. |
|
static |
Remove a request item from the queue's hash table index.
Handles both inline head-slot removal (promoting and freeing the first chained overflow node if present) and interior/tail chained node removal. Caller must hold queue->qLock.
| queue | Request queue owning the hash index. |
| item | Request item to remove from the index. |
| 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.
| queue | Request queue instance (must not be NULL). |
| item | Heap-allocated request item (ownership transferred to queue or freed on drop). |
| 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.)
| queue | Request queue instance. |
| fd | Client socket file descriptor that was closed or errored. |
| void request_queue_close | ( | struct request_queue * | queue | ) |
Destroy the request queue mutex and free the hash index and queue structure.
| queue | Request queue instance to tear down. |
| void request_queue_copy_stats | ( | struct request_queue * | queue, |
| stats_struct * | stats ) |
Copy a thread-safe snapshot of the queue's cumulative render statistics.
| queue | Request queue instance. |
| stats | Destination stats_struct buffer populated under queue->qLock. |
| 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:
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.
| queue | Request queue instance. |
| 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.
| 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.
| queue | Request queue instance. |
| priority | Command enum identifying the sub-queue (cmdRenderPrio, cmdRender, cmdRenderLow, cmdDirty, or cmdRenderBulk). |
| 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).
| queue | Request queue instance. |
| request | Completed request item currently on renderHead. |
| render_time | Elapsed render duration in milliseconds (recorded if > 0). |