Changeset 1216
- Timestamp:
- 01/31/08 13:25:59 (7 months ago)
- Files:
-
- 1.8.3/branches/devel/hdrs/intmap.h (modified) (1 diff)
- 1.8.3/branches/devel/src/cque.c (modified) (5 diffs)
- 1.8.3/branches/devel/src/intmap.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/branches/devel/hdrs/intmap.h
r1213 r1216 11 11 typedef struct intmap intmap; 12 12 13 typedef uint32_t im_key; /**< Integer map keys are 32-bit unsigned integers */ 14 /* typedef uint64_t im_key; */ 15 13 16 intmap *im_new(void); 14 17 void im_destroy(intmap *); 15 18 16 int im_count(intmap *);19 int64_t im_count(intmap *); 17 20 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);21 bool im_insert(intmap *, im_key, void *); 22 void *im_find(intmap *, im_key); 23 bool im_exists(intmap *, im_key); 24 bool im_delete(intmap *, im_key); 22 25 void im_dump_graph(intmap *, const char *); 23 26 void im_stats_header(dbref); 1.8.3/branches/devel/src/cque.c
r1213 r1216 67 67 68 68 intmap *queue_map = NULL; /**< Intmap for looking up queue entries by pid */ 69 static uint32_t top_pid = 0;69 static uint32_t top_pid = 1; 70 70 #define MAX_PID (1U << 15) 71 71 … … 262 262 uint32_t pid = top_pid; 263 263 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 264 271 while (1) { 265 272 if (pid > MAX_PID) 266 pid = 0;273 pid = 1; 267 274 if (im_exists(queue_map, pid)) 268 275 pid++; … … 287 294 int a; 288 295 BQUE *tmp; 296 int pid; 289 297 if (!IsPlayer(player) && (Halted(player))) 290 298 return; 291 299 if (!pay_queue(player, command)) /* make sure player can afford to do it */ 292 300 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 } 293 307 tmp = slab_malloc(bque_slab, NULL); 294 tmp->pid = next_pid();308 tmp->pid = pid; 295 309 tmp->comm = mush_strdup(command, "bqueue_comm"); 296 310 tmp->semattr = NULL; … … 402 416 BQUE *tmp; 403 417 int a; 418 int pid; 404 419 if (waittill == 0) { 405 420 if (sem != NOTHING) … … 410 425 if (!pay_queue(player, command)) /* make sure player can afford to do it */ 411 426 return; 427 pid = next_pid(); 428 if (pid == 0) { 429 notify(player, T("Queue entry table full. Try again later.")); 430 return; 431 } 412 432 tmp = slab_malloc(bque_slab, NULL); 413 433 tmp->comm = mush_strdup(command, "bqueue_comm"); 414 tmp->pid = next_pid();434 tmp->pid = pid; 415 435 tmp->player = player; 416 436 tmp->queued = QUEUE_PER_OWNER ? Owner(player) : player; 1.8.3/branches/devel/src/intmap.c
r1213 r1216 61 61 /** Structure that represents a node in a patricia tree. */ 62 62 typedef struct patricia { 63 uint32_tkey; /**< Key value */63 im_key key; /**< Key value */ 64 64 int bit; /**< Which bit to test in this node */ 65 65 void *data; /**< Pointer to data */ … … 69 69 /** Integer map struct */ 70 70 struct intmap { 71 int count; /**< Number of elements in tree */71 int64_t count; /**< Number of elements in tree */ 72 72 patricia *root; /**< pointer to root of tree */ 73 73 }; 74 74 75 75 #define MAX_BIT 31 76 /* #define MAX_BIT 63 */ 76 77 77 78 slab *intmap_slab = NULL; /**< Allocator for patricia nodes */ 78 79 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). */ 82 int64_t 81 83 im_count(intmap * im) 82 84 { … … 139 141 /* Returns the node matching the key or its prefix */ 140 142 static patricia * 141 pat_search(patricia * node, uint32_tkey, int bit)143 pat_search(patricia * node, im_key key, int bit) 142 144 { 143 145 assert(node); … … 155 157 */ 156 158 void * 157 im_find(intmap * im, uint32_tkey)159 im_find(intmap * im, im_key key) 158 160 { 159 161 patricia *node; … … 176 178 */ 177 179 bool 178 im_exists(intmap * im, uint32_tkey)180 im_exists(intmap * im, im_key key) 179 181 { 180 182 patricia *node; … … 193 195 */ 194 196 bool 195 im_insert(intmap * im, uint32_tkey, void *data)197 im_insert(intmap * im, im_key key, void *data) 196 198 { 197 199 patricia *here, *newnode, *prev = NULL; … … 268 270 */ 269 271 bool 270 im_delete(intmap * im, uint32_tkey)272 im_delete(intmap * im, im_key key) 271 273 { 272 274 patricia *parent = NULL, *firstparent = NULL, *grandparent = NULL; … … 473 475 im_stats(dbref player, intmap * im, const char *name) 474 476 { 475 notify_format(player, "%-11s %7 d %7u", name, im->count,477 notify_format(player, "%-11s %7lld %7u", name, im->count, 476 478 (unsigned int) (sizeof(*im) + (sizeof(patricia) * im->count))); 477 479 }
