Пример #1
0
/* Free the semaphore */
void SDL_DestroySemaphore(SDL_sem *sem)
{
	if ( sem ) 
	{
    RSemaphore sema;
    sema.SetHandle(sem->handle);
	sema.Signal(sema.Count());
    sema.Close();
    delete sem;
	sem = NULL;
	}
}
Пример #2
0
/* Free the semaphore */
void SDL_DestroySemaphore(SDL_sem *sem)
{
	if ( sem ) 
	{
    RSemaphore sema;
    sema.SetHandle(sem->handle);
#if !defined (UIQ3) && !defined(S60V3)
	sema.Signal(sema.Count());
#else
	sema.Signal(sem->count);
#endif
    sema.Close();
    delete sem;
	sem = NULL;
	}
}
EXPORT_C void StartServerL(const TDesC& aServerName, TUid aServerUid3, const TDesC& aServerFileName)
#endif
{
	CALLSTACKITEM_N(_CL(""), _CL("StartServer"));

	TBuf<50> mutexname; MakeServerMutexName(mutexname, aServerName);
	RAMutex mutex; mutex.GlobalLA(mutexname);
	
	TFindServer findServer(aServerName);
	TFullName name;
	
	if (findServer.Next(name) == KErrNone)
        {
		return;
        }
	
#if defined(__WINS__)
	RAThread serverthread;
#else
	RAProcess serverthread;
#endif
	TBuf<50> semaphorename; MakeServerSemaphoreName(semaphorename, aServerName);
	RSemaphore semaphore;
	if (semaphore.CreateGlobal(semaphorename, 0)!=KErrNone) {
		User::LeaveIfError(semaphore.OpenGlobal(semaphorename));
	}

#if defined(__WINS__)
	CreateServerProcessLA(aServerName, aFunction, serverthread);
#else
	CreateServerProcessLA(aServerName, aServerUid3, aServerFileName, serverthread);
#endif
	
	TTimeIntervalMicroSeconds32 w(10*1000);
	TInt i=0;
	TInt result=KErrTimedOut;
	while (i < 17) { 
		// a couple of minutes, in case there's some db conversion or the like
#ifdef __S60V3__
		if (semaphore.Wait(w.Int())==KErrNone) {
#else
		if ( semaphore.Count()>0) {
#endif
			result=KErrNone;
			break;
		}
		TExitType etype=serverthread.ExitType();
		if (etype!=EExitPending) {
			// server died
			result=KErrServerTerminated;
			break;
		}
#ifndef __S60V3__
		User::After(w);
#endif
		w=w.Int()*2;
		i++;
	}
	if (result!=KErrNone) {
		User::Leave(result);
	}

	semaphore.Close();
}

#if defined(__WINS__)
void CreateServerProcessLA(const TDesC& aServerName, TThreadFunction aFunction,
				RAThread& aThreadInto)
#else
#  if defined(__WINS__)
void CreateServerProcessLA(const TDesC& aServerName, TUid aServerUid3, 
				    const TDesC& aServerFileName,
				RAThread& aThreadInto)
#  else
void CreateServerProcessLA(const TDesC& aServerName, TUid aServerUid3, 
				    const TDesC& aServerFileName,
				RAProcess& aThreadInto)
#  endif
#endif
{
	CALLSTACKITEM_N(_CL(""), _CL("CreateServerProcess"));

	TInt result;
	
	
#if defined(__WINS__)
	
//#  if !defined(EKA2)
#if 0
	const TUidType serverUid(KNullUid, KNullUid, aServerUid3);
	RLibrary lib;
	TInt err=lib.Load(aServerFileName, _L("z:\\system\\programs"), serverUid);
	if (err!=KErrNone) {
		err=lib.Load(aServerFileName);
	}
	User::LeaveIfError(err);
	
	//  Get the WinsMain function
	TLibraryFunction functionWinsMain = lib.Lookup(1);
	
	//  Call it and cast the result to a thread function
	TThreadFunction serverThreadFunction = reinterpret_cast<TThreadFunction>(functionWinsMain());
#  else
	TThreadFunction serverThreadFunction = aFunction;
#  endif
	
	TName threadName(aServerName);
	
	// Append a random number to make it unique
	threadName.AppendNum(Math::Random(), EHex);
	
#  if 0
//#  if !defined(EKA2)
	aThreadInto.CreateLA(threadName,   // create new server thread
		serverThreadFunction, // thread's main function
		KDefaultStackSize,
		NULL,  // parameters
		&lib,
		NULL,
		KServerMinHeapSize,
		KServerMaxHeapSize,
		EOwnerProcess);
	lib.Close();    // if successful, server thread has handle to library now
	
#  else
	aThreadInto.CreateLA(threadName, serverThreadFunction, 
		KDefaultStackSize,
		KServerMinHeapSize, KServerMaxHeapSize, 0, EOwnerProcess);

#  endif
	
	aThreadInto.SetPriority(EPriorityMore);
	
#else
	
	const TUidType serverUid(KNullUid, KNullUid, aServerUid3);
	aThreadInto.CreateLA(aServerFileName, _L(""), serverUid);
	
#endif
	
	aThreadInto.Resume();
	
}