CtrlCore: Coco WakeupGuiThread, fixed Semaphore

git-svn-id: svn://ultimatepp.org/upp/trunk@12147 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2018-08-05 09:13:09 +00:00
parent 4918f43375
commit e9b8fe3453
6 changed files with 52 additions and 7 deletions

View file

@ -91,6 +91,9 @@
#else
#include <stdint.h>
#endif
#ifdef PLATFORM_OSX
#include <dispatch/dispatch.h>
#endif
#endif //PLATFORM_POSIX
#ifdef PLATFORM_POSIX

View file

@ -611,6 +611,30 @@ RWMutex::~RWMutex()
pthread_rwlock_destroy(rwlock);
}
#ifdef PLATFORM_OSX
void Semaphore::Release()
{
dispatch_semaphore_signal(sem);
}
void Semaphore::Wait()
{
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
}
Semaphore::Semaphore()
{
sem = dispatch_semaphore_create(0);
}
Semaphore::~Semaphore()
{
dispatch_release(sem);
}
#else
void Semaphore::Release()
{
sem_post(&sem);
@ -633,6 +657,8 @@ Semaphore::~Semaphore()
#endif
#endif
void LazyUpdate::Invalidate()
{
dirty.store(true, std::memory_order_release);

View file

@ -119,6 +119,8 @@ inline void AssertST() { ASSERT(Thread::IsST()); }
class Semaphore : NoCopy {
#ifdef PLATFORM_WIN32
HANDLE handle;
#elif PLATFORM_OSX
dispatch_semaphore_t sem;
#else
sem_t sem;
#endif

View file

@ -84,12 +84,15 @@ bool Upp::Ctrl::ProcessEvent(bool *)
ASSERT(IsMainThread());
Upp::AutoreleasePool __;
ONCELOCK {
[NSApp finishLaunching];
}
NSEvent *event = GetNextEvent(nil);
// DLOG("ProcessEvent " << ToString(event.description));
if(!event)
return false;
@ -152,12 +155,29 @@ void Upp::Ctrl::EventLoop(Ctrl *ctrl)
LLOG("Leaving event loop ");
}
static std::atomic<bool> sGuiSleep;
void Upp::Ctrl::GuiSleep(int ms)
{
ASSERT(IsMainThread());
sGuiSleep = true;
GetNextEvent([NSDate dateWithTimeIntervalSinceNow:ms / 1000.0]);
sGuiSleep = false;
}
namespace Upp {
void WakeUpGuiThread(void)
{
if(sGuiSleep) {
sGuiSleep = false;
[NSApp postEvent:[NSEvent otherEventWithType:NSEventTypeApplicationDefined
location:NSMakePoint(0, 0) modifierFlags:0 timestamp:0.0
windowNumber:0 context:nil subtype: 0 data1:0 data2:0]
atStart:YES];
}
}
};
void Upp::Ctrl::AnimateCaret()
{
GuiLock __;

View file

@ -10,11 +10,6 @@ void ChHostSkin(void)
{
}
void WakeUpGuiThread(void)
{
}
void Ctrl::GuiPlatformConstruct()
{
}

View file

@ -74,7 +74,6 @@ struct Ctrl::CallBox {
void Ctrl::PerformCall(Ctrl::CallBox *cbox)
{
cbox->cb();
LLOG("Sem release");
cbox->sem.Release();
}