PennMUSH Community

Changeset 1216

Show
Ignore:
Timestamp:
01/31/08 13:25:59 (7 months ago)
Author:
shawnw
Message:

Added upper limit to number of concurrent queue entries; fix return type of im_count() to avoid overflow

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/hdrs/intmap.h

    r1213 r1216  
    1111typedef struct intmap intmap; 
    1212 
     13typedef uint32_t im_key; /**< Integer map keys are 32-bit unsigned integers */ 
     14/* typedef uint64_t im_key; */ 
     15 
    1316intmap *im_new(void); 
    1417void im_destroy(intmap *); 
    1518 
    16 int im_count(intmap *); 
     19int64_t im_count(intmap *); 
    1720 
    18 bool im_insert(intmap *, uint32_t, void *); 
    19 void *im_find(intmap *, uint32_t); 
    20 bool im_exists(intmap *, uint32_t); 
    21 bool im_delete(intmap *, uint32_t); 
     21bool im_insert(intmap *, im_key, void *); 
     22void *im_find(intmap *, im_key); 
     23bool im_exists(intmap *, im_key); 
     24bool im_delete(intmap *, im_key); 
    2225void im_dump_graph(intmap *, const char *); 
    2326void im_stats_header(dbref); 
  • 1.8.3/branches/devel/src/cque.c

    r1213 r1216  
    6767 
    6868intmap *queue_map = NULL; /**< Intmap for looking up queue entries by pid */ 
    69 static uint32_t top_pid = 0
     69static uint32_t top_pid = 1
    7070#define MAX_PID (1U << 15) 
    7171 
     
    262262  uint32_t pid = top_pid; 
    263263 
     264  if (im_count(queue_map) >= (int)MAX_PID) { 
     265    do_rawlog(LT_ERR, 
     266              T("There are %d queue entries! That's too many. Failing to add another."), 
     267              im_count(queue_map)); 
     268    return 0; 
     269  } 
     270 
    264271  while (1) { 
    265272    if (pid > MAX_PID) 
    266       pid = 0
     273      pid = 1
    267274    if (im_exists(queue_map, pid)) 
    268275      pid++; 
     
    287294  int a; 
    288295  BQUE *tmp; 
     296  int pid; 
    289297  if (!IsPlayer(player) && (Halted(player))) 
    290298    return; 
    291299  if (!pay_queue(player, command))      /* make sure player can afford to do it */ 
    292300    return; 
     301  pid = next_pid(); 
     302  if (pid == 0) { 
     303    /* Too many queue entries */ 
     304    notify(player, T("Queue entry table full. Try again later.")); 
     305    return; 
     306  } 
    293307  tmp = slab_malloc(bque_slab, NULL); 
    294   tmp->pid = next_pid()
     308  tmp->pid = pid
    295309  tmp->comm = mush_strdup(command, "bqueue_comm"); 
    296310  tmp->semattr = NULL; 
     
    402416  BQUE *tmp; 
    403417  int a; 
     418  int pid; 
    404419  if (waittill == 0) { 
    405420    if (sem != NOTHING) 
     
    410425  if (!pay_queue(player, command))      /* make sure player can afford to do it */ 
    411426    return; 
     427  pid = next_pid(); 
     428  if (pid == 0) { 
     429    notify(player, T("Queue entry table full. Try again later.")); 
     430    return; 
     431  } 
    412432  tmp = slab_malloc(bque_slab, NULL); 
    413433  tmp->comm = mush_strdup(command, "bqueue_comm"); 
    414   tmp->pid = next_pid()
     434  tmp->pid = pid
    415435  tmp->player = player; 
    416436  tmp->queued = QUEUE_PER_OWNER ? Owner(player) : player; 
  • 1.8.3/branches/devel/src/intmap.c

    r1213 r1216  
    6161/** Structure that represents a node in a patricia tree. */ 
    6262typedef struct patricia { 
    63   uint32_t key; /**< Key value */ 
     63  im_key key; /**< Key value */ 
    6464  int bit; /**< Which bit to test in this node */ 
    6565  void *data; /**< Pointer to data */ 
     
    6969/** Integer map struct */ 
    7070struct intmap { 
    71   int count; /**< Number of elements in tree */ 
     71  int64_t count; /**< Number of elements in tree */ 
    7272  patricia *root; /**< pointer to root of tree */ 
    7373}; 
    7474 
    7575#define MAX_BIT 31 
     76/* #define MAX_BIT 63 */ 
    7677 
    7778slab *intmap_slab = NULL; /**< Allocator for patricia nodes */ 
    7879 
    79 /** Return the number of elements in an integer map. */ 
    80 int 
     80/** Return the number of elements in an integer map, or -1 on error 
     81    (Passing a NULL pointer instead of a map). */ 
     82int64_t 
    8183im_count(intmap * im) 
    8284{ 
     
    139141/* Returns the node matching the key or its prefix */ 
    140142static patricia * 
    141 pat_search(patricia * node, uint32_t key, int bit) 
     143pat_search(patricia * node, im_key key, int bit) 
    142144{ 
    143145  assert(node); 
     
    155157 */ 
    156158void * 
    157 im_find(intmap * im, uint32_t key) 
     159im_find(intmap * im, im_key key) 
    158160{ 
    159161  patricia *node; 
     
    176178 */ 
    177179bool 
    178 im_exists(intmap * im, uint32_t key) 
     180im_exists(intmap * im, im_key key) 
    179181{ 
    180182  patricia *node; 
     
    193195 */ 
    194196bool 
    195 im_insert(intmap * im, uint32_t key, void *data) 
     197im_insert(intmap * im, im_key key, void *data) 
    196198{ 
    197199  patricia *here, *newnode, *prev = NULL; 
     
    268270 */ 
    269271bool 
    270 im_delete(intmap * im, uint32_t key) 
     272im_delete(intmap * im, im_key key) 
    271273{ 
    272274  patricia *parent = NULL, *firstparent = NULL, *grandparent = NULL; 
     
    473475im_stats(dbref player, intmap * im, const char *name) 
    474476{ 
    475   notify_format(player, "%-11s %7d %7u", name, im->count, 
     477  notify_format(player, "%-11s %7lld %7u", name, im->count, 
    476478                (unsigned int) (sizeof(*im) + (sizeof(patricia) * im->count))); 
    477479}