UTMisc.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _UT_H_
00026 #error "DO NOT INCLUDE THIS FILE - INCLUDE UT.h INSTEAD"
00027 #endif
00028
00029
00030 EXTERN_C_BEGIN
00031
00032
00033
00034
00035
00036
00038 typedef unsigned int uint;
00039
00041 typedef unsigned char uint8;
00042
00044 typedef signed char int8;
00045
00047 typedef unsigned short int uint16;
00048
00050 typedef signed short int int16;
00051
00053 typedef unsigned int uint32;
00054
00056 typedef signed int int32;
00057
00059 typedef unsigned long long uint64;
00060
00062 typedef signed long long int64;
00063
00065 typedef uint8 byte;
00066
00068 typedef uint8 ascii7;
00069
00072 typedef uint8 utf8;
00073
00077 typedef const char stringliteral;
00078
00079 #if POINTER_IS_32_BIT
00081 typedef uint32 ptr_as_uint_t;
00082 #elif POINTER_IS_64_BIT
00083 typedef uint64 ptr_as_uint_t;
00084 #else
00085 #error "UT target platform header must define POINTER_IS_32_BIT or POINTER_IS_64_BIT"
00086 #endif
00087
00088
00089
00090
00091
00092
00093 #ifndef min
00095 #define min( a, b ) ( ( (a) < (b) ) ? (a) : (b) )
00096 #endif
00097
00098 #ifndef max
00100 #define max( a, b ) ( ( (a) > (b) ) ? (a) : (b) )
00101 #endif
00102
00103 #ifndef abs
00105 #define abs(value) ( ( (value) > 0 ) ? (value) : -(value) )
00106 #endif
00107
00109 #define div_round( numer, denom ) ( ( (numer) + (denom)/2 ) / (denom) )
00110
00112 #define div_round_up( numer, denom ) ( ( (numer) + (denom) - 1 ) / (denom) )
00113
00115 #define four_cc( a, b, c, d ) ( (a<<24) | (b<<16) | (c<<8) | (d) )
00116
00119 #define sizeof_array_element(object) (sizeof(object[2]) / 2)
00120
00121
00122
00123
00124
00125
00129 #define takes
00130
00134 #define gives
00135
00138 #define out
00139
00140
00141
00142
00143
00144
00146 #define S_IRWUSR (S_IRUSR | S_IWUSR)
00147
00149 #define S_IRWGRP (S_IRGRP | S_IWGRP)
00150
00152 #define S_IRWOTH (S_IROTH | S_IWOTH)
00153
00154
00155
00156
00157
00158
00167 #define postfix int
00168
00169
00170
00171
00172
00173
00217 extern UT_EXPORT void get_memory_info( out uint32* total_phys_kb,
00218 out uint32* total_virt_kb,
00219 out uint32* free_phys_kb,
00220 out uint32* free_virt_kb );
00221
00235 extern UT_EXPORT void get_cpu_utilization( out int* highest_of_any_one_core, out int* aggregate );
00236
00237
00238
00239
00240
00241
00245 typedef struct
00246 {
00247 uint16 year;
00248 uint8 month;
00249 uint8 day_of_week;
00250 uint8 day;
00251 uint8 hour;
00252 uint8 minute;
00253 uint8 second;
00254 uint32 microsecond;
00255 } DateTime_t;
00256
00257
00260 extern UT_EXPORT void get_date_time(out DateTime_t* date_time);
00261
00264 typedef int64 ustime_t;
00265
00268 extern UT_EXPORT ustime_t system_time_us();
00269
00273 typedef int32 mstime_t;
00274
00277 extern UT_EXPORT mstime_t system_time_ms();
00278
00283 typedef int32 roughtime_t;
00284
00289 extern UT_EXPORT roughtime_t rough_time_ms();
00290
00291
00292
00293
00294
00295
00304 extern UT_EXPORT int32 atomic_add( volatile int32* value_pointer, int32 add );
00305
00315 extern UT_EXPORT bool atomic_add_if_greater( volatile int32* value_pointer,
00316 int32 add_value,
00317 int32 if_greater_than );
00318
00326 extern UT_EXPORT bool atomic_add_if_less( volatile int32* value_pointer,
00327 int32 add_value,
00328 int32 if_less_than );
00329
00330
00331
00332
00333
00334
00337 extern UT_EXPORT int seeded_rand15();
00338
00339
00343 extern UT_EXPORT int32 seeded_rand(int bits);
00344
00345
00348 extern UT_EXPORT int32 seeded_rand_range( int32 from_val, int32 to_val );
00349
00350
00353 extern UT_EXPORT int64 seeded_rand_range64( int64 from_val, int64 to_val );
00354
00355
00356
00357
00358
00359
00366 extern UT_EXPORT int stricmp_utf8( stringliteral* a, stringliteral* b );
00367
00368
00375 extern UT_EXPORT int strnicmp_utf8( stringliteral* a, stringliteral* b, int len );
00376
00377
00385 extern UT_EXPORT stringliteral* stristr_utf8( stringliteral* haystack, stringliteral* needle );
00386
00387
00396 extern UT_EXPORT stringliteral* strnistr_utf8( stringliteral* haystack,
00397 int haystack_length,
00398 stringliteral* needle,
00399 int needle_length );
00400
00401
00402
00403
00404
00405
00408 extern UT_EXPORT uint8 mask_ls_bits_on8(uint on_bit_count);
00409
00412 extern UT_EXPORT uint16 mask_ls_bits_on16(uint on_bit_count);
00413
00416 extern UT_EXPORT uint32 mask_ls_bits_on32(uint on_bit_count);
00417
00420 extern UT_EXPORT uint64 mask_ls_bits_on64(uint on_bit_count);
00421
00424 extern UT_EXPORT uint8 mask_ms_bits_on8(uint on_bit_count);
00425
00428 extern UT_EXPORT uint16 mask_ms_bits_on16(uint on_bit_count);
00429
00432 extern UT_EXPORT uint32 mask_ms_bits_on32(uint on_bit_count);
00433
00436 extern UT_EXPORT uint64 mask_ms_bits_on64(uint on_bit_count);
00437
00439 extern UT_EXPORT uint count_bits_on8(uint8 value);
00440
00442 extern UT_EXPORT uint count_bits_on16(uint16 value);
00443
00445 extern UT_EXPORT uint count_bits_on32(uint32 value);
00446
00448 extern UT_EXPORT uint count_bits_on64(uint64 value);
00449
00452 extern UT_EXPORT int ls_on_bit_index8(uint8 value);
00453
00456 extern UT_EXPORT int ls_on_bit_index16(uint16 value);
00457
00460 extern UT_EXPORT int ls_on_bit_index32(uint32 value);
00461
00464 extern UT_EXPORT int ls_on_bit_index64(uint64 value);
00465
00468 extern UT_EXPORT int ms_on_bit_index8(uint8 value);
00469
00472 extern UT_EXPORT int ms_on_bit_index16(uint16 value);
00473
00476 extern UT_EXPORT int ms_on_bit_index32(uint32 value);
00477
00480 extern UT_EXPORT int ms_on_bit_index64(uint64 value);
00481
00484 extern UT_EXPORT uint8 flip_bit_order8(uint8 value);
00485
00488 extern UT_EXPORT uint16 flip_bit_order16(uint16 value);
00489
00492 extern UT_EXPORT uint32 flip_bit_order32(uint32 value);
00493
00496 extern UT_EXPORT uint64 flip_bit_order64(uint64 value);
00497
00498
00499 EXTERN_C_END