Merge branch 'android_invite' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into android_invite

This commit is contained in:
eehouse@eehouse.org 2011-06-30 18:57:53 -07:00 committed by Andy2
commit 3db7fccb53
5 changed files with 83 additions and 15 deletions

View file

@ -2,14 +2,14 @@
set -u -e set -u -e
NGAMES=${NGAMES:-1} NGAMES=${NGAMES:-1}
NROOMS=${NROOMS:-1} NROOMS=${NROOMS:-$NGAMES}
HOST=${HOST:-localhost} HOST=${HOST:-localhost}
PORT=${PORT:-10997} PORT=${PORT:-10997}
TIMEOUT=${TIMEOUT:-$((NGAMES*60+500))} TIMEOUT=${TIMEOUT:-$((NGAMES*60+500))}
DICTS=${DICTS:-dict.xwd} DICTS=${DICTS:-dict.xwd}
SAVE_GOOD=${SAVE_GOOD:-YES} SAVE_GOOD=${SAVE_GOOD:-YES}
MAXDEVS=${MAXDEVS:-4} MAXDEVS=${MAXDEVS:-4}
RESIGN_RATIO=${RESIGN_RATIO:-$((NGAMES/3))} RESIGN_RATIO=${RESIGN_RATIO:-$((NGAMES*2))}
DROP_N=${DROP_N:-0} DROP_N=${DROP_N:-0}
MINRUN=2 MINRUN=2

View file

@ -25,7 +25,7 @@
#include "cidlock.h" #include "cidlock.h"
#include "mlock.h" #include "mlock.h"
#define CIDLOCK_DEBUG // #define CIDLOCK_DEBUG
const set<int> const set<int>
CidInfo::GetSockets( void ) CidInfo::GetSockets( void )
@ -77,7 +77,9 @@ CidLock::print_claimed( const char* caller )
CidInfo* CidInfo*
CidLock::Claim( CookieID cid ) CidLock::Claim( CookieID cid )
{ {
#ifdef CIDLOCK_DEBUG
logf( XW_LOGINFO, "%s(%d)", __func__, cid ); logf( XW_LOGINFO, "%s(%d)", __func__, cid );
#endif
CidInfo* info = NULL; CidInfo* info = NULL;
for ( ; ; ) { for ( ; ; ) {
MutexLock ml( &m_infos_mutex ); MutexLock ml( &m_infos_mutex );
@ -103,10 +105,14 @@ CidLock::Claim( CookieID cid )
break; break;
} }
#ifdef CIDLOCK_DEBUG
logf( XW_LOGINFO, "%s(%d): waiting....", __func__, cid ); logf( XW_LOGINFO, "%s(%d): waiting....", __func__, cid );
#endif
pthread_cond_wait( &m_infos_condvar, &m_infos_mutex ); pthread_cond_wait( &m_infos_condvar, &m_infos_mutex );
} }
#ifdef CIDLOCK_DEBUG
logf( XW_LOGINFO, "%s(%d): DONE", __func__, cid ); logf( XW_LOGINFO, "%s(%d): DONE", __func__, cid );
#endif
return info; return info;
} /* CidLock::Claim */ } /* CidLock::Claim */
@ -114,8 +120,9 @@ CidInfo*
CidLock::ClaimSocket( int sock ) CidLock::ClaimSocket( int sock )
{ {
CidInfo* info = NULL; CidInfo* info = NULL;
#ifdef CIDLOCK_DEBUG
logf( XW_LOGINFO, "%s(sock=%d)", __func__, sock ); logf( XW_LOGINFO, "%s(sock=%d)", __func__, sock );
#endif
for ( ; ; ) { for ( ; ; ) {
MutexLock ml( &m_infos_mutex ); MutexLock ml( &m_infos_mutex );
@ -136,11 +143,15 @@ CidLock::ClaimSocket( int sock )
if ( iter == m_infos.end() || NULL != info ) { if ( iter == m_infos.end() || NULL != info ) {
break; break;
} }
#ifdef CIDLOCK_DEBUG
logf( XW_LOGINFO, "%s(sock=%d): waiting....", __func__, sock ); logf( XW_LOGINFO, "%s(sock=%d): waiting....", __func__, sock );
#endif
pthread_cond_wait( &m_infos_condvar, &m_infos_mutex ); pthread_cond_wait( &m_infos_condvar, &m_infos_mutex );
} }
#ifdef CIDLOCK_DEBUG
logf( XW_LOGINFO, "%s(%d): DONE", __func__, info? info->GetCid():0 ); logf( XW_LOGINFO, "%s(%d): DONE", __func__, info? info->GetCid():0 );
#endif
return info; return info;
} }
@ -148,7 +159,9 @@ void
CidLock::Relinquish( CidInfo* claim, bool drop ) CidLock::Relinquish( CidInfo* claim, bool drop )
{ {
CookieID cid = claim->GetCid(); CookieID cid = claim->GetCid();
#ifdef CIDLOCK_DEBUG
logf( XW_LOGINFO, "%s(%d,drop=%d)", __func__, cid, drop ); logf( XW_LOGINFO, "%s(%d,drop=%d)", __func__, cid, drop );
#endif
MutexLock ml( &m_infos_mutex ); MutexLock ml( &m_infos_mutex );
map< CookieID, CidInfo*>::iterator iter = m_infos.find( cid ); map< CookieID, CidInfo*>::iterator iter = m_infos.find( cid );
@ -156,7 +169,9 @@ CidLock::Relinquish( CidInfo* claim, bool drop )
assert( iter->second == claim ); assert( iter->second == claim );
assert( claim->GetOwner() == pthread_self() ); assert( claim->GetOwner() == pthread_self() );
if ( drop ) { if ( drop ) {
#ifdef CIDLOCK_DEBUG
logf( XW_LOGINFO, "%s: deleting %p", __func__, iter->second ); logf( XW_LOGINFO, "%s: deleting %p", __func__, iter->second );
#endif
m_infos.erase( iter ); m_infos.erase( iter );
delete claim; delete claim;
} else { } else {
@ -165,5 +180,7 @@ CidLock::Relinquish( CidInfo* claim, bool drop )
} }
PRINT_CLAIMED(); PRINT_CLAIMED();
pthread_cond_signal( &m_infos_condvar ); pthread_cond_signal( &m_infos_condvar );
#ifdef CIDLOCK_DEBUG
logf( XW_LOGINFO, "%s(%d,drop=%d): DONE", __func__, cid, drop ); logf( XW_LOGINFO, "%s(%d,drop=%d): DONE", __func__, cid, drop );
#endif
} }

View file

@ -0,0 +1,51 @@
#!/usr/bin/python
import re;
LOGFILE = "./xwrelay.log"
LINEPAT = r"^<0x.*>"
# first get a list of the threads
last_seen = {}
last_ts = ""
def do_init():
return [ {}, "00:00:00" ]
def print_last_seen(last_seen):
print "one run's worth:"
for key,value in last_seen.iteritems():
print key, "---", value
def main():
cur_date = "00/00/00"
last_seen, last_ts = do_init()
fil = open( LOGFILE, "r" )
for line in fil:
mo = re.match( r".* \*\*\*\*\* forked \d*th new process \*\*\*\*\*", line )
if mo:
print_last_seen( last_seen )
last_seen, last_ts = do_init()
continue
mo = re.match( r"<(0x.*)>(\d\d:\d\d:\d\d): (.*)$", line)
if mo:
thread = mo.group(1);
last_ts = mo.group(2)
last_seen[thread] = cur_date + "--" + last_ts
continue
mo = re.match( r"It's a new day: (.*)$", line )
if mo:
cur_date = mo.group(1)
fil.close()
print_last_seen( last_seen )
#######################################################################
# main
#######################################################################
if __name__ == "__main__":
main()
else:
print "not main"

View file

@ -95,6 +95,8 @@ XWThreadPool::Setup( int nThreads, packet_func pFunc, kill_func kFunc )
int result = pthread_create( &thread, NULL, listener_main, this ); int result = pthread_create( &thread, NULL, listener_main, this );
assert( result == 0 ); assert( result == 0 );
result = pthread_detach( thread );
assert( result == 0 );
} }
void void
@ -113,7 +115,6 @@ XWThreadPool::Stop()
void void
XWThreadPool::AddSocket( int socket, SockType stype ) XWThreadPool::AddSocket( int socket, SockType stype )
{ {
logf( XW_LOGINFO, "%s(%d)", __func__, socket );
{ {
RWWriteLock ml( &m_activeSocketsRWLock ); RWWriteLock ml( &m_activeSocketsRWLock );
m_activeSockets.push_back( pair<int,SockType>(socket, stype) ); m_activeSockets.push_back( pair<int,SockType>(socket, stype) );
@ -146,7 +147,7 @@ XWThreadPool::CloseSocket( int socket )
{ {
/* bool do_interrupt = false; */ /* bool do_interrupt = false; */
if ( !RemoveSocket( socket ) ) { if ( !RemoveSocket( socket ) ) {
RWWriteLock rwl( &m_activeSocketsRWLock ); MutexLock ml( &m_queueMutex );
deque<QueuePr>::iterator iter = m_queue.begin(); deque<QueuePr>::iterator iter = m_queue.begin();
while ( iter != m_queue.end() ) { while ( iter != m_queue.end() ) {
if ( iter->m_socket == socket ) { if ( iter->m_socket == socket ) {
@ -368,7 +369,6 @@ XWThreadPool::real_listener()
} }
if ( 0 != (fds[curfd].revents & (POLLIN | POLLPRI)) ) { if ( 0 != (fds[curfd].revents & (POLLIN | POLLPRI)) ) {
logf( XW_LOGINFO, "enqueuing %d", socket );
enqueue( socket, stypes[curfd] ); enqueue( socket, stypes[curfd] );
} else { } else {
logf( XW_LOGERROR, "odd revents: %x", logf( XW_LOGERROR, "odd revents: %x",
@ -409,15 +409,12 @@ XWThreadPool::enqueue( int socket, SockType stype, QAction act )
MutexLock ml( &m_queueMutex ); MutexLock ml( &m_queueMutex );
m_queue.push_back( pr ); m_queue.push_back( pr );
logf( XW_LOGINFO, "calling pthread_cond_signal" );
pthread_cond_signal( &m_queueCondVar ); pthread_cond_signal( &m_queueCondVar );
/* implicit unlock */
} }
void void
XWThreadPool::grab_elem_locked( QueuePr* prp ) XWThreadPool::grab_elem_locked( QueuePr* prp )
{ {
logf( XW_LOGINFO, "%s()", __func__ );
bool found = false; bool found = false;
prp->m_socket = -1; prp->m_socket = -1;
deque<QueuePr>::iterator iter; deque<QueuePr>::iterator iter;
@ -433,8 +430,6 @@ XWThreadPool::grab_elem_locked( QueuePr* prp )
} }
print_in_use(); print_in_use();
logf( XW_LOGINFO, "%s()=>%d", __func__, prp->m_socket );
} /* grab_elem_locked */ } /* grab_elem_locked */
void void

View file

@ -185,7 +185,6 @@ parseRelayID( const char* const in, char* buf, HostID* hid )
strncpy( buf, in, connNameLen ); strncpy( buf, in, connNameLen );
buf[connNameLen] = '\0'; buf[connNameLen] = '\0';
*hid = atoi( hidp+1 ); *hid = atoi( hidp+1 );
logf( XW_LOGINFO, "%s(%s)=>%s : %d", __func__, in, buf, *hid );
} }
return ok; return ok;
} }
@ -864,9 +863,15 @@ set_timeouts( int sock )
tv.tv_usec = 0; /* microseconds */ tv.tv_usec = 0; /* microseconds */
result = setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv) ); result = setsockopt( sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv) );
assert( 0 == result ); if ( 0 != result ) {
logf( XW_LOGERROR, "setsockopt=>%d (%s)", errno, strerror(errno) );
assert( 0 );
}
result = setsockopt( sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv) ); result = setsockopt( sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv) );
assert( 0 == result ); if ( 0 != result ) {
logf( XW_LOGERROR, "setsockopt=>%d (%s)", errno, strerror(errno) );
assert( 0 );
}
} }
int int