Merge branch 'master' of https://github.com/hyzboy/CMPlatform into HEAD
This commit is contained in:
commit
9b1975a8a5
@ -1,12 +1,8 @@
|
||||
#include<hgl/thread/Semaphore.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<pthread.h>
|
||||
#include<dispatch/dispatch.h>
|
||||
#include<hgl/thread/Semaphore.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/filesystem/EnumFile.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
@ -27,7 +27,7 @@ namespace hgl
|
||||
|
||||
if(config->folder_name.IsEmpty())
|
||||
{
|
||||
fullname='.';
|
||||
fullname=OS_TEXT(".");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include<hgl/platform/ExternalModule.h>
|
||||
#include<hgl/platform/Platform.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
#include<dlfcn.h>
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/proc/Fifo.h>
|
||||
#include<hgl/Str.h>
|
||||
#include<hgl/type/StrChar.h>
|
||||
#include<sys/stat.h>
|
||||
|
||||
namespace hgl
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/io/FileInputStream.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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/io/FileAccess.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<unistd.h>
|
||||
#include<stdlib.h>
|
||||
#include<fcntl.h>
|
||||
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/Logger.h>
|
||||
#include<hgl/log/Logger.h>
|
||||
#include<hgl/CodePage.h>
|
||||
#include<hgl/thread/ThreadMutex.h>
|
||||
#include<unistd.h>
|
||||
@ -115,7 +115,7 @@ namespace hgl
|
||||
}
|
||||
};//class LogInterface
|
||||
|
||||
Logger *CreateLoggerConsole(const OSString &,LogLevel ll)
|
||||
Logger *CreateLoggerConsole(LogLevel ll)
|
||||
{
|
||||
if(ll<llError)
|
||||
return(nullptr);
|
||||
|
@ -9,15 +9,15 @@ namespace hgl
|
||||
{
|
||||
lock=new pthread_rwlock_t;
|
||||
|
||||
pthread_rwlock_init((pthread_rwlock_t *)lock,nullptr);
|
||||
pthread_rwlock_init(lock,nullptr);
|
||||
}
|
||||
|
||||
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
|
||||
bool RWLock::WaitReadLock(double t)
|
||||
@ -26,14 +26,14 @@ namespace hgl
|
||||
|
||||
GetWaitTime(abstime,t);
|
||||
|
||||
return !pthread_rwlock_timedrdlock((pthread_rwlock_t *)lock,&abstime);
|
||||
return !pthread_rwlock_timedrdlock(lock,&abstime);
|
||||
}
|
||||
#endif//HGL_OS != HGL_OS_macOS
|
||||
|
||||
bool RWLock::ReadLock() {return !pthread_rwlock_rdlock((pthread_rwlock_t *)lock);}
|
||||
bool RWLock::ReadUnlock() {return !pthread_rwlock_unlock((pthread_rwlock_t *)lock);}
|
||||
bool RWLock::ReadLock() {return !pthread_rwlock_rdlock(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
|
||||
bool RWLock::WaitWriteLock(double t)
|
||||
@ -42,10 +42,10 @@ namespace hgl
|
||||
|
||||
GetWaitTime(abstime,t);
|
||||
|
||||
return !pthread_rwlock_timedwrlock((pthread_rwlock_t *)lock,&abstime);
|
||||
return !pthread_rwlock_timedwrlock(lock,&abstime);
|
||||
}
|
||||
#endif//HGL_OS != HGL_OS_macOS
|
||||
|
||||
bool RWLock::WriteLock() {return !pthread_rwlock_wrlock((pthread_rwlock_t *)lock);}
|
||||
bool RWLock::WriteUnlock() {return !pthread_rwlock_unlock((pthread_rwlock_t *)lock);}
|
||||
bool RWLock::WriteLock() {return !pthread_rwlock_wrlock(lock);}
|
||||
bool RWLock::WriteUnlock() {return !pthread_rwlock_unlock(lock);}
|
||||
}//namespace hgl
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include<hgl/thread/Semaphore.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<pthread.h>
|
||||
#include<semaphore.h>
|
||||
|
||||
@ -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<n;i++)
|
||||
result+=sem_post((sem_t *)ptr);
|
||||
result+=sem_post(ptr);
|
||||
|
||||
return !result;
|
||||
|
||||
//if(n==1)
|
||||
// return !sem_post((sem_t *)ptr);
|
||||
// return !sem_post(ptr);
|
||||
//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);
|
||||
|
||||
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(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
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include<hgl/thread/Thread.h>
|
||||
#include<hgl/thread/CondVar.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<signal.h>
|
||||
#include<errno.h>
|
||||
#include<hgl/Str.h>
|
||||
#include<hgl/type/StrChar.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,14 @@ namespace hgl
|
||||
win_name.Length(), win_name.c_str());
|
||||
}
|
||||
|
||||
void XCBWindow::ToMinWindow()
|
||||
{
|
||||
}
|
||||
|
||||
void XCBWindow::ToMaxWindow()
|
||||
{
|
||||
}
|
||||
|
||||
bool XCBWindow::MessageProc()
|
||||
{
|
||||
return(true);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include<hgl/proc/ProcMutex.h>
|
||||
#include<windows.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include<hgl/thread/RWLock.h>
|
||||
#include<hgl/thread/RWLock.h>
|
||||
|
||||
#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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 等待并获取一个信号
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include<hgl/platform/SystemInfo.h>
|
||||
#include<hgl/platform/SystemInfo.h>
|
||||
//#include<hgl/platform/ConsoleSystemInitInfo.h>
|
||||
#include<hgl/LogInfo.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/PlugIn.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<wchar.h>
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user