void runtime·osinit(void) { runtime·ncpu = getproccount(); m->procid = getpid(); runtime·notify(runtime·gonote); }
void runtime·osinit(void) { runtime·ncpu = getproccount(); m->procid = getpid(); runtime·notify(runtime·sigtramp); }
void runtime·osinit(void) { // -1 = current process, -2 = current thread runtime·stdcall(runtime·DuplicateHandle, 7, (uintptr)-1, (uintptr)-2, (uintptr)-1, &m->thread, (uintptr)0, (uintptr)0, (uintptr)DUPLICATE_SAME_ACCESS); runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (uintptr)1); runtime·stdcall(runtime·timeBeginPeriod, 1, (uintptr)1); runtime·ncpu = getproccount(); }
// Possible lock states are MUTEX_UNLOCKED, MUTEX_LOCKED and MUTEX_SLEEPING. // MUTEX_SLEEPING means that there is presumably at least one sleeping thread. // Note that there can be spinning threads during all states - they do not // affect mutex's state. static void futexlock(Lock *l) { uint32 i, v, wait, spin; // Speculative grab for lock. v = runtime·xchg(&l->key, MUTEX_LOCKED); if(v == MUTEX_UNLOCKED) return; // wait is either MUTEX_LOCKED or MUTEX_SLEEPING // depending on whether there is a thread sleeping // on this mutex. If we ever change l->key from // MUTEX_SLEEPING to some other value, we must be // careful to change it back to MUTEX_SLEEPING before // returning, to ensure that the sleeping thread gets // its wakeup call. wait = v; if(proccount == 0) proccount = getproccount(); // On uniprocessor's, no point spinning. // On multiprocessors, spin for ACTIVE_SPIN attempts. spin = 0; if(proccount > 1) spin = ACTIVE_SPIN; for(;;) { // Try for lock, spinning. for(i = 0; i < spin; i++) { while(l->key == MUTEX_UNLOCKED) if(runtime·cas(&l->key, MUTEX_UNLOCKED, wait)) return; runtime·procyield(ACTIVE_SPIN_CNT); } // Try for lock, rescheduling. for(i=0; i < PASSIVE_SPIN; i++) { while(l->key == MUTEX_UNLOCKED) if(runtime·cas(&l->key, MUTEX_UNLOCKED, wait)) return; runtime·osyield(); } // Sleep. v = runtime·xchg(&l->key, MUTEX_SLEEPING); if(v == MUTEX_UNLOCKED) return; wait = MUTEX_SLEEPING; futexsleep(&l->key, MUTEX_SLEEPING); } }
void runtime·osinit(void) { void *kernel32; runtime·externalthreadhandlerp = (uintptr)runtime·externalthreadhandler; runtime·stdcall(runtime·AddVectoredExceptionHandler, 2, (uintptr)1, (uintptr)runtime·sigtramp); runtime·stdcall(runtime·SetConsoleCtrlHandler, 2, runtime·ctrlhandler, (uintptr)1); runtime·stdcall(runtime·timeBeginPeriod, 1, (uintptr)1); runtime·ncpu = getproccount(); // Windows dynamic priority boosting assumes that a process has different types // of dedicated threads -- GUI, IO, computational, etc. Go processes use // equivalent threads that all do a mix of GUI, IO, computations, etc. // In such context dynamic priority boosting does nothing but harm, so we turn it off. runtime·stdcall(runtime·SetProcessPriorityBoost, 2, (uintptr)-1, (uintptr)1); kernel32 = runtime·stdcall(runtime·LoadLibraryA, 1, "kernel32.dll"); if(kernel32 != nil) { runtime·GetQueuedCompletionStatusEx = runtime·stdcall(runtime·GetProcAddress, 2, kernel32, "GetQueuedCompletionStatusEx"); } }
void go_main() { // a slowdown in this scenario for gccgo-6.3.0 but not for gcc-7.1.0 or Go runtime_gomaxprocsfunc(getproccount()); const long n = 500000; /*void *leftmost = chan_make(0);*/ void *leftmost; writebarrierptr(&leftmost, chan_make(0)); /*void *right = leftmost;*/ void *right; writebarrierptr(&right, leftmost); /*void *left = leftmost;*/ void *left; writebarrierptr(&left, leftmost); long i; long res; channels *chans; for(i = 0; i < n; i++) { /*right = chan_make(0);*/ writebarrierptr(&right, chan_make(0)); /*chans = (channels *)go_malloc(sizeof(channels));*/ writebarrierptr((void**)&chans, go_malloc(sizeof(channels))); /*chans->left = left;*/ writebarrierptr(&(chans->left), left); /*chans->right = right;*/ writebarrierptr(&(chans->right), right); __go_go(whisper, chans); /*left = right;*/ writebarrierptr(&left, right); } __go_go(first_whisper, right); res = *(long *)chan_recv(leftmost); printf("%ld\n", res); }
void runtime·osinit(void) { runtime·ncpu = getproccount(); }
void runtime_osinit(void) { runtime_ncpu = getproccount(); }