📄 gdk_system.c
字号:
#line 219 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_system.mx"#include "monetdb_config.h"#include "gdk.h"size_t _MT_pagesize = 0; /* variable holding memory size */size_t _MT_npages = 0; /* variable holding page size */MT_Lock MT_system_lock = PTHREAD_MUTEX_INITIALIZER;voidMT_init(void){#ifdef HAVE_GETSYSTEMINFO { SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); _MT_pagesize = sysInfo.dwPageSize; }#else#if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE) _MT_pagesize = sysconf(_SC_PAGESIZE);#endif#endif if (_MT_pagesize <= 0) _MT_pagesize = 4096; /* default */#ifdef HAVE_GLOBALMEMORYSTATUSEX { MEMORYSTATUSEX memStatEx; memStatEx.dwLength = sizeof(memStatEx); if (GlobalMemoryStatusEx(&memStatEx)) _MT_npages = (size_t) (memStatEx.ullTotalPhys / _MT_pagesize); }#endif#ifdef HAVE_GLOBALMEMORYSTATUS if (_MT_npages <= 0) { MEMORYSTATUS memStat; GlobalMemoryStatus(&memStat); _MT_npages = memStat.dwTotalPhys / _MT_pagesize; }#endif#if defined(HAVE_SYSCONF) && defined(_SC_PHYS_PAGES) _MT_npages = sysconf(_SC_PHYS_PAGES);#else#ifdef HAVE_GETRLIMIT { struct rlimit rl; getrlimit(RLIMIT_RSS, &rl); _MT_npages = rl.rlim_cur / _MT_pagesize; }#endif#endif}#ifdef HAVE_PTHREAD_SIGMASKvoidMT_thread_sigmask(sigset_t * new_mask, sigset_t * orig_mask){ (void) sigdelset(new_mask, SIGQUIT); (void) sigdelset(new_mask, SIGALRM); /* else sleep doesn't work */ (void) pthread_sigmask(SIG_SETMASK, new_mask, orig_mask);}#endifintMT_create_thread(MT_Id *t, void (*f) (void *), void *arg){#ifdef HAVE_PTHREAD_SIGMASK sigset_t new_mask, orig_mask;#endif pthread_attr_t attr; pthread_t newt; int ret;#ifdef HAVE_PTHREAD_SIGMASK (void) sigfillset(&new_mask); MT_thread_sigmask(&new_mask, &orig_mask);#endif pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); pthread_attr_setstacksize(&attr, 4 * THREAD_STACK_SIZE); ret = pthread_create(&newt, &attr, (void *(*)(void *)) f, arg); if (ret == 0)#ifdef PTW32 *t = (MT_Id) (((size_t) newt.p) + 1); /* use pthread-id + 1 */#else *t = (MT_Id) (((size_t) newt) + 1); /* use pthread-id + 1 */#endif#ifdef HAVE_PTHREAD_SIGMASK MT_thread_sigmask(&orig_mask, NULL);#endif return ret;}voidMT_global_exit(int s){ exit(s);}voidMT_exit_thread(int s){ int st = s; pthread_exit(&st);}intMT_kill_thread(MT_Id t){#ifdef HAVE_PTHREAD_KILL thread_t id = (thread_t) (t - 1); return pthread_kill((pthread_t) id, SIGHUP);#else (void) t; return -1; /* XXX */#endif}#if defined(_AIX) || defined(__APPLE_CC__)voidpthread_sema_init(pthread_sema_t *s, int flag, int nresources){ (void) flag; s->cnt = nresources; pthread_mutex_init(&(s->mutex), 0); pthread_cond_init(&(s->cond), 0);}voidpthread_sema_destroy(pthread_sema_t *s){ pthread_mutex_destroy(&(s->mutex)); pthread_cond_destroy(&(s->cond));}voidpthread_sema_up(pthread_sema_t *s){ int status = pthread_mutex_lock(&(s->mutex)); if (s->cnt++ < 0) { /* wackup sleeping thread */ status = pthread_cond_signal(&(s->cond)); } status = pthread_mutex_unlock(&(s->mutex));}voidpthread_sema_down(pthread_sema_t *s){ int status = pthread_mutex_lock(&(s->mutex)); if (--s->cnt < 0) { /* thread goes to sleep */ status = pthread_cond_wait(&(s->cond), &(s->mutex)); } status = pthread_mutex_unlock(&(s->mutex));}#endifMT_IdMT_getpid(void){#ifdef PTW32 return (MT_Id) (((size_t) pthread_self().p) + 1);#else return (MT_Id) (((size_t) pthread_self()) + 1);#endif}intMT_alive(int pid){#ifdef HAVE_KILL return kill(pid, 0) == 0;#else (void)pid; return 0;#endif}#line 406 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB/src/gdk/gdk_system.mx"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -