⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdk_system.h

📁 这个是内存数据库中的一个管理工具
💻 H
字号:
#ifndef _GDK_SYSTEM_H_#define _GDK_SYSTEM_H_#ifdef NATIVE_WIN32#ifndef LIBGDK#define gdk_export extern __declspec(dllimport)#else#define gdk_export extern __declspec(dllexport)#endif#else#define gdk_export extern#endif#ifdef HAVE_UNISTD_H# include <unistd.h>		/* io functions */#endif#ifdef HAVE_IO_H# include <io.h>#endif#ifdef HAVE_FCNTL_H#include <fcntl.h>#endif#include <sys/types.h>#ifdef HAVE_SIGNAL_H# include <signal.h>#endif#ifdef HAVE_PTHREAD_H/* don't re-include config.h; on Windows, don't redefine pid_t in an   incompatible way  */#undef HAVE_CONFIG_H#ifdef pid_t#undef pid_t#endif#include <sched.h>#include <pthread.h>#ifndef WIN32/* Linux gprof messes up on multithreaded programs */#ifdef PROFILE#define pthread_create gprof_pthread_create#endif#endif#endif#ifdef HAVE_SEMAPHORE_H# include <semaphore.h>#endif/* new pthread interface, where the thread id changed to a struct */#ifdef PTW32_VERSION#define PTW32 1#endif#if !(defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES)) && defined(HAVE_GETRLIMIT) && defined(HAVE_SYS_RESOURCE_H)# include <sys/resource.h>#endif/* debug and errno integers */gdk_export int GDKdebug;#define MT_geterrno()	errno#define MT_seterrno(x)	errno=x#define MT_log(_impl, _object, _action, _caller, _fp) do { if (GDKdebug & 1024) { fprintf(_fp, "%s: " _action "(" PTRFMT ")\n", _caller, PTRFMTCAST(void*) _object); fflush(_fp); } _impl; } while (0)/* virtual memory defines */gdk_export size_t _MT_npages;gdk_export size_t _MT_pagesize;#define MT_pagesize()	_MT_pagesize#define MT_npages()	_MT_npages/* API */gdk_export void    MT_init(void);     /*  init the package. */gdk_export int     MT_alive(int pid); /* OS independent way to check if some process is still alive. */#define MT_initialized() (MT_pagesize() > 0)typedef size_t MT_Id; /* thread number. will not be zero*/gdk_export int     MT_create_thread(MT_Id *t, void (*function) (void *), void *arg);gdk_export void    MT_exit_thread(int status);gdk_export void    MT_global_exit(int status);gdk_export MT_Id   MT_getpid(void);gdk_export int     MT_kill_thread(MT_Id t);#ifdef HAVE_PTHREAD_SIGMASKgdk_export void    MT_thread_sigmask(sigset_t * new_mask, sigset_t * orig_mask);#endif#if SIZEOF_VOID_P == 4/* "limited" stack size on 32-bit systems *//* to avoid address space fragmentation   */#define THREAD_STACK_SIZE	((size_t)2*512*1024)#else/* "increased" stack size on 64-bit systems    *//* since some compilers seem to require this   *//* for burg-generated code in pathfinder       *//* and address space fragmentation is no issue */#define THREAD_STACK_SIZE	((size_t)4*512*1024)#endiftypedef pthread_mutex_t MT_Lock;#define MT_lock_init(l)      pthread_mutex_init((pthread_mutex_t*) l, 0)#define MT_lock_destroy(l)   pthread_mutex_destroy((pthread_mutex_t*) l)#define MT_lock_set(l,n)     MT_log(pthread_mutex_lock((pthread_mutex_t *) l), l, "MT_set_lock", n, stderr)#define MT_lock_unset(l,n)   MT_log(pthread_mutex_unlock((pthread_mutex_t *) l), l, "MT_unset_lock", n, stderr)#define MT_lock_try(l)       pthread_mutex_trylock((pthread_mutex_t *) l)#define MT_lock_dump(l,fp,n) MT_log(/*nothing*/, &l, "MT_dump_lock", n, fp)/* backward compatability API */#define MT_init_lock(l)      MT_lock_init(&l)   #define MT_destroy_lock(l)   MT_lock_destroy(&l)   #define MT_set_lock(l,n)     MT_lock_set(&l,n)     #define MT_unset_lock(l,n)   MT_lock_unset(&l,n)   #define MT_try_lock(l)       MT_lock_try(&l)       #define MT_dump_lock(l,fp,n) MT_lock_dump(&l,fp,n) gdk_export MT_Lock MT_system_lock;#if defined(_AIX) || defined(__APPLE_CC__)typedef struct {	int cnt;	pthread_mutex_t mutex;	pthread_cond_t cond;} pthread_sema_t;gdk_export void    pthread_sema_init(pthread_sema_t *s, int flag, int nresources);gdk_export void    pthread_sema_destroy(pthread_sema_t *s);gdk_export void    pthread_sema_up(pthread_sema_t *s);gdk_export void    pthread_sema_down(pthread_sema_t *s);#else#define pthread_sema_t       sem_t#define pthread_sema_init    sem_init#define pthread_sema_destroy sem_destroy#define pthread_sema_up      sem_post#define pthread_sema_down(x) while(sem_wait(x)) #endiftypedef pthread_sema_t MT_Sema;#define MT_sema_init(s,nr)   pthread_sema_init(s,0,nr)#define MT_sema_destroy(s)   pthread_sema_destroy(s)#define MT_sema_up(s,n)      MT_log(pthread_sema_up(s), s, "MT_up_sema", n, stderr)#define MT_sema_down(s,n)    MT_log(pthread_sema_down(s), s, "MT_down_sema", n, stderr)#define MT_sema_dump(s,fp,n) MT_log(/*nothing*/, s, "MT_dump_sema", n, fp)/* backward compatability API */#define MT_init_sema(s,nr)   MT_sema_init(&s,nr)#define MT_destroy_sema(s)   MT_sema_destroy(&s)#define MT_up_sema(s,n)      MT_sema_up(&s,n)#define MT_down_sema(s,n)    MT_sema_down(&s,n)#define MT_dump_sema(s,fp,n) MT_sema_dump(&s,fp,n)typedef pthread_cond_t MT_Cond;#define MT_cond_init(c)      pthread_cond_init((pthread_cond_t*) c, NULL)#define MT_cond_destroy(c)   pthread_cond_destroy((pthread_cond_t*) c)#define MT_cond_signal(c,n)  MT_log(pthread_cond_signal((pthread_cond_t*) c), c, "MT_signal_cond", n, stderr)#define MT_cond_wait(c,l,n)  MT_log(pthread_cond_wait((pthread_cond_t*) c, (pthread_mutex_t *) l), c, "MT_wait_cond", n, stderr)/* backward compatability API */#define MT_init_cond(c)      MT_cond_init(&c)#define MT_destroy_cond(c)   MT_cond_destroy(&c)   #define MT_signal_cond(c,n)  MT_cond_signal(&c,n)  #define MT_wait_cond(c,l,n)  MT_cond_wait(&c,&l,n)  #endif /*_GDK_SYSTEM_H_*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -