static short AcquireLock(OTUDP *x) { // Mutual exclusion: Make sure that neither Max not Open Transport will interrupt us int i; short oldLockout; oldLockout = lockout_set(1); OTEnterNotifier(x->o_udp_ep); #define TOO_MANY_SPINS 1 i = 0; while (OTAcquireLock(&(x->o_readlock)) == false) { if ((++i) > TOO_MANY_SPINS) { error("¥ otudp_read: OTAcquireLock keeps failing!"); } } if (x->o_semaphoreTest != 0) { ++(x->o_semaphoreTestFailureCount); if (x->o_semaphoreTestFailureCount == 1 || (x->o_semaphoreTestFailureCount % 100) == 0) { error("¥ otudp_read: new semaphore test failed (%d times)"); } } ++(x->o_semaphoreTest); return oldLockout; }
// This function is taken from GUSI interface. // ( 01/02/19 masahiro minami<*****@*****.**> ) static void AsyncTCPPopEvent( TCPsocket sock ) { // Make sure OT calls are not interrupted // Not sure if we really need this. OTEnterNotifier( sock->channel ); sock->event |= (sock->curEvent = sock->newEvent ); sock->completion |= ( sock->curCompletion = sock->newCompletion ); sock->newEvent = sock->newCompletion = 0; OTLeaveNotifier( sock->channel ); if( sock->curEvent & T_UDERR) { // We just clear the error. // Should we feed this back to users ? // (TODO ) OTRcvUDErr( sock->channel, NULL ); #ifdef DEBUG_NET printf("AsyncTCPPopEvent T_UDERR recognized"); #endif } // Remote is disconnecting... if( sock->curEvent & ( T_DISCONNECT | T_ORDREL )) { sock->readShutdown = true; } if( sock->curEvent &T_CONNECT ) { // Ignore the info of remote (second parameter). // Shoule we care ? // (TODO) OTRcvConnect( sock->channel, NULL ); sock->connected = 1; } if( sock->curEvent & T_ORDREL ) { OTRcvOrderlyDisconnect( sock->channel ); } if( sock->curEvent & T_DISCONNECT ) { OTRcvDisconnect( sock->channel, NULL ); } // Do we need to ? // (masahiro minami<*****@*****.**>) //YieldToAnyThread(); }
static short AcquireLock(OTTCP *x) { // Mutual exclusion: Make sure that neither Max not Open Transport will interrupt us int i; short oldLockout; oldLockout = lockout_set(1); OTEnterNotifier(x->o_tcp_ep); #define TOO_MANY_SPINS 1 i = 0; while (OTAcquireLock(&(x->o_readlock)) == false) { if ((++i) > TOO_MANY_SPINS) { ouchstring("OTAcquireLock keeps failing inside ottcp_read!"); } } return oldLockout; }