From 1f05e55379b5eb1deb7e29447d1a9c22c867f2f3 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 3 Oct 2008 00:56:17 +0200 Subject: [PATCH] Remove CSDL::EOwnThread. Remove possibility of running SDL and application in separate threads. --- SDL.kdevelop.filelist | 1 - src/main/symbian/SDL_main.cpp | 156 +++++------------------------------ src/main/symbian/sdllibt.cpp | 8 -- src/video/symbian/SDL_epocevents.cpp | 7 -- symbian/include/internal/epoc_sdl.h | 4 - symbian/include/sdlepocapi.h | 2 - 6 files changed, 19 insertions(+), 159 deletions(-) delete mode 100644 src/main/symbian/sdllibt.cpp diff --git a/SDL.kdevelop.filelist b/SDL.kdevelop.filelist index 9329886..dfe1be1 100644 --- a/SDL.kdevelop.filelist +++ b/SDL.kdevelop.filelist @@ -107,7 +107,6 @@ src/main/symbian/SDL_main.cpp src/main/symbian/debug.cpp src/main/symbian/sdlexe.cpp src/main/symbian/sdllib.cpp -src/main/symbian/sdllibt.cpp src/stdlib src/stdlib/SDL_getenv.c src/stdlib/SDL_iconv.c diff --git a/src/main/symbian/SDL_main.cpp b/src/main/symbian/SDL_main.cpp index 603a29c..5f3e752 100644 --- a/src/main/symbian/SDL_main.cpp +++ b/src/main/symbian/SDL_main.cpp @@ -54,28 +54,18 @@ EpocSdlEnvData* gEpocEnv; class EnvUtils { public: - static inline TBool IsOwnThreaded(); - static TBool Rendezvous(RThread& aThread, TRequestStatus& aStatus); static void RunSingleThread(); }; -inline TBool EnvUtils::IsOwnThreaded() -{ - return gEpocEnv->iEpocEnvFlags & CSDL::EOwnThread; -} - void EnvUtils::RunSingleThread() { - if(!EnvUtils::IsOwnThreaded()) + int count = RThread().RequestCount(); + if(count > 0) { - int count = RThread().RequestCount(); - if(count > 0) - { - int err; - if(CActiveScheduler::RunIfReady(err, CActive::EPriorityIdle)) - { - CActiveScheduler::Current()->WaitForAnyRequest(); - } + int err; + if(CActiveScheduler::RunIfReady(err, CActive::EPriorityIdle)) + { + CActiveScheduler::Current()->WaitForAnyRequest(); } } } @@ -96,53 +86,32 @@ class CEventQueue : public CBase, public MEventQueue ~CEventQueue(); int Append(const TWsEvent& aEvent); const TWsEvent Shift(); - void Lock(); - void Unlock(); TBool HasData(); private: std::queue m_queue; - RCriticalSection iCS; }; void CEventQueue::ConstructL() { - if(EnvUtils::IsOwnThreaded()) - User::LeaveIfError(iCS.CreateLocal()); } CEventQueue::~CEventQueue() { - iCS.Close(); } int CEventQueue::Append(const TWsEvent& aEvent) { - Lock(); m_queue.push(aEvent); - Unlock(); return 0; } - TBool CEventQueue::HasData() { EnvUtils::RunSingleThread(); return !m_queue.empty(); } -void CEventQueue::Lock() -{ - if(EnvUtils::IsOwnThreaded()) - iCS.Wait(); -} - -void CEventQueue::Unlock() -{ - if(EnvUtils::IsOwnThreaded()) - iCS.Signal(); -} - const TWsEvent CEventQueue::Shift() { const TWsEvent event = m_queue.front(); @@ -211,7 +180,6 @@ class CSdlAppServ : public CActive RThread iAppThread; int iService; int iReturnValue; - RSemaphore iSema; MSDLObserver* iObserver; TRequestStatus* iStatusPtr; }; @@ -234,11 +202,7 @@ int CSdlAppServ::ObserverEvent(int aEvent, int aParam) { if(iObserver != NULL) { - if(RThread().Id() == gEpocEnv->iId && EnvUtils::IsOwnThreaded()) - { - return iObserver->SdlThreadEvent(aEvent, aParam); - } - else if(RThread().Id() == iMainId) + if(RThread().Id() == iMainId) { return iObserver->SdlEvent(aEvent, aParam); } @@ -260,8 +224,6 @@ void CSdlAppServ::PanicMain(const TDesC& aInfo, int aReason) void CSdlAppServ::ConstructL() { CActiveScheduler::Add(this); - if(EnvUtils::IsOwnThreaded()) - User::LeaveIfError(iSema.CreateLocal(1)); iStatus = KRequestPending; iStatusPtr = &iStatus; SetActive(); @@ -270,20 +232,11 @@ void CSdlAppServ::ConstructL() CSdlAppServ::~CSdlAppServ() { Cancel(); - if(iSema.Handle() != NULL) - iSema.Signal(); - iSema.Close(); iAppThread.Close(); } int CSdlAppServ::Request(int aService) { - if(EnvUtils::IsOwnThreaded()) - { - if(RThread().Id() == iAppThread.Id()) - return KErrBadHandle; - iSema.Wait(); - } EnvUtils::RunSingleThread(); iService = aService; iAppThread.RequestComplete(iStatusPtr, KErrNone); @@ -366,15 +319,10 @@ void CSdlAppServ::RunL() iStatusPtr = &iStatus; SetActive(); } - - if(EnvUtils::IsOwnThreaded()) - iSema.Signal(); } void CSdlAppServ::DoCancel() { - if(EnvUtils::IsOwnThreaded()) - iSema.Wait(); TRequestStatus* s = &iStatus; iAppThread.RequestComplete(s, KErrCancel); } @@ -425,11 +373,6 @@ void EpocSdlEnv::Suspend() if(gEpocEnv->iDsa != NULL && (gEpocEnv->iDsa->Stopped() || EpocSdlEnv::Flags(CSDL::EEnableFocusStop))) { gEpocEnv->iDsa->SetSuspend(); - if(EnvUtils::IsOwnThreaded()) - { - RThread().Suspend(); - EpocSdlEnv::ObserverEvent(MSDLObserver::EEventResume, 0); - } } } @@ -437,13 +380,6 @@ void EpocSdlEnv::SetWaitDsa() { if(!IsDsaAvailable()) { - if(EnvUtils::IsOwnThreaded()) - { - RThread th; - th.Open(gEpocEnv->iId); - th.Suspend(); - th.Close(); - } if(gEpocEnv->iDsa != NULL) gEpocEnv->iDsa->SetSuspend(); } @@ -455,13 +391,7 @@ void EpocSdlEnv::Resume() { gEpocEnv->iDsa->Resume(); } - if(EnvUtils::IsOwnThreaded()) - { - RThread th; - th.Open(gEpocEnv->iId); - th.Resume(); - th.Close(); - } + const int value = gEpocEnv->iAppSrv->ObserverEvent(MSDLObserver::EEventResume, 0); gEpocEnv->iAppSrv->HandleObserverValue(MSDLObserver::EEventResume, value, ETrue); } @@ -533,7 +463,7 @@ void EpocSdlEnv::RemoveCleanupItem(TAny* aItem) } } -void EpocSdlEnv::CleanupItems() +void EpocSdlEnv::CleanupItems() { const TThreadId id = RThread().Id(); int last = gEpocEnv->iCleanupItems->Count() - 1; @@ -594,7 +524,7 @@ void EpocSdlEnv::WaitDeviceChange() gEpocEnv->iAppSrv->RequestValue(CSdlAppServ::EAppSrvWaitDsa); } -LOCAL_C TBool CheckSdl() +LOCAL_C TBool CheckSdl() { int isExit = ETrue; RThread sdl; @@ -692,27 +622,11 @@ LOCAL_C int MainL() LOCAL_C int DoMain(TAny* /*aParam*/) { TBool fbsconnected = EFalse; - CTrapCleanup* cleanup = NULL; - - if(EnvUtils::IsOwnThreaded()) - { - cleanup = CTrapCleanup::New(); - if(RFbsSession::GetSession() == NULL) - { - PANIC_IF_ERROR(RFbsSession::Connect()); - fbsconnected = ETrue; - } - } gEpocEnv->iAppSrv->Init(); // Call stdlib main int ret = 0; - if(EnvUtils::IsOwnThreaded()) - { - //completes waiting rendesvous - RThread::Rendezvous(KErrNone); - } TRAPD(err, err = MainL()); @@ -730,8 +644,6 @@ LOCAL_C int DoMain(TAny* /*aParam*/) if(fbsconnected) RFbsSession::Disconnect(); - delete cleanup; - if(gEpocEnv->iCallerStatus != NULL) { User::RequestComplete(gEpocEnv->iCallerStatus, err); @@ -846,32 +758,14 @@ EXPORT_C TThreadId CSDL::CallMainL(const TMainFunc& aFunc, TRequestStatus* const CRemConCoreApiTarget::NewL( *iSelector, *this ); iSelector->OpenTargetL(); - if(EnvUtils::IsOwnThreaded()) - { - RThread thread; - User::LeaveIfError(thread.Create(KSDLMain, DoMain, aStackSize, NULL, NULL)); - - if(aStatus != NULL) - { - thread.Logon(*aStatus); - } - - gEpocEnv->iId = thread.Id(); - thread.SetPriority(EPriorityLess); - thread.Resume(); - thread.Close(); - } - else - { - gEpocEnv->iCallerStatus = aStatus; - if(aStatus != NULL) - *aStatus = KRequestPending; - gEpocEnv->iId = RThread().Id(); - // when priority is not lowered screen updates much more frequently, which - // may be undesired, for example in case of openttd's generating world dialog - RThread().SetPriority(EPriorityLess); - DoMain( NULL ); - } + gEpocEnv->iCallerStatus = aStatus; + if(aStatus != NULL) + *aStatus = KRequestPending; + gEpocEnv->iId = RThread().Id(); + // when priority is not lowered screen updates much more frequently, which + // may be undesired, for example in case of openttd's generating world dialog + RThread().SetPriority(EPriorityLess); + DoMain( NULL ); return gEpocEnv->iId; } @@ -917,7 +811,7 @@ EXPORT_C int CSDL::SetSDLCode(int aScanCode, int aSDLCode) EXPORT_C MSDLObserver* CSDL::Observer() { return gEpocEnv->iAppSrv->Observer(); -} +} EXPORT_C void CSDL::SetObserver(MSDLObserver* aObserver) { @@ -984,18 +878,6 @@ void CSDL::MrccatoCommand(TRemConCoreApiOperationId aOperationId, TRemConCoreApi } } -TBool EnvUtils::Rendezvous(RThread& aThread, TRequestStatus& aStatus) -{ - if(gEpocEnv->iId != TThreadId(0) && - aThread.Open(gEpocEnv->iId) && - aThread.ExitType() == EExitPending) - { - aThread.Rendezvous(aStatus); - return ETrue; - } - return EFalse; -} - void* SDL_LoadObject(const char *sofile) { RLibrary* lib = new RLibrary(); diff --git a/src/main/symbian/sdllibt.cpp b/src/main/symbian/sdllibt.cpp deleted file mode 100644 index 7a0f4a8..0000000 --- a/src/main/symbian/sdllibt.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include - -GLREF_C int E32Main() -{ - return SDLEnv::SetMain(SDL_main, CSDL::EOwnThread | CSDL::EEnableFocusStop, NULL, SDLEnv::EParamQuery); -} diff --git a/src/video/symbian/SDL_epocevents.cpp b/src/video/symbian/SDL_epocevents.cpp index 80fa5e8..552f327 100644 --- a/src/video/symbian/SDL_epocevents.cpp +++ b/src/video/symbian/SDL_epocevents.cpp @@ -224,14 +224,7 @@ extern "C" { MEventQueue& events = EpocSdlEnv::EventQueue(); while(events.HasData()) { - events.Lock(); - - //there have to be a copy, so we can release - //lock immediately. HandleWsEvent may cause - //deadlock otherwise. - const TWsEvent event = events.Shift(); - events.Unlock(); EPOC_HandleWsEvent(_this, event); } } diff --git a/symbian/include/internal/epoc_sdl.h b/symbian/include/internal/epoc_sdl.h index 7222f91..00a7b65 100644 --- a/symbian/include/internal/epoc_sdl.h +++ b/symbian/include/internal/epoc_sdl.h @@ -17,12 +17,8 @@ class MEventQueue { public: virtual TInt Append(const TWsEvent& aEvent) = 0; - // virtual const TWsEvent& Top() = 0; virtual TBool HasData() = 0; - // virtual TInt Shift() = 0; virtual const TWsEvent Shift() = 0; - virtual void Lock() = 0; - virtual void Unlock() = 0; }; typedef void (*TSdlCleanupOperation) (TAny* aThis); diff --git a/symbian/include/sdlepocapi.h b/symbian/include/sdlepocapi.h index 3de67bc..20c20d1 100644 --- a/symbian/include/sdlepocapi.h +++ b/symbian/include/sdlepocapi.h @@ -65,7 +65,6 @@ class MSDLObserver ESuspendNoSuspend //after EEventSuspend, prevents the suspend. }; virtual TInt SdlEvent(TInt aEvent, TInt aParam) = 0; //event is called in application thread - virtual TInt SdlThreadEvent(TInt aEvent, TInt aParam) = 0; //event is called in SDL thread }; @@ -76,7 +75,6 @@ class CSDL : public CBase, public MRemConCoreApiTargetObserver { ENoFlags = 0x0, EEnableFocusStop = 0x1, //let SDL thread to be stopped if not on top - EOwnThread = 0x1000, //always put SDL running its own thread EMainThread = 0x2000, //always put SDL in application thread }; -- 2.11.4.GIT