FreeSWITCH - mod_xml_rpc 소스 분석 6threadwindows.c

3515 단어 freeswitchabyss
이 파일은 윈도우즈 플랫폼을 위한 루트입니다.VisualStudio에서 볼 수 있는, socketopenssl.c、socket_unix.c、thread_fork.c 및 threadpthread.c 이 네 개의 파일은abyss 프로젝트를 생성할 때 코드를 생성하지 않습니다.이것은 이해하기 쉽다, 특히threadfork.c 및 threadpthread.c 이 두 파일에 threadwindows.c 파일은 윈도우즈 플랫폼에서 abyss를 컴파일할 때 윈도우즈 플랫폼 하단 라인과 관련된 특정 코드만 사용하는 것으로 이해할 수 있다.

라인

struct abyss_thread {
    HANDLE handle;
    void * userHandle;
    TThreadProc *   func;
    TThreadDoneFn * threadDone;
};
typedef struct abyss_thread TThread;

TThread는 라이브러리 내부의 라인에 대한 봉인입니다.ThreadCreate 함수의 역할은 TThread 구조체 변수를 만들고 라인을 시작하는 것입니다.TThread 구조체 변수는 루트 주 함수에 제공됩니다.사용자 코드는 사용자 정의 데이터를 userHandle에 저장할 수 있도록 라인에 제공하려고 합니다.사용자 코드의 스레드 주 함수는 TThreadProc 유형이어야 합니다.또한 사용자 코드는 TThreadDoneFn 형식의 스레드 완성 처리 함수를 제공할 수 있습니다.useSigchld 매개 변수는 윈도우즈 플랫폼에서 의미가 없기 때문에 사용하지 않았을 수도 있습니다.CREATE 를 사용했으므로 스레드가 생성된 후 즉시 시작되지 않습니다.SUSPENDED 매개변수.루틴이 생성된 후 핸들은 TThread 변수의handle 속성에 저장됩니다.
void
ThreadCreate(TThread **      const threadPP,
             void *          const userHandle,
             TThreadProc   * const func,
             TThreadDoneFn * const threadDone,
             bool            const useSigchld,
             const char **   const errorP) {

    TThread * threadP;

    MALLOCVAR(threadP);

    if (threadP == NULL)
        xmlrpc_asprintf(errorP,
                        "Can't allocate memory for thread descriptor.");
    else {
        DWORD z;

        threadP->userHandle = userHandle;
        threadP->func       = func;
        threadP->threadDone = threadDone;

        threadP->handle = (HANDLE)_beginthreadex(NULL,
                                                 THREAD_STACK_SIZE,
                                                 threadRun,
                                                 threadP,
                                                 CREATE_SUSPENDED,
                                                 &z);

        if (threadP->handle == NULL)
            xmlrpc_asprintf(errorP, "_beginthreadex() failed.");
        else {
            *errorP = NULL;
            *threadPP = threadP;
        }
        if (*errorP)
            free(threadP);
    }
}
static uint32_t WINAPI
threadRun(void * const arg) {

    struct abyss_thread * const threadP = arg;

    threadP->func(threadP->userHandle);

    threadP->threadDone(threadP->userHandle);

    return 0;
}

TThread에 루틴 핸들이 저장되어 있기 때문에 다른 모든 루틴 봉인 함수는 TThread의handle 핸들을 대상으로 조작됩니다.

Mutex

struct abyss_mutex {
    HANDLE winMutex;
};
typedef struct abyss_mutex TMutex;

abyss_mutex는 윈도우즈 플랫폼 아래에 문맥만 봉인되어 있습니다.MutexCreate 함수 처리 과정도 이 점을 설명한다.신청 공간이 TMutex를 만든 후 Create Mutex 함수를 호출하여 윈도우즈 플랫폼에서 mutex 대상을 만들고 성공한 후에 커서를 TMutex의win Mutex 속성에 부여합니다.다른 Mutex 함수는 스레드 함수와 마찬가지로 Mutex 핸들만 다룹니다.
bool
MutexCreate(TMutex ** const mutexPP) {

    TMutex * mutexP;
    bool succeeded;

    MALLOCVAR(mutexP);

    if (mutexP) {

        mutexP->winMutex = CreateMutex(NULL, FALSE, NULL);

        succeeded = (mutexP->winMutex != NULL);
    } else
        succeeded = FALSE;

    if (!succeeded)
        free(mutexP);

    *mutexPP = mutexP;

    TraceMsg( "Created Mutex %s
", (succeeded ? "ok" : "FAILED") ); return succeeded; }



좋은 웹페이지 즐겨찾기