📄 sys.h
字号:
ERTS_GLB_INLINE interts_smp_is_system_blocked(erts_activity_t allowed_activities){#ifdef ERTS_SMP return erts_is_system_blocked(allowed_activities);#else return 1;#endif}ERTS_GLB_INLINE voiderts_smp_block_system(Uint32 allowed_activities){#ifdef ERTS_SMP erts_block_system(allowed_activities);#endif}ERTS_GLB_INLINE interts_smp_emergency_block_system(long timeout, Uint32 allowed_activities){#ifdef ERTS_SMP return erts_emergency_block_system(timeout, allowed_activities);#else return 0;#endif}ERTS_GLB_INLINE voiderts_smp_release_system(void){#ifdef ERTS_SMP erts_release_system();#endif}ERTS_GLB_INLINE interts_smp_pending_system_block(void){#ifdef ERTS_SMP return erts_smp_atomic_read(&erts_system_block_state.do_block);#else return 0;#endif}ERTS_GLB_INLINE voiderts_smp_chk_system_block(void (*prepare)(void *), void (*resume)(void *), void *arg){#ifdef ERTS_SMP if (erts_smp_pending_system_block()) erts_block_me(prepare, resume, arg);#endif}ERTS_GLB_INLINE voiderts_smp_set_activity(erts_activity_t old_activity, erts_activity_t new_activity, int locked, void (*prepare)(void *), void (*resume)(void *), void *arg, char *file, int line){#ifdef ERTS_SMP#ifdef ERTS_ENABLE_LOCK_CHECK erts_lc_activity_change_begin();#endif switch (old_activity) { case ERTS_ACTIVITY_UNDEFINED: break; case ERTS_ACTIVITY_WAIT: erts_smp_atomic_dec(&erts_system_block_state.in_activity.wait); if (locked) { /* You are not allowed to leave activity waiting * without supplying the possibility to block * unlocked. */ erts_set_activity_error(ERTS_ACT_ERR_LEAVE_WAIT_UNLOCKED, file, line); } break; case ERTS_ACTIVITY_GC: erts_smp_atomic_dec(&erts_system_block_state.in_activity.gc); break; case ERTS_ACTIVITY_IO: erts_smp_atomic_dec(&erts_system_block_state.in_activity.io); break; default: erts_set_activity_error(ERTS_ACT_ERR_LEAVE_UNKNOWN_ACTIVITY, file, line); break; } /* We are not allowed to block when going to activity waiting... */ if (new_activity != ERTS_ACTIVITY_WAIT && erts_smp_pending_system_block()) erts_check_block(old_activity,new_activity,locked,prepare,resume,arg); switch (new_activity) { case ERTS_ACTIVITY_UNDEFINED: break; case ERTS_ACTIVITY_WAIT: erts_smp_atomic_inc(&erts_system_block_state.in_activity.wait); break; case ERTS_ACTIVITY_GC: erts_smp_atomic_inc(&erts_system_block_state.in_activity.gc); break; case ERTS_ACTIVITY_IO: erts_smp_atomic_inc(&erts_system_block_state.in_activity.io); break; default: erts_set_activity_error(ERTS_ACT_ERR_ENTER_UNKNOWN_ACTIVITY, file, line); break; } switch (new_activity) { case ERTS_ACTIVITY_WAIT: case ERTS_ACTIVITY_GC: case ERTS_ACTIVITY_IO: if (erts_smp_pending_system_block()) erts_note_activity_begin(new_activity); break; default: break; }#ifdef ERTS_ENABLE_LOCK_CHECK erts_lc_activity_change_end();#endif#endif}#endif /* #if ERTS_GLB_INLINE_INCL_FUNC_DEF */#if defined(DEBUG) || defined(ERTS_ENABLE_LOCK_CHECK)#undef ERTS_REFC_DEBUG#define ERTS_REFC_DEBUG#endiftypedef erts_smp_atomic_t erts_refc_t;ERTS_GLB_INLINE void erts_refc_init(erts_refc_t *refcp, long val);ERTS_GLB_INLINE void erts_refc_inc(erts_refc_t *refcp, long min_val);ERTS_GLB_INLINE long erts_refc_inctest(erts_refc_t *refcp, long min_val);ERTS_GLB_INLINE void erts_refc_dec(erts_refc_t *refcp, long min_val);ERTS_GLB_INLINE long erts_refc_dectest(erts_refc_t *refcp, long min_val);ERTS_GLB_INLINE long erts_refc_read(erts_refc_t *refcp, long min_val);#if ERTS_GLB_INLINE_INCL_FUNC_DEFERTS_GLB_INLINE voiderts_refc_init(erts_refc_t *refcp, long val){ erts_smp_atomic_init((erts_smp_atomic_t *) refcp, val);}ERTS_GLB_INLINE voiderts_refc_inc(erts_refc_t *refcp, long min_val){#ifdef ERTS_REFC_DEBUG long val = erts_smp_atomic_inctest((erts_smp_atomic_t *) refcp); if (val < min_val) erl_exit(ERTS_ABORT_EXIT, "erts_refc_inc(): Bad refc found (refc=%ld < %ld)!\n", val, min_val);#else erts_smp_atomic_inc((erts_smp_atomic_t *) refcp);#endif}ERTS_GLB_INLINE longerts_refc_inctest(erts_refc_t *refcp, long min_val){ long val = erts_smp_atomic_inctest((erts_smp_atomic_t *) refcp);#ifdef ERTS_REFC_DEBUG if (val < min_val) erl_exit(ERTS_ABORT_EXIT, "erts_refc_inctest(): Bad refc found (refc=%ld < %ld)!\n", val, min_val);#endif return val;}ERTS_GLB_INLINE voiderts_refc_dec(erts_refc_t *refcp, long min_val){#ifdef ERTS_REFC_DEBUG long val = erts_smp_atomic_dectest((erts_smp_atomic_t *) refcp); if (val < min_val) erl_exit(ERTS_ABORT_EXIT, "erts_refc_dec(): Bad refc found (refc=%ld < %ld)!\n", val, min_val);#else erts_smp_atomic_dec((erts_smp_atomic_t *) refcp);#endif}ERTS_GLB_INLINE longerts_refc_dectest(erts_refc_t *refcp, long min_val){ long val = erts_smp_atomic_dectest((erts_smp_atomic_t *) refcp);#ifdef ERTS_REFC_DEBUG if (val < min_val) erl_exit(ERTS_ABORT_EXIT, "erts_refc_dectest(): Bad refc found (refc=%ld < %ld)!\n", val, min_val);#endif return val;}ERTS_GLB_INLINE longerts_refc_read(erts_refc_t *refcp, long min_val){ long val = erts_smp_atomic_read((erts_smp_atomic_t *) refcp);#ifdef ERTS_REFC_DEBUG if (val < min_val) erl_exit(ERTS_ABORT_EXIT, "erts_refc_read(): Bad refc found (refc=%ld < %ld)!\n", val, min_val);#endif return val;}#endif /* #if ERTS_GLB_INLINE_INCL_FUNC_DEF */#ifdef ERTS_ENABLE_KERNEL_POLLextern int erts_use_kernel_poll;#endifvoid elib_ensure_initialized(void);#if (defined(VXWORKS) || defined(_OSE_))/* NOTE! sys_calloc2 does not exist on other platforms than VxWorks and OSE */EXTERN_FUNCTION(void*, sys_calloc2, (Uint, Uint));#endif /* VXWORKS || OSE */#define sys_memcpy(s1,s2,n) memcpy(s1,s2,n)#define sys_memmove(s1,s2,n) memmove(s1,s2,n)#define sys_memcmp(s1,s2,n) memcmp(s1,s2,n)#define sys_memset(s,c,n) memset(s,c,n)#define sys_memzero(s, n) memset(s,'\0',n)#define sys_strcmp(s1,s2) strcmp(s1,s2)#define sys_strncmp(s1,s2,n) strncmp(s1,s2,n)#define sys_strcpy(s1,s2) strcpy(s1,s2)#define sys_strncpy(s1,s2,n) strncpy(s1,s2,n)#define sys_strlen(s) strlen(s)/* define function symbols (needed in sys_drv_api) */#define sys_fp_alloc sys_alloc#define sys_fp_realloc sys_realloc#define sys_fp_free sys_free#define sys_fp_memcpy memcpy#define sys_fp_memmove memmove#define sys_fp_memcmp memcmp#define sys_fp_memset memset/* #define sys_fp_memzero elib_memzero */#define sys_fp_strcmp strcmp#define sys_fp_strncmp strncmp#define sys_fp_strcpy strcpy#define sys_fp_strncpy strncpy#define sys_fp_strlen strlen/* Return codes from the nb_read and nb_write functions */#define FD_READY 1#define FD_CONTINUE 2#define FD_ERROR 3/* Standard set of integer macros .. */#define get_int64(s) ((((unsigned char*) (s))[0] << 56) | \ (((unsigned char*) (s))[1] << 48) | \ (((unsigned char*) (s))[2] << 40) | \ (((unsigned char*) (s))[3] << 32) | \ (((unsigned char*) (s))[4] << 24) | \ (((unsigned char*) (s))[5] << 16) | \ (((unsigned char*) (s))[6] << 8) | \ (((unsigned char*) (s))[7]))#define put_int64(i, s) do { \ Uint j = (i); \ ((char*)(s))[7] = (char)((j)&0xff), j>>=8; \ ((char*)(s))[6] = (char)((j)&0xff), j>>=8; \ ((char*)(s))[5] = (char)((j)&0xff), j>>=8; \ ((char*)(s))[4] = (char)((j)&0xff), j>>=8; \ ((char*)(s))[3] = (char)((j)&0xff), j>>=8; \ ((char*)(s))[2] = (char)((j)&0xff), j>>=8; \ ((char*)(s))[1] = (char)((j)&0xff), j>>=8; \ ((char*)(s))[0] = (char)((j)&0xff); \ } while (0)#define get_int32(s) ((((unsigned char*) (s))[0] << 24) | \ (((unsigned char*) (s))[1] << 16) | \ (((unsigned char*) (s))[2] << 8) | \ (((unsigned char*) (s))[3]))#define put_int32(i, s) {((char*)(s))[0] = (char)((i) >> 24) & 0xff; \ ((char*)(s))[1] = (char)((i) >> 16) & 0xff; \ ((char*)(s))[2] = (char)((i) >> 8) & 0xff; \ ((char*)(s))[3] = (char)((i) & 0xff);}#define get_int16(s) ((((unsigned char*) (s))[0] << 8) | \ (((unsigned char*) (s))[1]))#define put_int16(i, s) {((unsigned char*)(s))[0] = ((i) >> 8) & 0xff; \ ((unsigned char*)(s))[1] = (i) & 0xff;}#define get_int8(s) ((((unsigned char*) (s))[0] ))#define put_int8(i, s) { ((unsigned char*)(s))[0] = (i) & 0xff;}/* * Use DEBUGF as you would use printf, but use double parentheses: * * DEBUGF(("Error: %s\n", error)); * * The output will appear in a special console. */#ifdef DEBUGEXTERN_FUNCTION(void, erl_debug, (char* format, ...));EXTERN_FUNCTION(void, erl_bin_write, (unsigned char *, int, int));# define DEBUGF(x) erl_debug x#else# define DEBUGF(x)#endif#ifdef VXWORKS/* This includes redefines of malloc etc this should be done after sys_alloc, etc, above */# include "reclaim.h"/*********************Malloc and friends************************ * There is a problem with the naming of malloc and friends, * malloc is used throughout sys.c and the resolver to mean save_alloc, * but it should actually mean either sys_alloc or sys_alloc2, * so the definitions from reclaim_master.h are not any * good, i redefine the malloc family here, although it's quite * ugly, actually it would be preferrable to use the * names sys_alloc and so on throughout the offending code, but * that will be saved as an later exercise... * I also add an own calloc, to make the BSD resolver source happy. ***************************************************************//* Undefine malloc and friends */# ifdef malloc# undef malloc# endif# ifdef calloc# undef calloc# endif# ifdef realloc# undef realloc# endif# ifdef free# undef free# endif/* Redefine malloc and friends */# define malloc sys_alloc# define calloc sys_calloc# define realloc sys_realloc# define free sys_free#endif#ifdef __WIN32__void call_break_handler(void);char* last_error(void);char* win32_errorstr(int);#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -