Merge branch 'master' of https://github.com/hyzboy/CMPlatform into HEAD

This commit is contained in:
hyzboy 2020-06-18 09:53:04 +08:00
commit 9b1975a8a5
19 changed files with 111 additions and 86 deletions

View File

@ -1,12 +1,8 @@
#include<hgl/thread/Semaphore.h> #include<hgl/thread/Semaphore.h>
#include<hgl/LogInfo.h> #include<hgl/log/LogInfo.h>
#include<pthread.h>
#include<dispatch/dispatch.h>
namespace hgl namespace hgl
{ {
void GetWaitTime(struct timespec &,double);
/** /**
* @param max_count * @param max_count
*/ */
@ -52,7 +48,18 @@ namespace hgl
{ {
if(!ptr)return(false); 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(!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 }//namespace hgl

View File

@ -10,13 +10,13 @@ namespace hgl
{ {
cond_var=new pthread_cond_t; cond_var=new pthread_cond_t;
pthread_cond_init((pthread_cond_t *)cond_var,nullptr); pthread_cond_init(cond_var,nullptr);
} }
CondVar::~CondVar() CondVar::~CondVar()
{ {
pthread_cond_destroy((pthread_cond_t *)cond_var); pthread_cond_destroy(cond_var);
delete (pthread_cond_t *)cond_var; delete cond_var;
} }
bool CondVar::Wait(ThreadMutex *tm,double t) bool CondVar::Wait(ThreadMutex *tm,double t)
@ -27,21 +27,21 @@ namespace hgl
GetWaitTime(abstime,t); 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 else
{ {
return(!pthread_cond_wait((pthread_cond_t *)cond_var,tm->GetThreadMutex())); return(!pthread_cond_wait(cond_var,tm->GetThreadMutex()));
} }
} }
void CondVar::Signal() void CondVar::Signal()
{ {
pthread_cond_signal((pthread_cond_t *)cond_var); pthread_cond_signal(cond_var);
} }
void CondVar::Broadcast() void CondVar::Broadcast()
{ {
pthread_cond_broadcast((pthread_cond_t *)cond_var); pthread_cond_broadcast(cond_var);
} }
}//namespace hgl }//namespace hgl

View File

@ -1,5 +1,5 @@
#include<hgl/filesystem/EnumFile.h> #include<hgl/filesystem/EnumFile.h>
#include<hgl/LogInfo.h> #include<hgl/log/LogInfo.h>
#include<unistd.h> #include<unistd.h>
#include<stdlib.h> #include<stdlib.h>
#include<stdio.h> #include<stdio.h>
@ -27,7 +27,7 @@ namespace hgl
if(config->folder_name.IsEmpty()) if(config->folder_name.IsEmpty())
{ {
fullname='.'; fullname=OS_TEXT(".");
} }
else else
{ {

View File

@ -1,6 +1,6 @@
#include<hgl/platform/ExternalModule.h> #include<hgl/platform/ExternalModule.h>
#include<hgl/platform/Platform.h> #include<hgl/platform/Platform.h>
#include<hgl/LogInfo.h> #include<hgl/log/LogInfo.h>
#include<dlfcn.h> #include<dlfcn.h>

View File

@ -1,5 +1,5 @@
#include<hgl/proc/Fifo.h> #include<hgl/proc/Fifo.h>
#include<hgl/Str.h> #include<hgl/type/StrChar.h>
#include<sys/stat.h> #include<sys/stat.h>
namespace hgl namespace hgl

View File

@ -1,5 +1,5 @@
#include<hgl/filesystem/FileSystem.h> #include<hgl/filesystem/FileSystem.h>
#include<hgl/LogInfo.h> #include<hgl/log/LogInfo.h>
#include<hgl/io/FileInputStream.h> #include<hgl/io/FileInputStream.h>
#include<hgl/io/FileOutputStream.h> #include<hgl/io/FileOutputStream.h>
@ -170,7 +170,7 @@ namespace hgl
{ {
if(!mkdir(name,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH))return(true); 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); return(false);
} }

View File

@ -1,5 +1,5 @@
#include<hgl/io/FileAccess.h> #include<hgl/io/FileAccess.h>
#include<hgl/LogInfo.h> #include<hgl/log/LogInfo.h>
#include<unistd.h> #include<unistd.h>
#include<stdlib.h> #include<stdlib.h>
#include<fcntl.h> #include<fcntl.h>
@ -35,13 +35,13 @@ namespace hgl
if(fom==fomReadWrite )fp=hgl_open64(fn,O_RDWR );else if(fom==fomReadWrite )fp=hgl_open64(fn,O_RDWR );else
if(fom==fomAppend )fp=hgl_open64(fn,O_APPEND );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); RETURN_ERROR(-1);
} }
if(fp==-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; return fp;

View File

@ -1,4 +1,4 @@
#include<hgl/Logger.h> #include<hgl/log/Logger.h>
#include<hgl/CodePage.h> #include<hgl/CodePage.h>
#include<hgl/thread/ThreadMutex.h> #include<hgl/thread/ThreadMutex.h>
#include<unistd.h> #include<unistd.h>
@ -115,7 +115,7 @@ namespace hgl
} }
};//class LogInterface };//class LogInterface
Logger *CreateLoggerConsole(const OSString &,LogLevel ll) Logger *CreateLoggerConsole(LogLevel ll)
{ {
if(ll<llError) if(ll<llError)
return(nullptr); return(nullptr);

View File

@ -9,15 +9,15 @@ namespace hgl
{ {
lock=new pthread_rwlock_t; lock=new pthread_rwlock_t;
pthread_rwlock_init((pthread_rwlock_t *)lock,nullptr); pthread_rwlock_init(lock,nullptr);
} }
RWLock::~RWLock() RWLock::~RWLock()
{ {
pthread_rwlock_destroy((pthread_rwlock_t *)lock); pthread_rwlock_destroy(lock);
} }
bool RWLock::TryReadLock() {return !pthread_rwlock_tryrdlock((pthread_rwlock_t *)lock);} bool RWLock::TryReadLock() {return !pthread_rwlock_tryrdlock(lock);}
#if HGL_OS != HGL_OS_macOS #if HGL_OS != HGL_OS_macOS
bool RWLock::WaitReadLock(double t) bool RWLock::WaitReadLock(double t)
@ -26,14 +26,14 @@ namespace hgl
GetWaitTime(abstime,t); GetWaitTime(abstime,t);
return !pthread_rwlock_timedrdlock((pthread_rwlock_t *)lock,&abstime); return !pthread_rwlock_timedrdlock(lock,&abstime);
} }
#endif//HGL_OS != HGL_OS_macOS #endif//HGL_OS != HGL_OS_macOS
bool RWLock::ReadLock() {return !pthread_rwlock_rdlock((pthread_rwlock_t *)lock);} bool RWLock::ReadLock() {return !pthread_rwlock_rdlock(lock);}
bool RWLock::ReadUnlock() {return !pthread_rwlock_unlock((pthread_rwlock_t *)lock);} bool RWLock::ReadUnlock() {return !pthread_rwlock_unlock(lock);}
bool RWLock::TryWriteLock() {return !pthread_rwlock_trywrlock((pthread_rwlock_t *)lock);} bool RWLock::TryWriteLock() {return !pthread_rwlock_trywrlock(lock);}
#if HGL_OS != HGL_OS_macOS #if HGL_OS != HGL_OS_macOS
bool RWLock::WaitWriteLock(double t) bool RWLock::WaitWriteLock(double t)
@ -42,10 +42,10 @@ namespace hgl
GetWaitTime(abstime,t); GetWaitTime(abstime,t);
return !pthread_rwlock_timedwrlock((pthread_rwlock_t *)lock,&abstime); return !pthread_rwlock_timedwrlock(lock,&abstime);
} }
#endif//HGL_OS != HGL_OS_macOS #endif//HGL_OS != HGL_OS_macOS
bool RWLock::WriteLock() {return !pthread_rwlock_wrlock((pthread_rwlock_t *)lock);} bool RWLock::WriteLock() {return !pthread_rwlock_wrlock(lock);}
bool RWLock::WriteUnlock() {return !pthread_rwlock_unlock((pthread_rwlock_t *)lock);} bool RWLock::WriteUnlock() {return !pthread_rwlock_unlock(lock);}
}//namespace hgl }//namespace hgl

View File

@ -1,5 +1,5 @@
#include<hgl/thread/Semaphore.h> #include<hgl/thread/Semaphore.h>
#include<hgl/LogInfo.h> #include<hgl/log/LogInfo.h>
#include<pthread.h> #include<pthread.h>
#include<semaphore.h> #include<semaphore.h>
@ -14,10 +14,10 @@ namespace hgl
{ {
ptr=new sem_t; 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)); LOG_ERROR(OS_TEXT("sem_init error,max_count=")+OSString::valueOf(max_count));
delete (sem_t *)ptr; delete ptr;
ptr=nullptr; ptr=nullptr;
} }
} }
@ -26,8 +26,8 @@ namespace hgl
{ {
if(!ptr)return; if(!ptr)return;
sem_destroy((sem_t *)ptr); sem_destroy(ptr);
delete (sem_t *)ptr; delete ptr;
} }
/** /**
@ -43,14 +43,14 @@ namespace hgl
int result=0; int result=0;
for(int i=0;i<n;i++) for(int i=0;i<n;i++)
result+=sem_post((sem_t *)ptr); result+=sem_post(ptr);
return !result; return !result;
//if(n==1) //if(n==1)
// return !sem_post((sem_t *)ptr); // return !sem_post(ptr);
//else //else
// return !sem_post_multiple((sem_t *)ptr,n); //注这个函数不是所有os都支持 // return !sem_post_multiple(ptr,n); //注这个函数不是所有os都支持
} }
/** /**
@ -61,7 +61,18 @@ namespace hgl
{ {
if(!ptr)return(false); if(!ptr)return(false);
return !sem_trywait((sem_t *)ptr); return !sem_trywait(ptr);
}
/**
*
* @return ,,,false
*/
bool Semaphore::Acquire()
{
if(!ptr)return(false);
return !sem_wait(ptr);
} }
/** /**
@ -73,15 +84,10 @@ namespace hgl
{ {
if(!ptr)return(false); if(!ptr)return(false);
if(t<=0)
return !sem_wait((sem_t *)ptr);
else
{
struct timespec abstime; struct timespec abstime;
GetWaitTime(abstime,t); GetWaitTime(abstime,t);
return !sem_timedwait((sem_t *)ptr,&abstime); return !sem_timedwait(ptr,&abstime);
}
} }
}//namespace hgl }//namespace hgl

View File

@ -1,9 +1,9 @@
#include<hgl/thread/Thread.h> #include<hgl/thread/Thread.h>
#include<hgl/thread/CondVar.h> #include<hgl/thread/CondVar.h>
#include<hgl/LogInfo.h> #include<hgl/log/LogInfo.h>
#include<signal.h> #include<signal.h>
#include<errno.h> #include<errno.h>
#include<hgl/Str.h> #include<hgl/type/StrChar.h>
namespace hgl namespace hgl
{ {
@ -35,7 +35,7 @@ namespace hgl
tp=0; tp=0;
pthread_attr_destroy(&attr); 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); return(false);
} }

View File

@ -91,6 +91,14 @@ namespace hgl
win_name.Length(), win_name.c_str()); win_name.Length(), win_name.c_str());
} }
void XCBWindow::ToMinWindow()
{
}
void XCBWindow::ToMaxWindow()
{
}
bool XCBWindow::MessageProc() bool XCBWindow::MessageProc()
{ {
return(true); return(true);

View File

@ -13,7 +13,6 @@ namespace hgl
private: private:
bool InitConnection(); bool InitConnection();
VkSurfaceKHR CreateSurface(VkInstance) override;
public: public:
@ -32,6 +31,10 @@ namespace hgl
void Show()override{} void Show()override{}
void Hide()override{} void Hide()override{}
void ToMinWindow() override;
void ToMaxWindow() override;
bool MessageProc() override; bool MessageProc() override;
bool WaitMessage() override; bool WaitMessage() override;
};//class XCBWindow:public Window };//class XCBWindow:public Window

View File

@ -8,31 +8,31 @@ namespace hgl
CondVar::CondVar() CondVar::CondVar()
{ {
cond_var = new CONDITION_VARIABLE; cond_var = new CONDITION_VARIABLE;
InitializeConditionVariable((CONDITION_VARIABLE *)cond_var); InitializeConditionVariable(cond_var);
} }
CondVar::~CondVar() CondVar::~CondVar()
{ {
delete (CONDITION_VARIABLE *)cond_var; delete cond_var;
} }
bool CondVar::Wait(ThreadMutex *tm, double time) 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) 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() void CondVar::Signal()
{ {
WakeConditionVariable((CONDITION_VARIABLE *)cond_var); WakeConditionVariable(cond_var);
} }
void CondVar::Broadcast() void CondVar::Broadcast()
{ {
WakeAllConditionVariable((CONDITION_VARIABLE *)cond_var); WakeAllConditionVariable(cond_var);
} }
}//namespace hgl }//namespace hgl

View File

@ -1,5 +1,4 @@
#include<hgl/proc/ProcMutex.h> #include<hgl/proc/ProcMutex.h>
#include<windows.h>
namespace hgl namespace hgl
{ {

View File

@ -1,4 +1,4 @@
#include<hgl/thread/RWLock.h> #include<hgl/thread/RWLock.h>
#pragma warning(disable:4800) // BOOL -> bool 性能损失警告 #pragma warning(disable:4800) // BOOL -> bool 性能损失警告
namespace hgl namespace hgl
@ -7,19 +7,19 @@ namespace hgl
{ {
lock = new SRWLOCK; lock = new SRWLOCK;
InitializeSRWLock((SRWLOCK *)lock); InitializeSRWLock(lock);
} }
RWLock::~RWLock() RWLock::~RWLock()
{ {
delete (SRWLOCK *)lock; delete lock;
} }
bool RWLock::TryReadLock() { return TryAcquireSRWLockShared((SRWLOCK *)lock); } bool RWLock::TryReadLock(){ return TryAcquireSRWLockShared(lock); }
bool RWLock::ReadLock() { AcquireSRWLockShared((SRWLOCK *)lock); return(true); } bool RWLock::ReadLock (){ AcquireSRWLockShared(lock); return(true); }
bool RWLock::ReadUnlock() { ReleaseSRWLockShared((SRWLOCK *)lock); return(true); } bool RWLock::ReadUnlock (){ ReleaseSRWLockShared(lock); return(true); }
bool RWLock::TryWriteLock() { return TryAcquireSRWLockExclusive((SRWLOCK *)lock); } bool RWLock::TryWriteLock (){ return TryAcquireSRWLockExclusive(lock); }
bool RWLock::WriteLock() { AcquireSRWLockExclusive((SRWLOCK *)lock); return(true); } bool RWLock::WriteLock (){ AcquireSRWLockExclusive(lock); return(true); }
bool RWLock::WriteUnlock() { ReleaseSRWLockExclusive((SRWLOCK *)lock); return(true); } bool RWLock::WriteUnlock (){ ReleaseSRWLockExclusive(lock); return(true); }
}//namespace hgl }//namespace hgl

View File

@ -11,7 +11,7 @@ namespace hgl
*/ */
Semaphore::Semaphore(int max_count) Semaphore::Semaphore(int max_count)
{ {
ptr=CreateSemaphore(nullptr,0,max_count,nullptr); ptr=CreateSemaphoreW(nullptr,0,max_count,nullptr);
if(!ptr) if(!ptr)
LOG_ERROR(OS_TEXT("CreateSemaphore error,max_count=")+OSString::valueOf(max_count)); LOG_ERROR(OS_TEXT("CreateSemaphore error,max_count=")+OSString::valueOf(max_count));
@ -42,6 +42,15 @@ namespace hgl
return(WaitForSingleObject(ptr,0)==WAIT_OBJECT_0); return(WaitForSingleObject(ptr,0)==WAIT_OBJECT_0);
} }
/**
*
* @return ,,,false
*/
bool Semaphore::Acquire()
{
return(WaitForSingleObject(ptr,INFINITE)==WAIT_OBJECT_0);
}
/** /**
* *
* @param time ,使0.() * @param time ,使0.()

View File

@ -1,6 +1,6 @@
#include<hgl/platform/SystemInfo.h> #include<hgl/platform/SystemInfo.h>
//#include<hgl/platform/ConsoleSystemInitInfo.h> //#include<hgl/platform/ConsoleSystemInitInfo.h>
#include<hgl/LogInfo.h> #include<hgl/log/LogInfo.h>
#include<hgl/PlugIn.h> #include<hgl/PlugIn.h>
#include<hgl/filesystem/FileSystem.h> #include<hgl/filesystem/FileSystem.h>
#include<wchar.h> #include<wchar.h>

View File

@ -182,7 +182,7 @@ namespace hgl
::GetKeyNameTextW(key,name,64); ::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)); +WideString(L" ,name: " )+WideString(name));
} }
#endif _DEBUG #endif _DEBUG