diff --git a/src/Apple/Semaphore.cpp b/src/Apple/Semaphore.cpp index 7e0af7c..87c1d54 100644 --- a/src/Apple/Semaphore.cpp +++ b/src/Apple/Semaphore.cpp @@ -1,12 +1,8 @@ -#include -#include -#include -#include +#include +#include namespace hgl { - void GetWaitTime(struct timespec &,double); - /** * @param max_count 最大计数 */ @@ -52,7 +48,18 @@ namespace hgl { if(!ptr)return(false); - return !dispatch_semaphore_wait(ptr, DISPATCH_TIME_NOW); + return !dispatch_semaphore_wait(ptr,DISPATCH_TIME_NOW); + } + + /** + * 等待并获取一个信号 + * @return 是否等待到了,如果超过最长时间,仍未等到即为超时,返回false + */ + bool Semaphore::Acquire() + { + if(!ptr)return(false); + + return !dispatch_semaphore_wait(ptr,DISPATCH_TIME_FOREVER); } /** @@ -64,15 +71,8 @@ namespace hgl { if(!ptr)return(false); - if(t<=0) - { - return !dispatch_semaphore_wait(ptr, DISPATCH_TIME_FOREVER); - } - else - { - dispatch_time_t when=dispatch_time(DISPATCH_TIME_NOW,t*HGL_NANO_SEC_PER_SEC); + dispatch_time_t when=dispatch_time(DISPATCH_TIME_NOW,t*HGL_NANO_SEC_PER_SEC); - return !dispatch_semaphore_wait(ptr,when); - } + return !dispatch_semaphore_wait(ptr,when); } }//namespace hgl diff --git a/src/UNIX/CondVar.cpp b/src/UNIX/CondVar.cpp index 395133c..320b76d 100644 --- a/src/UNIX/CondVar.cpp +++ b/src/UNIX/CondVar.cpp @@ -10,13 +10,13 @@ namespace hgl { cond_var=new pthread_cond_t; - pthread_cond_init((pthread_cond_t *)cond_var,nullptr); + pthread_cond_init(cond_var,nullptr); } CondVar::~CondVar() { - pthread_cond_destroy((pthread_cond_t *)cond_var); - delete (pthread_cond_t *)cond_var; + pthread_cond_destroy(cond_var); + delete cond_var; } bool CondVar::Wait(ThreadMutex *tm,double t) @@ -27,21 +27,21 @@ namespace hgl GetWaitTime(abstime,t); - return(!pthread_cond_timedwait((pthread_cond_t *)cond_var,tm->GetThreadMutex(),&abstime)); + return(!pthread_cond_timedwait(cond_var,tm->GetThreadMutex(),&abstime)); } else { - return(!pthread_cond_wait((pthread_cond_t *)cond_var,tm->GetThreadMutex())); + return(!pthread_cond_wait(cond_var,tm->GetThreadMutex())); } } void CondVar::Signal() { - pthread_cond_signal((pthread_cond_t *)cond_var); + pthread_cond_signal(cond_var); } void CondVar::Broadcast() { - pthread_cond_broadcast((pthread_cond_t *)cond_var); + pthread_cond_broadcast(cond_var); } }//namespace hgl diff --git a/src/UNIX/EnumFile.cpp b/src/UNIX/EnumFile.cpp index 67c6b5c..f5b5548 100644 --- a/src/UNIX/EnumFile.cpp +++ b/src/UNIX/EnumFile.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -27,7 +27,7 @@ namespace hgl if(config->folder_name.IsEmpty()) { - fullname='.'; + fullname=OS_TEXT("."); } else { diff --git a/src/UNIX/ExternalModule.cpp b/src/UNIX/ExternalModule.cpp index bf1ccc4..4e3c212 100644 --- a/src/UNIX/ExternalModule.cpp +++ b/src/UNIX/ExternalModule.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include diff --git a/src/UNIX/Fifo.cpp b/src/UNIX/Fifo.cpp index 5ab161d..9ea17e4 100644 --- a/src/UNIX/Fifo.cpp +++ b/src/UNIX/Fifo.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include namespace hgl diff --git a/src/UNIX/File.cpp b/src/UNIX/File.cpp index 78b0910..4b2b822 100644 --- a/src/UNIX/File.cpp +++ b/src/UNIX/File.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -170,7 +170,7 @@ namespace hgl { if(!mkdir(name,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))return(true); - LOG_PROBLEM(OS_TEXT("Create Directory <")+OSString(name)+OS_TEXT("> failed,errno: ")+OSString(errno)); + LOG_PROBLEM(OS_TEXT("Create Directory <")+OSString(name)+OS_TEXT("> failed,errno: ")+OSString::valueOf(errno)); return(false); } diff --git a/src/UNIX/FileAccess.cpp b/src/UNIX/FileAccess.cpp index f695222..563a610 100644 --- a/src/UNIX/FileAccess.cpp +++ b/src/UNIX/FileAccess.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -35,13 +35,13 @@ namespace hgl if(fom==fomReadWrite )fp=hgl_open64(fn,O_RDWR );else if(fom==fomAppend )fp=hgl_open64(fn,O_APPEND );else { - LOG_ERROR(OS_TEXT("UNIX,FileAccess,OpenFile(")+OSString(fn)+OS_TEXT(" mode error: "+OSString(fom))); + LOG_ERROR(OS_TEXT("UNIX,FileAccess,OpenFile(")+OSString(fn)+OS_TEXT(" mode error: "+OSString::valueOf(fom))); RETURN_ERROR(-1); } if(fp==-1) { - LOG_ERROR(OS_TEXT("UNIX,FileAccess,OpenFile(")+OSString(fn)+OS_TEXT(") open return error: "+OSString(errno))); + LOG_ERROR(OS_TEXT("UNIX,FileAccess,OpenFile(")+OSString(fn)+OS_TEXT(") open return error: "+OSString::valueOf(errno))); } return fp; diff --git a/src/UNIX/LogConsole.cpp b/src/UNIX/LogConsole.cpp index 3946652..ad5e323 100644 --- a/src/UNIX/LogConsole.cpp +++ b/src/UNIX/LogConsole.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -115,7 +115,7 @@ namespace hgl } };//class LogInterface - Logger *CreateLoggerConsole(const OSString &,LogLevel ll) + Logger *CreateLoggerConsole(LogLevel ll) { if(ll -#include +#include #include #include @@ -14,10 +14,10 @@ namespace hgl { ptr=new sem_t; - if(sem_init((sem_t *)ptr,PTHREAD_PROCESS_PRIVATE,0)) + if(sem_init(ptr,PTHREAD_PROCESS_PRIVATE,0)) { - LOG_ERROR(OS_TEXT("sem_init error,max_count=")+OSString(max_count)); - delete (sem_t *)ptr; + LOG_ERROR(OS_TEXT("sem_init error,max_count=")+OSString::valueOf(max_count)); + delete ptr; ptr=nullptr; } } @@ -26,8 +26,8 @@ namespace hgl { if(!ptr)return; - sem_destroy((sem_t *)ptr); - delete (sem_t *)ptr; + sem_destroy(ptr); + delete ptr; } /** @@ -43,14 +43,14 @@ namespace hgl int result=0; for(int i=0;i #include -#include +#include #include #include -#include +#include namespace hgl { @@ -35,7 +35,7 @@ namespace hgl tp=0; pthread_attr_destroy(&attr); - LOG_ERROR(OS_TEXT("Create Thread (pthread_create) failed.errno:")+OSString(errno)); + LOG_ERROR(OS_TEXT("Create Thread (pthread_create) failed.errno:")+OSString::valueOf(errno)); return(false); } diff --git a/src/UNIX/XCBWindow.cpp b/src/UNIX/XCBWindow.cpp index f1209b5..851014b 100644 --- a/src/UNIX/XCBWindow.cpp +++ b/src/UNIX/XCBWindow.cpp @@ -91,6 +91,14 @@ namespace hgl win_name.Length(), win_name.c_str()); } + void XCBWindow::ToMinWindow() + { + } + + void XCBWindow::ToMaxWindow() + { + } + bool XCBWindow::MessageProc() { return(true); diff --git a/src/UNIX/XCBWindow.h b/src/UNIX/XCBWindow.h index 6df4f21..726b2d3 100644 --- a/src/UNIX/XCBWindow.h +++ b/src/UNIX/XCBWindow.h @@ -13,7 +13,6 @@ namespace hgl private: bool InitConnection(); - VkSurfaceKHR CreateSurface(VkInstance) override; public: @@ -32,6 +31,10 @@ namespace hgl void Show()override{} void Hide()override{} + + void ToMinWindow() override; + void ToMaxWindow() override; + bool MessageProc() override; bool WaitMessage() override; };//class XCBWindow:public Window diff --git a/src/Win/CondVar.cpp b/src/Win/CondVar.cpp index 49f2f43..095e3b6 100644 --- a/src/Win/CondVar.cpp +++ b/src/Win/CondVar.cpp @@ -8,31 +8,31 @@ namespace hgl CondVar::CondVar() { cond_var = new CONDITION_VARIABLE; - InitializeConditionVariable((CONDITION_VARIABLE *)cond_var); + InitializeConditionVariable(cond_var); } CondVar::~CondVar() { - delete (CONDITION_VARIABLE *)cond_var; + delete cond_var; } bool CondVar::Wait(ThreadMutex *tm, double time) { - return SleepConditionVariableCS((CONDITION_VARIABLE *)cond_var,(CRITICAL_SECTION *)(tm->GetThreadMutex()),(DWORD)(time>0?time*1000:INFINITE)); + return SleepConditionVariableCS(cond_var,tm->GetThreadMutex(),(DWORD)(time>0?time*1000:INFINITE)); } bool CondVar::Wait(RWLock *lock, double time, bool read) { - return SleepConditionVariableSRW((CONDITION_VARIABLE *)cond_var,(SRWLOCK *)(lock->GetRWLock()),(DWORD)(time>0?time*1000:INFINITE),read?CONDITION_VARIABLE_LOCKMODE_SHARED:0); + return SleepConditionVariableSRW(cond_var,lock->GetRWLock(),(DWORD)(time>0?time*1000:INFINITE),read?CONDITION_VARIABLE_LOCKMODE_SHARED:0); } void CondVar::Signal() { - WakeConditionVariable((CONDITION_VARIABLE *)cond_var); + WakeConditionVariable(cond_var); } void CondVar::Broadcast() { - WakeAllConditionVariable((CONDITION_VARIABLE *)cond_var); + WakeAllConditionVariable(cond_var); } }//namespace hgl diff --git a/src/Win/ProcMutex.cpp b/src/Win/ProcMutex.cpp index 403d341..582323e 100644 --- a/src/Win/ProcMutex.cpp +++ b/src/Win/ProcMutex.cpp @@ -1,5 +1,4 @@ #include -#include namespace hgl { diff --git a/src/Win/RWLock.cpp b/src/Win/RWLock.cpp index 3a1018b..c05aa56 100644 --- a/src/Win/RWLock.cpp +++ b/src/Win/RWLock.cpp @@ -1,4 +1,4 @@ -#include +#include #pragma warning(disable:4800) // BOOL -> bool 性能损失警告 namespace hgl @@ -7,19 +7,19 @@ namespace hgl { lock = new SRWLOCK; - InitializeSRWLock((SRWLOCK *)lock); + InitializeSRWLock(lock); } RWLock::~RWLock() { - delete (SRWLOCK *)lock; + delete lock; } - bool RWLock::TryReadLock() { return TryAcquireSRWLockShared((SRWLOCK *)lock); } - bool RWLock::ReadLock() { AcquireSRWLockShared((SRWLOCK *)lock); return(true); } - bool RWLock::ReadUnlock() { ReleaseSRWLockShared((SRWLOCK *)lock); return(true); } + bool RWLock::TryReadLock(){ return TryAcquireSRWLockShared(lock); } + bool RWLock::ReadLock (){ AcquireSRWLockShared(lock); return(true); } + bool RWLock::ReadUnlock (){ ReleaseSRWLockShared(lock); return(true); } - bool RWLock::TryWriteLock() { return TryAcquireSRWLockExclusive((SRWLOCK *)lock); } - bool RWLock::WriteLock() { AcquireSRWLockExclusive((SRWLOCK *)lock); return(true); } - bool RWLock::WriteUnlock() { ReleaseSRWLockExclusive((SRWLOCK *)lock); return(true); } + bool RWLock::TryWriteLock (){ return TryAcquireSRWLockExclusive(lock); } + bool RWLock::WriteLock (){ AcquireSRWLockExclusive(lock); return(true); } + bool RWLock::WriteUnlock (){ ReleaseSRWLockExclusive(lock); return(true); } }//namespace hgl diff --git a/src/Win/Semaphore.cpp b/src/Win/Semaphore.cpp index 0d8df8f..b0aece2 100644 --- a/src/Win/Semaphore.cpp +++ b/src/Win/Semaphore.cpp @@ -11,7 +11,7 @@ namespace hgl */ Semaphore::Semaphore(int max_count) { - ptr=CreateSemaphore(nullptr,0,max_count,nullptr); + ptr=CreateSemaphoreW(nullptr,0,max_count,nullptr); if(!ptr) LOG_ERROR(OS_TEXT("CreateSemaphore error,max_count=")+OSString::valueOf(max_count)); @@ -41,6 +41,15 @@ namespace hgl { return(WaitForSingleObject(ptr,0)==WAIT_OBJECT_0); } + + /** + * 等待并获取一个信号 + * @return 是否等待到了,如果超过最长时间,仍未等到即为超时,返回false + */ + bool Semaphore::Acquire() + { + return(WaitForSingleObject(ptr,INFINITE)==WAIT_OBJECT_0); + } /** * 等待并获取一个信号 diff --git a/src/Win/SystemInfo.cpp b/src/Win/SystemInfo.cpp index b26d4b6..839a399 100644 --- a/src/Win/SystemInfo.cpp +++ b/src/Win/SystemInfo.cpp @@ -1,6 +1,6 @@ -#include +#include //#include -#include +#include #include #include #include diff --git a/src/Win/WinMessage.cpp b/src/Win/WinMessage.cpp index 8e31e6f..4388d24 100644 --- a/src/Win/WinMessage.cpp +++ b/src/Win/WinMessage.cpp @@ -182,7 +182,7 @@ namespace hgl ::GetKeyNameTextW(key,name,64); - LOG_INFO(WideString(L"Unknow Key: " )+WideString(key) + LOG_INFO(WideString(L"Unknow Key: " )+WideString::valueOf(key) +WideString(L" ,name: " )+WideString(name)); } #endif _DEBUG