1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
/*############################################################################
# Copyright (C) 2005 Intel Corporation
#
# SPDX-License-Identifier: MIT
############################################################################*/
#ifndef __THREAD_DEFS_H__
#define __THREAD_DEFS_H__
#include "vm/strings_defs.h"
#include "vpl/mfxdefs.h"
typedef unsigned int(MFX_STDCALL* msdk_thread_callback)(void*);
#if defined(_WIN32) || defined(_WIN64)
#include <process.h>
#include <windows.h>
struct msdkSemaphoreHandle {
void* m_semaphore;
};
struct msdkEventHandle {
void* m_event;
};
struct msdkThreadHandle {
void* m_thread;
};
#else // #if defined(_WIN32) || defined(_WIN64)
#include <errno.h>
#include <pthread.h>
#include <sys/resource.h>
#include <sys/time.h>
struct msdkSemaphoreHandle {
msdkSemaphoreHandle(mfxU32 count) : m_count(count) {}
mfxU32 m_count;
pthread_cond_t m_semaphore;
pthread_mutex_t m_mutex;
};
struct msdkEventHandle {
msdkEventHandle(bool manual, bool state) : m_manual(manual), m_state(state) {}
bool m_manual;
bool m_state;
pthread_cond_t m_event;
pthread_mutex_t m_mutex;
};
class MSDKEvent;
struct msdkThreadHandle {
msdkThreadHandle(msdk_thread_callback func, void* arg)
: m_func(func),
m_arg(arg),
m_event(0),
m_thread(0) {}
msdk_thread_callback m_func;
void* m_arg;
MSDKEvent* m_event;
pthread_t m_thread;
};
#endif // #if defined(_WIN32) || defined(_WIN64)
class MSDKSemaphore : public msdkSemaphoreHandle {
public:
MSDKSemaphore(mfxStatus& sts, mfxU32 count = 0);
~MSDKSemaphore(void);
mfxStatus Post(void);
mfxStatus Wait(void);
private:
MSDKSemaphore(const MSDKSemaphore&);
void operator=(const MSDKSemaphore&);
};
class MSDKEvent : public msdkEventHandle {
public:
MSDKEvent(mfxStatus& sts, bool manual, bool state);
~MSDKEvent(void);
mfxStatus Signal(void);
mfxStatus Reset(void);
mfxStatus Wait(void);
mfxStatus TimedWait(mfxU32 msec);
private:
MSDKEvent(const MSDKEvent&);
void operator=(const MSDKEvent&);
};
class MSDKThread : public msdkThreadHandle {
public:
MSDKThread(mfxStatus& sts, msdk_thread_callback func, void* arg);
~MSDKThread(void);
mfxStatus Wait(void);
mfxStatus TimedWait(mfxU32 msec);
mfxStatus GetExitCode();
#if !defined(_WIN32) && !defined(_WIN64)
friend void* msdk_thread_start(void* arg);
#endif
private:
MSDKThread(const MSDKThread&);
void operator=(const MSDKThread&);
};
mfxU32 msdk_get_current_pid();
mfxStatus msdk_setrlimit_vmem(mfxU64 size);
mfxStatus msdk_thread_get_schedtype(const char*, mfxI32& type);
void msdk_thread_printf_scheduling_help();
#endif //__THREAD_DEFS_H__
|