static void mcommoninit(M *m) { // Add to runtime_allm so garbage collector doesn't free m // when it is just in a register or thread-local storage. m->alllink = runtime_allm; // runtime_Cgocalls() iterates over allm w/o schedlock, // so we need to publish it safely. runtime_atomicstorep((void**)&runtime_allm, m); m->id = runtime_sched.mcount++; m->fastrand = 0x49f6428aUL + m->id; if(m->mcache == nil) m->mcache = runtime_allocmcache(); }
static void mcommoninit(M *m) { m->id = runtime_sched.mcount++; m->fastrand = 0x49f6428aUL + m->id + runtime_cputicks(); if(m->mcache == nil) m->mcache = runtime_allocmcache(); runtime_callers(1, m->createstack, nelem(m->createstack)); // Add to runtime_allm so garbage collector doesn't free m // when it is just in a register or thread-local storage. m->alllink = runtime_allm; // runtime_NumCgoCall() iterates over allm w/o schedlock, // so we need to publish it safely. runtime_atomicstorep(&runtime_allm, m); }
void runtime_startpanic(void) { M *m; m = runtime_m(); if(runtime_mheap.cachealloc.size == 0) { // very early runtime_printf("runtime: panic before malloc heap initialized\n"); m->mallocing = 1; // tell rest of panic not to try to malloc } else if(m->mcache == nil) // can happen if called from signal handler or throw m->mcache = runtime_allocmcache(); switch(m->dying) { case 0: m->dying = 1; if(runtime_g() != nil) runtime_g()->writebuf = nil; runtime_xadd(&runtime_panicking, 1); runtime_lock(&paniclk); if(runtime_debug.schedtrace > 0 || runtime_debug.scheddetail > 0) runtime_schedtrace(true); runtime_freezetheworld(); return; case 1: // Something failed while panicing, probably the print of the // argument to panic(). Just print a stack trace and exit. m->dying = 2; runtime_printf("panic during panic\n"); runtime_dopanic(0); runtime_exit(3); case 2: // This is a genuine bug in the runtime, we couldn't even // print the stack trace successfully. m->dying = 3; runtime_printf("stack trace unavailable\n"); runtime_exit(4); default: // Can't even print! Just exit. runtime_exit(5); } }