int put1(Map *map, uvlong addr, uchar *v, int size) { if (!map) { werrstr("put1: invalid map"); return -1; } return mput(map, addr, v, size); }
int put1(Map *map, uint64_t addr, uint8_t *v, int size) { if (!map) { werrstr("put1: invalid map"); return -1; } return mput(map, addr, v, size); }
int put2(Map *map, uint64_t addr, uint16_t v) { if (!map) { werrstr("put2: invalid map"); return -1; } v = machdata->swab(v); return mput(map, addr, &v, 2); }
int put4(Map *map, uint64_t addr, uint32_t v) { if (!map) { werrstr("put4: invalid map"); return -1; } v = machdata->swal(v); return mput(map, addr, &v, 4); }
int put8(Map *map, uint64_t addr, uint64_t v) { if (!map) { werrstr("put8: invalid map"); return -1; } v = machdata->swav(v); return mput(map, addr, &v, 8); }
int put2(Map *map, uvlong addr, ushort v) { if (!map) { werrstr("put2: invalid map"); return -1; } v = machdata->swab(v); return mput(map, addr, &v, 2); }
// Get the next goroutine that m should run. // Sched must be locked on entry, is unlocked on exit. // Makes sure that at most $GOMAXPROCS gs are // running on cpus (not in system calls) at any given time. static G* nextgandunlock(void) { G *gp; if(runtime·sched.mcpu < 0) runtime·throw("negative runtime·sched.mcpu"); // If there is a g waiting as m->nextg, // mnextg took care of the runtime·sched.mcpu++. if(m->nextg != nil) { gp = m->nextg; m->nextg = nil; schedunlock(); return gp; } if(m->lockedg != nil) { // We can only run one g, and it's not available. // Make sure some other cpu is running to handle // the ordinary run queue. if(runtime·sched.gwait != 0) matchmg(); } else { // Look for work on global queue. while(runtime·sched.mcpu < runtime·sched.mcpumax && (gp=gget()) != nil) { if(gp->lockedm) { mnextg(gp->lockedm, gp); continue; } runtime·sched.mcpu++; // this m will run gp schedunlock(); return gp; } // Otherwise, wait on global m queue. mput(m); } if(runtime·sched.mcpu == 0 && runtime·sched.msyscall == 0) runtime·throw("all goroutines are asleep - deadlock!"); m->nextg = nil; m->waitnextg = 1; runtime·noteclear(&m->havenextg); if(runtime·sched.waitstop && runtime·sched.mcpu <= runtime·sched.mcpumax) { runtime·sched.waitstop = 0; runtime·notewakeup(&runtime·sched.stopped); } schedunlock(); runtime·notesleep(&m->havenextg); if((gp = m->nextg) == nil) runtime·throw("bad m->nextg in nextgoroutine"); m->nextg = nil; return gp; }
// Get the next goroutine that m should run. // Sched must be locked on entry, is unlocked on exit. // Makes sure that at most $GOMAXPROCS g's are // running on cpus (not in system calls) at any given time. static G* nextgandunlock(void) { G *gp; uint32 v; top: if(atomic_mcpu(runtime·sched.atomic) >= maxgomaxprocs) runtime·throw("negative mcpu"); // If there is a g waiting as m->nextg, the mcpu++ // happened before it was passed to mnextg. if(m->nextg != nil) { gp = m->nextg; m->nextg = nil; schedunlock(); return gp; } if(m->lockedg != nil) { // We can only run one g, and it's not available. // Make sure some other cpu is running to handle // the ordinary run queue. if(runtime·sched.gwait != 0) { matchmg(); // m->lockedg might have been on the queue. if(m->nextg != nil) { gp = m->nextg; m->nextg = nil; schedunlock(); return gp; } } } else { // Look for work on global queue. while(haveg() && canaddmcpu()) { gp = gget(); if(gp == nil) runtime·throw("gget inconsistency"); if(gp->lockedm) { mnextg(gp->lockedm, gp); continue; } runtime·sched.grunning++; schedunlock(); return gp; } // The while loop ended either because the g queue is empty // or because we have maxed out our m procs running go // code (mcpu >= mcpumax). We need to check that // concurrent actions by entersyscall/exitsyscall cannot // invalidate the decision to end the loop. // // We hold the sched lock, so no one else is manipulating the // g queue or changing mcpumax. Entersyscall can decrement // mcpu, but if does so when there is something on the g queue, // the gwait bit will be set, so entersyscall will take the slow path // and use the sched lock. So it cannot invalidate our decision. // // Wait on global m queue. mput(m); } // Look for deadlock situation. // There is a race with the scavenger that causes false negatives: // if the scavenger is just starting, then we have // scvg != nil && grunning == 0 && gwait == 0 // and we do not detect a deadlock. It is possible that we should // add that case to the if statement here, but it is too close to Go 1 // to make such a subtle change. Instead, we work around the // false negative in trivial programs by calling runtime.gosched // from the main goroutine just before main.main. // See runtime·main above. // // On a related note, it is also possible that the scvg == nil case is // wrong and should include gwait, but that does not happen in // standard Go programs, which all start the scavenger. // if((scvg == nil && runtime·sched.grunning == 0) || (scvg != nil && runtime·sched.grunning == 1 && runtime·sched.gwait == 0 && (scvg->status == Grunning || scvg->status == Gsyscall))) { runtime·throw("all goroutines are asleep - deadlock!"); } m->nextg = nil; m->waitnextg = 1; runtime·noteclear(&m->havenextg); // Stoptheworld is waiting for all but its cpu to go to stop. // Entersyscall might have decremented mcpu too, but if so // it will see the waitstop and take the slow path. // Exitsyscall never increments mcpu beyond mcpumax. v = runtime·atomicload(&runtime·sched.atomic); if(atomic_waitstop(v) && atomic_mcpu(v) <= atomic_mcpumax(v)) { // set waitstop = 0 (known to be 1) runtime·xadd(&runtime·sched.atomic, -1<<waitstopShift); runtime·notewakeup(&runtime·sched.stopped); } schedunlock(); runtime·notesleep(&m->havenextg); if(m->helpgc) { runtime·gchelper(); m->helpgc = 0; runtime·lock(&runtime·sched); goto top; } if((gp = m->nextg) == nil) runtime·throw("bad m->nextg in nextgoroutine"); m->nextg = nil; return gp; }
int main(int argc, char *argv[]){ char buff[N], *param; //1024 int j = 0, nb; if( argc != 2){ printf("Usage: %s <server host>\n", argv[0]); exit(1); } printf("commands\n"); do{ memset(buff, '\0', N); prompt(); gets(buff); param = strchr(buff,' '); // param <- commands if (param) { *param=0; param++; } for(j = 0; j < NB_CMDS; j++) if( !strcmp(buff, commandes[j])) break; switch(j){ case(OPEN): if(connection) printf("already connected\n"); else myconnect(argv[1]); break; case(GET): if(!connection) printf("Not connected!\n"); else get(param); break; case(PUT): if(!connection) printf("Not connected!\n"); else put(param); break; case(MGET): if(!connection) printf("Not connected!\n"); else mget(param); break; case(MPUT): if(!connection) printf("Not connected!\n"); else mput(param); break; case(CD): if(!connection) printf("NoT connecteD!\n"); else cd(param); break; case(LCD): lcd(param); break; case(MGET_): if(!connection) printf("Not connected!\n"); else mget_(param); break; case(MPUT_): if(!connection) printf("Not connected!\n"); else mput_(param); break; case(DIR): if(!connection) printf("Not connecte!\n"); else dir(); break; case(LDIR): ldir(); break; case(RGET): if(!connection) printf("Not connected!\n"); else rget(param); break; case(RPUT): if(!connection) printf("Not connected!\n"); else rput(param); break; //case (HELP): aide(); // break; default: printf("%s command invalid\n", buff); printf("Commands are as follows\n"); printf(" get : To Get A file from Server\n"); printf(" put : To Put A file to Server\n"); printf(" cd : change Server's Current Directory\n"); printf(" lcd : Change Client's current Directory\n"); printf(" mget : To Get multiple files from Server\n"); printf(" mput : To put multiple files from Server\n"); printf(" dir : List the Server's current Directory\n"); printf(" ldir : List the Client's current Directory\n"); printf(" mget_ : Put files with wildcard support\n"); printf("mput_ : get files with wildcard support\n"); printf("rget : Get a directory recursively\n"); printf("rput : Put a Directory recursiovely\n"); break; } } while(1); return(0); }
// Get the next goroutine that m should run. // Sched must be locked on entry, is unlocked on exit. // Makes sure that at most $GOMAXPROCS g's are // running on cpus (not in system calls) at any given time. static G* nextgandunlock(void) { G *gp; uint32 v; top: if(atomic_mcpu(runtime_sched.atomic) >= maxgomaxprocs) runtime_throw("negative mcpu"); // If there is a g waiting as m->nextg, the mcpu++ // happened before it was passed to mnextg. if(m->nextg != nil) { gp = m->nextg; m->nextg = nil; schedunlock(); return gp; } if(m->lockedg != nil) { // We can only run one g, and it's not available. // Make sure some other cpu is running to handle // the ordinary run queue. if(runtime_sched.gwait != 0) { matchmg(); // m->lockedg might have been on the queue. if(m->nextg != nil) { gp = m->nextg; m->nextg = nil; schedunlock(); return gp; } } } else { // Look for work on global queue. while(haveg() && canaddmcpu()) { gp = gget(); if(gp == nil) runtime_throw("gget inconsistency"); if(gp->lockedm) { mnextg(gp->lockedm, gp); continue; } runtime_sched.grunning++; schedunlock(); return gp; } // The while loop ended either because the g queue is empty // or because we have maxed out our m procs running go // code (mcpu >= mcpumax). We need to check that // concurrent actions by entersyscall/exitsyscall cannot // invalidate the decision to end the loop. // // We hold the sched lock, so no one else is manipulating the // g queue or changing mcpumax. Entersyscall can decrement // mcpu, but if does so when there is something on the g queue, // the gwait bit will be set, so entersyscall will take the slow path // and use the sched lock. So it cannot invalidate our decision. // // Wait on global m queue. mput(m); } v = runtime_atomicload(&runtime_sched.atomic); if(runtime_sched.grunning == 0) runtime_throw("all goroutines are asleep - deadlock!"); m->nextg = nil; m->waitnextg = 1; runtime_noteclear(&m->havenextg); // Stoptheworld is waiting for all but its cpu to go to stop. // Entersyscall might have decremented mcpu too, but if so // it will see the waitstop and take the slow path. // Exitsyscall never increments mcpu beyond mcpumax. if(atomic_waitstop(v) && atomic_mcpu(v) <= atomic_mcpumax(v)) { // set waitstop = 0 (known to be 1) runtime_xadd(&runtime_sched.atomic, -1<<waitstopShift); runtime_notewakeup(&runtime_sched.stopped); } schedunlock(); runtime_notesleep(&m->havenextg); if(m->helpgc) { runtime_gchelper(); m->helpgc = 0; runtime_lock(&runtime_sched); goto top; } if((gp = m->nextg) == nil) runtime_throw("bad m->nextg in nextgoroutine"); m->nextg = nil; return gp; }