int mutex_service_call(uint32_t svc_number, ...) { int ret = 0; va_list ap; va_start(ap, svc_number); switch (svc_number) { case SVC_ACQUIRE: { struct mutex *mut = va_arg(ap, struct mutex *); ret = svc_acquire(mut); break; } case SVC_RELEASE: { struct mutex *mut = va_arg(ap, struct mutex *); svc_release(mut); break; } default: panic_print("Unknown SVC: %d", svc_number); break; } va_end(ap); return ret; }
/* * Release the specified connection. * Certain actions may be performed before doing this: * - drain of a single UDP packet if the socket type is SOCK_DGRAM */ void conn_free( connection_s *cp, int release_mem ) { struct service *sp ; if( cp == NULL ) return; if( debug.on ) msg( LOG_INFO, "conn_free", "freeing connection") ; sp = cp->co_sp ; if( (SVC_SOCKET_TYPE( sp ) == SOCK_DGRAM) && (SVC_IS_ACTIVE( sp )) ) drain( cp->co_descriptor ) ; if ( SVC_RELE( sp ) == 0 ) { pset_remove( SERVICES( ps ), sp ) ; svc_release( sp ); } cp->co_sp = NULL; if ( CONN_DESCRIPTOR( cp ) > 0 ) CONN_CLOSE( cp ) ; CLEAR( *cp ) ; if (release_mem) { FREE_CONN( cp ) ; } }
/* * Invoked when a server of the specified service dies */ void svc_postmortem( struct service *sp, struct server *serp ) { struct service *co_sp = SERVER_CONNSERVICE( serp ) ; connection_s *cp = SERVER_CONNECTION( serp ) ; const char *func = "svc_postmortem" ; SVC_DEC_RUNNING_SERVERS( sp ) ; /* * Log information about the server that died */ if ( SVC_IS_LOGGING( sp ) ) { if ( SERVER_WRITES_TO_LOG(serp) ) { if ( debug.on ) msg( LOG_DEBUG, func, "Checking log size of %s service", SVC_ID( sp ) ) ; xlog_control( SVC_LOG( sp ), XLOG_SIZECHECK ) ; } svc_log_exit( sp, serp ) ; } /* * Now check if we have to check the log size of the service that owns * the connection */ if ( co_sp != sp && SVC_IS_LOGGING( co_sp ) ) xlog_control( SVC_LOG( co_sp ), XLOG_SIZECHECK ) ; if (!SVC_WAITS(sp)) { conn_free( cp, 1 ) ; cp = NULL; } else { if (cp) { if ( SVC_SOCKET_TYPE( sp ) == SOCK_DGRAM ) drain( cp->co_descriptor ) ; free(cp); cp = NULL; if( SVC_RELE( sp ) == 0 ) svc_release( sp ); /* shouldn't be 0, but should remove from * pset if it is... */ } svc_resume(sp); } }