ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.125 by root, Wed Nov 14 22:52:13 2018 UTC vs.
Revision 1.126 by root, Sat Nov 17 23:33:18 2018 UTC

81 81
82// in range excluding end 82// in range excluding end
83#define IN_RANGE_EXC(val,beg,end) \ 83#define IN_RANGE_EXC(val,beg,end) \
84 ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg)) 84 ((unsigned int)(val) - (unsigned int)(beg) < (unsigned int)(end) - (unsigned int)(beg))
85 85
86void cleanup (const char *cause, bool make_core = false); 86ecb_cold void cleanup (const char *cause, bool make_core = false);
87void fork_abort (const char *msg); 87ecb_cold void fork_abort (const char *msg);
88 88
89// rationale for using (U) not (T) is to reduce signed/unsigned issues, 89// rationale for using (U) not (T) is to reduce signed/unsigned issues,
90// as a is often a constant while b is the variable. it is still a bug, though. 90// as a is often a constant while b is the variable. it is still a bug, though.
91template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; } 91template<typename T, typename U> static inline T min (T a, U b) { return a < (T)b ? a : (T)b; }
92template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; } 92template<typename T, typename U> static inline T max (T a, U b) { return a > (T)b ? a : (T)b; }
283absdir (int d) 283absdir (int d)
284{ 284{
285 return ((d - 1) & 7) + 1; 285 return ((d - 1) & 7) + 1;
286} 286}
287 287
288// avoid ctz name because netbsd or freebsd spams it's namespace with it
289#if GCC_VERSION(3,4)
290static inline int least_significant_bit (uint32_t x)
291{
292 return __builtin_ctz (x);
293}
294#else
295int least_significant_bit (uint32_t x);
296#endif
297
298#define for_all_bits_sparse_32(mask, idxvar) \ 288#define for_all_bits_sparse_32(mask, idxvar) \
299 for (uint32_t idxvar, mask_ = mask; \ 289 for (uint32_t idxvar, mask_ = mask; \
300 mask_ && ((idxvar = least_significant_bit (mask_)), mask_ &= ~(1 << idxvar), 1);) 290 mask_ && ((idxvar = ecb_ctz32 (mask_)), mask_ &= ~(1 << idxvar), 1);)
301 291
302extern ssize_t slice_alloc; // statistics 292extern ssize_t slice_alloc; // statistics
303 293
304void *salloc_ (int n); 294void *salloc_ (int n);
305void *salloc_ (int n, void *src); 295void *salloc_ (int n, void *src);
536 // p if not null 526 // p if not null
537 refcnt_base::refcnt_t *refcnt_ref () { return p ? &p->refcnt : &refcnt_dummy; } 527 refcnt_base::refcnt_t *refcnt_ref () { return p ? &p->refcnt : &refcnt_dummy; }
538 528
539 void refcnt_dec () 529 void refcnt_dec ()
540 { 530 {
541 if (!is_constant (p)) 531 if (!ecb_is_constant (p))
542 --*refcnt_ref (); 532 --*refcnt_ref ();
543 else if (p) 533 else if (p)
544 --p->refcnt; 534 --p->refcnt;
545 } 535 }
546 536
547 void refcnt_inc () 537 void refcnt_inc ()
548 { 538 {
549 if (!is_constant (p)) 539 if (!ecb_is_constant (p))
550 ++*refcnt_ref (); 540 ++*refcnt_ref ();
551 else if (p) 541 else if (p)
552 ++p->refcnt; 542 ++p->refcnt;
553 } 543 }
554 544
814 804
815int similar_direction (int a, int b); 805int similar_direction (int a, int b);
816 806
817// like v?sprintf, but returns a "static" buffer 807// like v?sprintf, but returns a "static" buffer
818char *vformat (const char *format, va_list ap); 808char *vformat (const char *format, va_list ap);
819char *format (const char *format, ...) attribute ((format (printf, 1, 2))); 809char *format (const char *format, ...) ecb_attribute ((format (printf, 1, 2)));
820 810
821// safety-check player input which will become object->msg 811// safety-check player input which will become object->msg
822bool msg_is_safe (const char *msg); 812bool msg_is_safe (const char *msg);
823 813
824///////////////////////////////////////////////////////////////////////////// 814/////////////////////////////////////////////////////////////////////////////

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines