void vrpn_PeerMutex::mainloop (void) { int i; d_server->mainloop(); for (i = 0; i < d_numPeers; i++) { d_peer[i]->mainloop(); } checkGrantMutex(); }
void vrpn_PeerMutex::request(void) { int i; // No point in sending requests if it's not currently available. // However, we need to trigger any local denial callbacks; otherwise // this looks like a silent failure. if (!isAvailable()) { triggerDenyCallbacks(); #ifdef VERBOSE fprintf(stderr, "vrpn_PeerMutex::request: the mutex isn't available.\n"); #endif return; } d_state = REQUESTING; d_numPeersGrantingLock = 0; for (i = 0; i < d_numPeers; i++) { // d_peerData[i].grantedLock = VRPN_FALSE; sendRequest(d_peer[i]); } // If somebody else sends a request before we get all our grants, // and their IP/port# is lower than ours, we have to yield to them. d_holderIP = d_myIP; d_holderPort = d_myPort; // We used to wait until the next pass through mainloop() to check // this (our request could be trivially granted if we have no // peers), but that leads to bad things (TM), like having to // insert extra calls to mainloop() in client code just to guarantee // that we have the mutex. checkGrantMutex(); #ifdef VERBOSE fprintf(stderr, "vrpn_PeerMutex::request: requested the mutex " "(from %d peers).\n", d_numPeers); #endif }