Ignore:
Timestamp:
Nov 28, 2011, 6:58:54 PM (9 years ago)
Author:
gary
Message:

win32: implement threads and mutexes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/thread/threadbase.h

    r1093 r1095  
    1919#if defined __linux__ || defined __native_client__
    2020#   include <pthread.h>
     21#elif defined _WIN32
     22#   include <windows.h>
    2123#else
    2224#   error No threading support yet :(
     
    3335#if defined __linux__ || defined __native_client__
    3436        pthread_mutex_init(&m_mutex, NULL);
     37#elif defined _WIN32
     38        InitializeCriticalSection(&m_mutex);
    3539#endif
    3640    }
     
    4044#if defined __linux__ || defined __native_client__
    4145        pthread_mutex_destroy(&m_mutex);
     46#elif defined _WIN32
     47        DeleteCriticalSection(&m_mutex);
    4248#endif
    4349    }
     
    4753#if defined __linux__ || defined __native_client__
    4854        pthread_mutex_lock(&m_mutex);
     55#elif defined _WIN32
     56        EnterCriticalSection(&m_mutex);
    4957#endif
    5058    }
     
    5462#if defined __linux__ || defined __native_client__
    5563        pthread_mutex_unlock(&m_mutex);
     64#elif defined _WIN32
     65        LeaveCriticalSection(&m_mutex);
    5666#endif
    5767    }
     
    6070#if defined __linux__ || defined __native_client__
    6171    pthread_mutex_t m_mutex;
     72#elif defined _WIN32
     73    CRITICAL_SECTION m_mutex;
    6274#endif
    6375};
     
    124136#if defined __linux__ || defined __native_client__
    125137        pthread_create(&m_thread, NULL, fn, data);
     138#elif defined _WIN32
     139        m_thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)fn, data, 0, &m_tid);
    126140#endif
    127141    }
     
    131145#if defined __linux__ || defined __native_client__
    132146        pthread_join(m_thread, NULL);
     147#elif defined _WIN32
     148        WaitForSingleObject(m_thread, INFINITE);
    133149#endif
    134150    }
     
    137153#if defined __linux__ || defined __native_client__
    138154    pthread_t m_thread;
     155#elif defined _WIN32
     156    HANDLE m_thread;
     157    DWORD m_tid;
    139158#endif
    140159};
Note: See TracChangeset for help on using the changeset viewer.