remove dependency of ithsys on host
This commit is contained in:
parent
3ac79fb9c5
commit
30f95423f1
@ -41,7 +41,7 @@ target_compile_options(vnrhost PRIVATE
|
||||
#STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
|
||||
|
||||
target_link_libraries(vnrhost
|
||||
ithsys
|
||||
#ithsys
|
||||
profile
|
||||
${WDK_HOME}/lib/wxp/i386/ntdll.lib
|
||||
)
|
||||
|
@ -38,7 +38,7 @@ Settings *settings;
|
||||
HWND dummyWindow;
|
||||
BOOL running;
|
||||
|
||||
#define ITH_SYNC_HOOK IthMutexLocker locker(::hookMutex)
|
||||
#define ITH_SYNC_HOOK MutexLocker locker(::hookMutex)
|
||||
|
||||
namespace
|
||||
{ // unnamed
|
||||
@ -64,11 +64,10 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused)
|
||||
case DLL_PROCESS_ATTACH:
|
||||
DisableThreadLibraryCalls(hinstDLL);
|
||||
InitializeCriticalSection(&::hostCs);
|
||||
IthInitSystemService();
|
||||
GetDebugPrivileges();
|
||||
// jichi 12/20/2013: Since I already have a GUI, I don't have to InitCommonControls()
|
||||
// Used by timers.
|
||||
InitCommonControls();
|
||||
// InitCommonControls();
|
||||
// jichi 8/24/2013: Create hidden window so that ITH can access timer and events
|
||||
dummyWindow = CreateWindowW(L"Button", L"InternalWindow", 0, 0, 0, 0, 0, 0, 0, hinstDLL, 0);
|
||||
break;
|
||||
@ -76,7 +75,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused)
|
||||
if (::running)
|
||||
CloseHost();
|
||||
DeleteCriticalSection(&::hostCs);
|
||||
IthCloseSystemService();
|
||||
DestroyWindow(dummyWindow);
|
||||
break;
|
||||
default:
|
||||
|
@ -201,13 +201,15 @@ void DispatchSentence(void* str,DWORD status, int len)
|
||||
memcpy(sentenceBuffer,str,len);
|
||||
*(WORD*)(sentenceBuffer+len)=0;
|
||||
HGLOBAL hCopy;
|
||||
wchar_t copy[0x200];
|
||||
wchar_t copy[0x400];
|
||||
if (status&USING_UNICODE)
|
||||
{
|
||||
memcpy(copy, sentenceBuffer, len + 2);
|
||||
}
|
||||
else
|
||||
copy[MB_WC(sentenceBuffer, copy)] = 0;
|
||||
{
|
||||
MultiByteToWideChar(932, 0, sentenceBuffer, -1, copy, 0x400);
|
||||
}
|
||||
DispatchSentenceToExtensions(copy, status);
|
||||
}
|
||||
}
|
||||
|
@ -79,88 +79,15 @@ template <>
|
||||
bool try_lock() { return ::TryEnterCriticalSection(&_M_mutex); }
|
||||
};
|
||||
|
||||
// Conditional variable
|
||||
|
||||
template <typename _Cond>
|
||||
class win_mutex_cond
|
||||
class MutexLocker
|
||||
{
|
||||
typedef win_mutex_cond<_Cond> _Self;
|
||||
typedef _Cond __native_type;
|
||||
win_mutex_cond(const _Self&);
|
||||
_Self &operator=(const _Self&);
|
||||
|
||||
__native_type _M_cond;
|
||||
HANDLE m;
|
||||
public:
|
||||
enum wait_status { no_timeout = 0, timeout };
|
||||
typedef __native_type *native_handle_type;
|
||||
|
||||
win_mutex_cond() {}
|
||||
native_handle_type native_handle() { return &_M_cond; }
|
||||
|
||||
void notify_one() {}
|
||||
void notify_all() {}
|
||||
|
||||
template <typename _Mutex>
|
||||
void wait(_Mutex &mutex) {}
|
||||
|
||||
template <typename _Mutex, typename _Pred>
|
||||
void wait(_Mutex &mutex, _Pred pred) {}
|
||||
|
||||
template <typename _Mutex>
|
||||
wait_status wait_for(_Mutex &mutex, int msecs) {}
|
||||
|
||||
template <typename _Mutex, typename _Pred>
|
||||
wait_status wait_for(_Mutex &mutex, int msecs, _Pred pred) {}
|
||||
};
|
||||
|
||||
// Note: Conditional variables are NOT availabe on Windows XP/2003
|
||||
// See: http://en.cppreference.com/w/cpp/thread/condition_variable
|
||||
// See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686903%28v=vs.85%29.aspx
|
||||
template <>
|
||||
class win_mutex_cond<CONDITION_VARIABLE>
|
||||
explicit MutexLocker(HANDLE mutex) : m(mutex)
|
||||
{
|
||||
typedef win_mutex_cond<CONDITION_VARIABLE> _Self;
|
||||
typedef CONDITION_VARIABLE __native_type;
|
||||
win_mutex_cond(const _Self&);
|
||||
_Self &operator=(const _Self&);
|
||||
|
||||
__native_type _M_cond;
|
||||
public:
|
||||
enum wait_status { no_timeout = 0, timeout };
|
||||
typedef __native_type *native_handle_type;
|
||||
native_handle_type native_handle() { return &_M_cond; }
|
||||
|
||||
win_mutex_cond() { ::InitializeConditionVariable(&_M_cond); }
|
||||
|
||||
void notify_one() { ::WakeConditionVariable(&_M_cond); }
|
||||
void notify_all() { ::WakeAllConditionVariable(&_M_cond); }
|
||||
|
||||
template <typename _Mutex>
|
||||
void wait(_Mutex &mutex)
|
||||
{ ::SleepConditionVariableCS(&_M_cond, mutex.native_handle(), INFINITE); }
|
||||
|
||||
template <typename _Mutex, typename _Pred>
|
||||
void wait(_Mutex &mutex, _Pred pred)
|
||||
{ while (!pred()) wait(mutex); }
|
||||
|
||||
template <typename _Mutex>
|
||||
wait_status wait_for(_Mutex &mutex, int msecs)
|
||||
{ return ::SleepConditionVariableCS(&_M_cond, mutex.native_handle(), msecs) ? no_timeout : timeout; }
|
||||
|
||||
template <typename _Mutex, typename _Pred>
|
||||
wait_status wait_for(_Mutex &mutex, int msecs, _Pred pred)
|
||||
{
|
||||
auto start = ::GetTickCount();
|
||||
while (!pred()) {
|
||||
auto now = ::GetTickCount();
|
||||
msecs -= now - start;
|
||||
if (msecs <= 0)
|
||||
return timeout;
|
||||
start = now;
|
||||
wait_for(mutex, msecs);
|
||||
}
|
||||
return no_timeout;
|
||||
WaitForSingleObject(m, 0);
|
||||
}
|
||||
~MutexLocker() { if (m != INVALID_HANDLE_VALUE && m != nullptr) ReleaseMutex(m); }
|
||||
};
|
||||
|
||||
// EOF
|
||||
|
Loading…
Reference in New Issue
Block a user