mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-27 09:58:45 +01:00
Merge branch 'android_invite' of ssh://xwords.git.sourceforge.net/gitroot/xwords/xwords into android_invite
This commit is contained in:
commit
3db7fccb53
5 changed files with 83 additions and 15 deletions
|
@ -2,14 +2,14 @@
|
|||
set -u -e
|
||||
|
||||
NGAMES=${NGAMES:-1}
|
||||
NROOMS=${NROOMS:-1}
|
||||
NROOMS=${NROOMS:-$NGAMES}
|
||||
HOST=${HOST:-localhost}
|
||||
PORT=${PORT:-10997}
|
||||
TIMEOUT=${TIMEOUT:-$((NGAMES*60+500))}
|
||||
DICTS=${DICTS:-dict.xwd}
|
||||
SAVE_GOOD=${SAVE_GOOD:-YES}
|
||||
MAXDEVS=${MAXDEVS:-4}
|
||||
RESIGN_RATIO=${RESIGN_RATIO:-$((NGAMES/3))}
|
||||
RESIGN_RATIO=${RESIGN_RATIO:-$((NGAMES*2))}
|
||||
DROP_N=${DROP_N:-0}
|
||||
MINRUN=2
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "cidlock.h"
|
||||
#include "mlock.h"
|
||||
|
||||
#define CIDLOCK_DEBUG
|
||||
// #define CIDLOCK_DEBUG
|
||||
|
||||
const set<int>
|
||||
CidInfo::GetSockets( void )
|
||||
|
@ -77,7 +77,9 @@ CidLock::print_claimed( const char* caller )
|
|||
CidInfo*
|
||||
CidLock::Claim( CookieID cid )
|
||||
{
|
||||
#ifdef CIDLOCK_DEBUG
|
||||
logf( XW_LOGINFO, "%s(%d)", __func__, cid );
|
||||
#endif
|
||||
CidInfo* info = NULL;
|
||||
for ( ; ; ) {
|
||||
MutexLock ml( &m_infos_mutex );
|
||||
|
@ -103,10 +105,14 @@ CidLock::Claim( CookieID cid )
|
|||
break;
|
||||
}
|
||||
|
||||
#ifdef CIDLOCK_DEBUG
|
||||
logf( XW_LOGINFO, "%s(%d): waiting....", __func__, cid );
|
||||
#endif
|
||||
pthread_cond_wait( &m_infos_condvar, &m_infos_mutex );
|
||||
}
|
||||
#ifdef CIDLOCK_DEBUG
|
||||
logf( XW_LOGINFO, "%s(%d): DONE", __func__, cid );
|
||||
#endif
|
||||
return info;
|
||||
} /* CidLock::Claim */
|
||||
|
||||
|
@ -114,8 +120,9 @@ CidInfo*
|
|||
CidLock::ClaimSocket( int sock )
|
||||
{
|
||||
CidInfo* info = NULL;
|
||||
#ifdef CIDLOCK_DEBUG
|
||||
logf( XW_LOGINFO, "%s(sock=%d)", __func__, sock );
|
||||
|
||||
#endif
|
||||
for ( ; ; ) {
|
||||
MutexLock ml( &m_infos_mutex );
|
||||
|
||||
|
@ -136,11 +143,15 @@ CidLock::ClaimSocket( int sock )
|
|||
if ( iter == m_infos.end() || NULL != info ) {
|
||||
break;
|
||||
}
|
||||
#ifdef CIDLOCK_DEBUG
|
||||
logf( XW_LOGINFO, "%s(sock=%d): waiting....", __func__, sock );
|
||||
#endif
|
||||
pthread_cond_wait( &m_infos_condvar, &m_infos_mutex );
|
||||
}
|
||||
|
||||
#ifdef CIDLOCK_DEBUG
|
||||
logf( XW_LOGINFO, "%s(%d): DONE", __func__, info? info->GetCid():0 );
|
||||
#endif
|
||||
return info;
|
||||
}
|
||||
|
||||
|
@ -148,7 +159,9 @@ void
|
|||
CidLock::Relinquish( CidInfo* claim, bool drop )
|
||||
{
|
||||
CookieID cid = claim->GetCid();
|
||||
#ifdef CIDLOCK_DEBUG
|
||||
logf( XW_LOGINFO, "%s(%d,drop=%d)", __func__, cid, drop );
|
||||
#endif
|
||||
|
||||
MutexLock ml( &m_infos_mutex );
|
||||
map< CookieID, CidInfo*>::iterator iter = m_infos.find( cid );
|
||||
|
@ -156,7 +169,9 @@ CidLock::Relinquish( CidInfo* claim, bool drop )
|
|||
assert( iter->second == claim );
|
||||
assert( claim->GetOwner() == pthread_self() );
|
||||
if ( drop ) {
|
||||
#ifdef CIDLOCK_DEBUG
|
||||
logf( XW_LOGINFO, "%s: deleting %p", __func__, iter->second );
|
||||
#endif
|
||||
m_infos.erase( iter );
|
||||
delete claim;
|
||||
} else {
|
||||
|
@ -165,5 +180,7 @@ CidLock::Relinquish( CidInfo* claim, bool drop )
|
|||
}
|
||||
PRINT_CLAIMED();
|
||||
pthread_cond_signal( &m_infos_condvar );
|
||||
#ifdef CIDLOCK_DEBUG
|
||||
logf( XW_LOGINFO, "%s(%d,drop=%d): DONE", __func__, cid, drop );
|
||||
#endif
|
||||
}
|
||||
|
|
51
xwords4/relay/scripts/threads_alive.py
Executable file
51
xwords4/relay/scripts/threads_alive.py
Executable 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"
|
|
@ -95,6 +95,8 @@ XWThreadPool::Setup( int nThreads, packet_func pFunc, kill_func kFunc )
|
|||
|
||||
int result = pthread_create( &thread, NULL, listener_main, this );
|
||||
assert( result == 0 );
|
||||
result = pthread_detach( thread );
|
||||
assert( result == 0 );
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -113,7 +115,6 @@ XWThreadPool::Stop()
|
|||
void
|
||||
XWThreadPool::AddSocket( int socket, SockType stype )
|
||||
{
|
||||
logf( XW_LOGINFO, "%s(%d)", __func__, socket );
|
||||
{
|
||||
RWWriteLock ml( &m_activeSocketsRWLock );
|
||||
m_activeSockets.push_back( pair<int,SockType>(socket, stype) );
|
||||
|
@ -146,7 +147,7 @@ XWThreadPool::CloseSocket( int socket )
|
|||
{
|
||||
/* bool do_interrupt = false; */
|
||||
if ( !RemoveSocket( socket ) ) {
|
||||
RWWriteLock rwl( &m_activeSocketsRWLock );
|
||||
MutexLock ml( &m_queueMutex );
|
||||
deque<QueuePr>::iterator iter = m_queue.begin();
|
||||
while ( iter != m_queue.end() ) {
|
||||
if ( iter->m_socket == socket ) {
|
||||
|
@ -368,7 +369,6 @@ XWThreadPool::real_listener()
|
|||
}
|
||||
|
||||
if ( 0 != (fds[curfd].revents & (POLLIN | POLLPRI)) ) {
|
||||
logf( XW_LOGINFO, "enqueuing %d", socket );
|
||||
enqueue( socket, stypes[curfd] );
|
||||
} else {
|
||||
logf( XW_LOGERROR, "odd revents: %x",
|
||||
|
@ -409,15 +409,12 @@ XWThreadPool::enqueue( int socket, SockType stype, QAction act )
|
|||
MutexLock ml( &m_queueMutex );
|
||||
m_queue.push_back( pr );
|
||||
|
||||
logf( XW_LOGINFO, "calling pthread_cond_signal" );
|
||||
pthread_cond_signal( &m_queueCondVar );
|
||||
/* implicit unlock */
|
||||
}
|
||||
|
||||
void
|
||||
XWThreadPool::grab_elem_locked( QueuePr* prp )
|
||||
{
|
||||
logf( XW_LOGINFO, "%s()", __func__ );
|
||||
bool found = false;
|
||||
prp->m_socket = -1;
|
||||
deque<QueuePr>::iterator iter;
|
||||
|
@ -433,8 +430,6 @@ XWThreadPool::grab_elem_locked( QueuePr* prp )
|
|||
}
|
||||
|
||||
print_in_use();
|
||||
|
||||
logf( XW_LOGINFO, "%s()=>%d", __func__, prp->m_socket );
|
||||
} /* grab_elem_locked */
|
||||
|
||||
void
|
||||
|
|
|
@ -185,7 +185,6 @@ parseRelayID( const char* const in, char* buf, HostID* hid )
|
|||
strncpy( buf, in, connNameLen );
|
||||
buf[connNameLen] = '\0';
|
||||
*hid = atoi( hidp+1 );
|
||||
logf( XW_LOGINFO, "%s(%s)=>%s : %d", __func__, in, buf, *hid );
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
@ -864,9 +863,15 @@ set_timeouts( int sock )
|
|||
tv.tv_usec = 0; /* microseconds */
|
||||
|
||||
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) );
|
||||
assert( 0 == result );
|
||||
if ( 0 != result ) {
|
||||
logf( XW_LOGERROR, "setsockopt=>%d (%s)", errno, strerror(errno) );
|
||||
assert( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
|
|
Loading…
Reference in a new issue