Ignore:
Timestamp:
Aug 2, 2007, 7:43:29 PM (14 years ago)
Author:
charles
Message:

win32 cleanly compiles and starts now. (still doesn't atually *work*, but we're getting closer...)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/platform.c

    r2587 r2591  
    3434  #define BEOS_MAX_THREADS 256
    3535#elif defined(WIN32)
     36  #include <windows.h>
     37  #include <shlobj.h> /* for CSIDL_APPDATA, CSIDL_PROFILE */
    3638#else
    3739  #include <pthread.h>
     
    4446
    4547#include "transmission.h"
     48#include "list.h"
    4649#include "net.h"
    4750#include "platform.h"
     
    112115    resume_thread( t->thread );
    113116#elif defined(WIN32)
    114     t->thread = (HANDLE) _beginthreadex( NULL, 0, &ThreadFunc, NULL, 0, NULL );
     117    t->thread = (HANDLE) _beginthreadex( NULL, 0, &ThreadFunc, t, 0, NULL );
    115118#else
    116119    pthread_create( &t->thread, NULL, (void * (*) (void *)) ThreadFunc, t );
     
    217220    release_sem( l->lock );
    218221#elif defined(WIN32)
    219     DeleteCriticalSection( &l->lock );
     222    LeaveCriticalSection( &l->lock );
    220223#else
    221224    pthread_mutex_unlock( &l->lock );
     
    344347    int start, end;
    345348#elif defined(WIN32)
    346     CONDITION_VARIABLE cond;
     349    tr_list_t * events;
     350    tr_lock_t * lock;
    347351#else
    348352    pthread_cond_t cond;
    349353#endif
    350354};
     355
     356#ifdef WIN32
     357static DWORD getContEventTLS( void )
     358{
     359    static int inited = FALSE;
     360    static DWORD event_tls;
     361    if( !inited ) {
     362        inited = TRUE;
     363        event_tls = TlsAlloc();
     364    }
     365    return event_tls;
     366}
     367#endif
    351368
    352369tr_cond_t*
     
    359376    c->end = 0;
    360377#elif defined(WIN32)
    361     InitializeConditionVariable( &c->cond );
     378    c->events = NULL;
     379    c->lock = tr_lockNew( );
    362380#else
    363381    pthread_cond_init( &c->cond, NULL );
     
    366384}
    367385
    368 void tr_condWait( tr_cond_t * c, tr_lock_t * l )
    369 {
    370 #ifdef SYS_BEOS
     386void
     387tr_condWait( tr_cond_t * c, tr_lock_t * l )
     388{
     389#ifdef SYS_BEOS
     390
    371391    /* Keep track of that thread */
    372392    acquire_sem( c->sem );
     
    379399    suspend_thread( find_thread( NULL ) ); /* Wait for signal */
    380400    acquire_sem( *l );
    381 #elif defined(WIN32)
    382     SleepConditionVariableCS( &c->cond, &l->lock, INFINITE );
    383 #else
     401
     402#elif defined(WIN32)
     403
     404    /* get this thread's cond event */
     405    DWORD key = getContEventTLS ( );
     406    HANDLE hEvent = TlsGetValue( key );
     407    if( !hEvent ) {
     408        hEvent = CreateEvent( 0, FALSE, FALSE, 0 );
     409        TlsSetValue( key, hEvent );
     410    }
     411
     412    /* add it to the list of events waiting to be signaled */
     413    tr_lockLock( c->lock );
     414    c->events = tr_list_append( c->events, hEvent );
     415    tr_lockUnlock( c->lock );
     416
     417    /* now wait for it to be signaled */
     418    tr_lockUnlock( l );
     419    WaitForSingleObject( hEvent, INFINITE );
     420    tr_lockLock( l );
     421
     422    /* remove it from the list of events waiting to be signaled */
     423    tr_lockLock( c->lock );
     424    c->events = tr_list_remove_data( c->events, hEvent );
     425    tr_lockUnlock( c->lock );
     426
     427#else
     428
    384429    pthread_cond_wait( &c->cond, &l->lock );
     430
    385431#endif
    386432}
     
    410456}
    411457#endif
    412 void tr_condSignal( tr_cond_t * c )
    413 {
    414 #ifdef SYS_BEOS
     458void
     459tr_condSignal( tr_cond_t * c )
     460{
     461#ifdef SYS_BEOS
     462
    415463    acquire_sem( c->sem );
    416464    condTrySignal( c );
    417465    release_sem( c->sem );
    418 #elif defined(WIN32)
    419     WakeConditionVariable( &c->cond );
    420 #else
     466
     467#elif defined(WIN32)
     468
     469    tr_lockLock( c->lock );
     470    if( c->events != NULL )
     471        SetEvent( (HANDLE)c->events->data );
     472    tr_lockUnlock( c->lock );
     473
     474#else
     475
    421476    pthread_cond_signal( &c->cond );
    422 #endif
    423 }
    424 void tr_condBroadcast( tr_cond_t * c )
    425 {
    426 #ifdef SYS_BEOS
     477
     478#endif
     479}
     480
     481void
     482tr_condBroadcast( tr_cond_t * c )
     483{
     484#ifdef SYS_BEOS
     485
    427486    acquire_sem( c->sem );
    428487    while( !condTrySignal( c ) );
    429488    release_sem( c->sem );
    430 #elif defined(WIN32)
    431     WakeAllConditionVariable( &c->cond );
    432 #else
     489
     490#elif defined(WIN32)
     491
     492    tr_list_t * l;
     493    tr_lockLock( c->lock );
     494    for( l=c->events; l!=NULL; l=l->next )
     495        SetEvent( (HANDLE)l->data );
     496    tr_lockUnlock( c->lock );
     497
     498#else
     499
    433500    pthread_cond_broadcast( &c->cond );
     501
    434502#endif
    435503}
     
    441509    delete_sem( c->sem );
    442510#elif defined(WIN32)
    443     /* a no-op, apparently */
     511    tr_list_free( c->events );
     512    tr_lockFree( c->lock );
    444513#else
    445514    pthread_cond_destroy( &c->cond );
     
    453522***/
    454523
    455 #if !defined( SYS_BEOS ) && !defined( __AMIGAOS4__ )
    456 
     524#if !defined(WIN32) && !defined(SYS_BEOS) && !defined(__AMIGAOS4__)
    457525#include <pwd.h>
     526#endif
    458527
    459528const char *
    460529tr_getHomeDirectory( void )
    461530{
    462     static char     homeDirectory[MAX_PATH_LENGTH];
    463     static int      init = 0;
    464     char          * envHome;
    465     struct passwd * pw;
     531    static char buf[MAX_PATH_LENGTH];
     532    static int init = 0;
     533    const char * envHome;
    466534
    467535    if( init )
    468     {
    469         return homeDirectory;
    470     }
     536        return buf;
    471537
    472538    envHome = getenv( "HOME" );
    473     if( NULL == envHome )
    474     {
    475         pw = getpwuid( getuid() );
     539    if( envHome )
     540        snprintf( buf, sizeof(buf), "%s", envHome );
     541    else {
     542#ifdef WIN32
     543        SHGetFolderPath( NULL, CSIDL_PROFILE, NULL, 0, buf );
     544#elif defined(SYS_BEOS) || defined(__AMIGAOS4__)
     545        *buf = '\0';
     546#else
     547        struct passwd * pw = getpwuid( getuid() );
    476548        endpwent();
    477         if( NULL == pw )
    478         {
    479             /* XXX need to handle this case */
    480             return NULL;
    481         }
    482         envHome = pw->pw_dir;
    483     }
    484 
    485     snprintf( homeDirectory, MAX_PATH_LENGTH, "%s", envHome );
     549        if( pw != NULL )
     550            snprintf( buf, sizeof(buf), "%s", pw->pw_dir );
     551#endif
     552    }
     553
    486554    init = 1;
    487 
    488     return homeDirectory;
    489 }
    490 
    491 #else
    492 
    493 const char *
    494 tr_getHomeDirectory( void )
    495 {
    496     /* XXX */
    497     return "";
    498 }
    499 
    500 #endif /* !SYS_BEOS && !__AMIGAOS4__ */
     555    return buf;
     556}
     557
    501558
    502559static void
     
    546603#elif defined(__AMIGAOS4__)
    547604    snprintf( buf, buflen, "PROGDIR:.transmission" );
     605#elif defined(WIN32)
     606    {
     607        char tmp[MAX_PATH_LENGTH];
     608        SHGetFolderPath( NULL, CSIDL_APPDATA, NULL, 0, tmp );
     609        tr_buildPath( buf, sizeof(buf), tmp, "Transmission", NULL );
     610        buflen = strlen( buf );
     611    }
    548612#else
    549613    tr_buildPath ( buf, buflen, h, ".transmission", NULL );
     
    575639
    576640    p = tr_getPrefsDirectory();
    577 #ifdef SYS_BEOS
     641#if defined(SYS_BEOS) || defined(WIN32)
    578642    tr_buildPath( buf, buflen, p, "Cache", NULL );
    579643#elif defined( SYS_DARWIN )
     
    606670    p = tr_getPrefsDirectory ();
    607671
    608 #ifdef SYS_BEOS
     672#if defined(SYS_BEOS) || defined(WIN32)
    609673    tr_buildPath( buf, buflen, p, "Torrents", NULL );
    610674#elif defined( SYS_DARWIN )
Note: See TracChangeset for help on using the changeset viewer.