void CarThread::ThreadFunc() { Thread::ThreadFunc(); int i, j; for (i = 1; i <= No_of_rides; i++) { for (j = 1; j <= Capacity; j++) Queue.Signal(); // allow CAPACITY passengers to check in Boarding.Wait(); // wait for boarding to complete // print on boarding passenger names cout << "The car is running for the " << i << " time with passengers "; for (j = 0; j < Capacity; j++) cout << " " << On_board_passenger_ID[j]; cout << endl; Delay(); // ride for a while On_board_passenger_counter = 0; // start unloading passengers for (j = 1; j <= Capacity; j++) { Riding.Signal(); // release a passenger Unloading.Wait(); // wait until this passenger is done } // definitely, the car is empty and goes for the next run } // done here and show messages cout << "The car is shot-off for maintenance" << endl; Exit(); }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams) { OptionParser parser; OptionBool loopback("-l", "--loopback", "Use the loopback adapter only"); parser.AddOption(&loopback); if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) { return; } if (loopback.Value()) { aInitParams->SetUseLoopbackNetworkAdapter(); } aInitParams->SetMsearchTime(1); aInitParams->SetDvUpnpServerPort(0); UpnpLibrary::Initialise(aInitParams); std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList(); TIpAddress subnet = (*subnetList)[0]->Subnet(); UpnpLibrary::DestroySubnetList(subnetList); UpnpLibrary::StartCombined(subnet); //Debug::SetLevel(Debug::kEvent | Debug::kDvEvent); Print("TestDvDeviceStd - starting\n"); Semaphore* sem = new Semaphore("SEM1", 0); DeviceBasic* device = new DeviceBasic(DeviceBasic::eProtocolUpnp); CpDevices* deviceList = new CpDevices(device->Device().Udn(), *sem); FunctorCpDeviceCpp added = MakeFunctorCpDeviceCpp(*deviceList, &CpDevices::Added); FunctorCpDeviceCpp removed = MakeFunctorCpDeviceCpp(*deviceList, &CpDevices::Removed); std::string domainName("openhome.org"); std::string serviceType("TestBasic"); TUint ver = 1; CpDeviceListCppUpnpServiceType* list = new CpDeviceListCppUpnpServiceType(domainName, serviceType, ver, added, removed); sem->Wait(30*1000); // allow up to 30s to find our one device try { deviceList->TestActions(); Functor cb = MakeFunctor(sem, &DeviceDisabled); device->Device().SetDisabled(cb); sem->Wait(); deviceList->TestThrows(); device->Device().SetEnabled(); deviceList->TestSubscriptions(); } catch (Exception& e) { Print("Exception %s from %s:%u\n", e.Message(), e.File(), e.Line()); ASSERTS(); } delete sem; delete list; delete deviceList; delete device; Print("TestDvDeviceStd - completed\n"); UpnpLibrary::Close(); }
ANativeWindowDisplayAdapter::~ANativeWindowDisplayAdapter() { Semaphore sem; TIUTILS::Message msg; LOG_FUNCTION_NAME; ///The ANativeWindow object will get destroyed here destroy(); ///If Display thread exists if (mDisplayThread.get()) { ///Kill the display thread sem.Create(); msg.command = DisplayThread::DISPLAY_EXIT; // Send the semaphore to signal once the command is completed msg.arg1 = &sem; ///Post the message to display thread mDisplayThread->msgQ().put(&msg); ///Wait for the ACK - implies that the thread is now started and waiting for frames sem.Wait(); // Exit and cleanup the thread mDisplayThread->requestExitAndWait(); // Delete the display thread mDisplayThread.clear(); } LOG_FUNCTION_NAME_EXIT; }
/** * Fills the SimStepData from a Transfer thread with the first simulation result from the SRD queue * This method won't filter the data, all existing and available parameter, algebraic and states will be saved. * parameter: pointer from type SimStepData, it points on a data struct in a Transfer thread */ bool getResultData(SimStepData* p_SimResDataForw_from_Transfer) { bool retValue = true; /* * This part is necessary for the producer &consumer problem with districted buffer * An entity which want to use the array must pas this part */ ghSemaphore_NumberUsedSlots.Wait(); ssdMutex.Lock(); /******************************************************************** * Entity has pas the synchronization station and can work on the SSD buffer */ if ((*pp_srdfArray_FirstQueueElement)->forTimeStep != -1) { popSRDF(p_SimResDataForw_from_Transfer); } else{ //cout << "no chance ;) for time: " << (*pp_srdfArray_FirstQueueElement)->forTimeStep << endl; fflush(stdout); } // Release the mutex ssdMutex.Unlock(); ghSemaphore_NumberFreeSlots.Post(); return retValue; }
void DeviceList::Poll() { Functor updatesComplete = MakeFunctor(*this, &DeviceList::InitialNotificationComplete); const TUint count = (TUint)iList.size(); for (TUint i=0; i<count; i++) { CpDevice* device = iList[i]; TUint countBefore = gSubscriptionCount; Print("Device "); Print(device->Udn()); CpProxyUpnpOrgConnectionManager1* connMgr = new CpProxyUpnpOrgConnectionManager1(*device); connMgr->SetPropertyChanged(updatesComplete); TUint startTime = Os::TimeInMs(iEnv.OsCtx()); while(true) { iSem.Clear(); connMgr->Subscribe(); try { iSem.Wait(kDevicePollMs+1); } catch(Timeout&) {} connMgr->Unsubscribe(); if (Os::TimeInMs(iEnv.OsCtx()) - startTime > kDevicePollMs) { break; } gSubscriptionCount++; } Print(" %u\n", gSubscriptionCount - countBefore); delete connMgr; } }
extern "C" void OhNetTestRunner(OhNetHandleInitParams aInitParams) { OhNetInitParamsSetMsearchTime(aInitParams, 1); OhNetInitParamsSetUseLoopbackNetworkAdapter(aInitParams); OhNetInitParamsSetDvUpnpServerPort(aInitParams, 0); OhNetLibraryInitialise(aInitParams); Print("TestDvDeviceC - starting\n"); OhNetHandleNetworkAdapterList subnetList = OhNetSubnetListCreate(); OhNetHandleNetworkAdapter nif = OhNetSubnetAt(subnetList, 0); TIpAddress subnet = OhNetNetworkAdapterSubnet(nif); OhNetSubnetListDestroy(subnetList); (void)OhNetLibraryStartCombined(subnet); // Debug::SetLevel(Debug::kService); Semaphore* sem = new Semaphore("SEM1", 0); DeviceBasicC* device = new DeviceBasicC(DeviceBasicC::eProtocolUpnp); DeviceList* deviceList = new DeviceList(*sem); HandleCpDeviceList dlh = CpDeviceListCreateUpnpServiceType("openhome.org", "TestBasic", 1, added, deviceList, removed, deviceList); sem->Wait(30*1000); // allow up to 30 seconds to find our one device deviceList->TestActions(); deviceList->TestSubscriptions(); CpDeviceListDestroy(dlh); delete sem; delete deviceList; delete device; Print("TestDvDeviceC - completed\n"); OhNetLibraryClose(); }
void TestDvSubscription() { InitialisationParams& initParams = Stack::InitParams(); TUint oldMsearchTime = initParams.MsearchTimeSecs(); initParams.SetMsearchTime(1); Print("TestDvSubscription - starting\n"); Semaphore* sem = new Semaphore("SEM1", 0); DeviceBasic* device = new DeviceBasic; CpDevices* deviceList = new CpDevices(*sem); FunctorCpDevice added = MakeFunctorCpDevice(*deviceList, &CpDevices::Added); FunctorCpDevice removed = MakeFunctorCpDevice(*deviceList, &CpDevices::Removed); Brn domainName("openhome.org"); Brn serviceType("TestBasic"); TUint ver = 1; CpDeviceListUpnpServiceType* list = new CpDeviceListUpnpServiceType(domainName, serviceType, ver, added, removed); sem->Wait(30*1000); // allow up to 30 seconds to issue the msearch and receive a response delete sem; deviceList->Test(); delete list; delete deviceList; delete device; Print("TestDvSubscription - completed\n"); initParams.SetMsearchTime(oldMsearchTime); }
void CpDevices::Validate(std::vector<const char*>& aExpectedUdns) { iLock.Wait(); TBool wait = (aExpectedUdns.size() > iList.size()); iTargetCount = (TUint)aExpectedUdns.size(); iLock.Signal(); if (wait) { try { iSem.Wait(30 * 1000); } catch (Timeout&) { Print("ERROR: Failed to detect sufficient devices\n"); } } if (aExpectedUdns.size() != iList.size()) { Print("ERROR: expected %u devices, found %u\n", aExpectedUdns.size(), iList.size()); ASSERTS(); } while (aExpectedUdns.size() > 0) { Brn expected(aExpectedUdns[0]); TBool found = false; for (TUint i=0; i<iList.size(); i++) { if (expected == iList[i]->Udn()) { Brh friendlyName; iList[i]->GetAttribute("Upnp.FriendlyName", friendlyName); ASSERT(friendlyName == expected); aExpectedUdns.erase(aExpectedUdns.begin()); found = true; break; } } ASSERT(found); } ASSERT(aExpectedUdns.size() == 0); }
void SuiteMulticast::Test() { iThread0->Start(); iThread1->Start(); iSender.Wait(); iSender.Wait(); SocketUdp send; Bwn buf(iExp); TUint i; for( i=0; i < kMsgBytes; i++) { buf.SetBytes(0); AppendUint32(buf, i); //num of bytes in this message buf.SetBytes(i + sizeof(TUint)); //use prefilled values send.Send(buf, Endpoint(iPort, kMulticastAddress)); // assume that a delay of 500ms without response implies that the message wasn't delivered try { iSender.Wait(500); iSender.Wait(500); } catch (Timeout&) { Print("SuiteMulticast - message(s) not delivered\n"); TEST(1 == 0); return; // temp } if (iSender.Clear()) { TEST(1 == 0); Print("SuiteMulticast - sent one message, received more than once\n"); } } buf.SetBytes(0); AppendUint32(buf, kQuit); send.Send(buf, Endpoint(iPort, kMulticastAddress)); try { iSender.Wait(500); iSender.Wait(500); } catch (Timeout&) { Print("SuiteMulticast - quit message(s) not delivered\n"); } }
void SignalThread::Run() { while (1) { iSelf.Wait(); iOwner.Signal(); CheckForKill(); } }
void SuiteAlive::Test() { Environment& env = iDvStack.Env(); Blocker* blocker = new Blocker(env); CpListenerBasic* listener = new CpListenerBasic; NetworkAdapter* nif = env.NetworkAdapterList().CurrentAdapter(kAdapterCookie); SsdpListenerMulticast* listenerMulticast = new SsdpListenerMulticast(env, nif->Address()); nif->RemoveRef(kAdapterCookie); TInt listenerId = listenerMulticast->AddNotifyHandler(listener); listenerMulticast->Start(); DviDevice* device = new DviDeviceStandard(iDvStack, gNameDevice1); device->SetAttribute("Upnp.Domain", "a.b.c"); device->SetAttribute("Upnp.Type", "type1"); device->SetAttribute("Upnp.Version", "1"); AddService(device, new DviService(iDvStack, "a.b.c", "service1", 1)); AddService(device, new DviService(iDvStack, "a.b.c", "service2", 1)); device->SetEnabled(); blocker->Wait(1); /* we expect 5 messages but linux sometimes reports multicast messages from all subnets to listeners on any single subnet so just check that we've received a multiple of 5 messages */ TEST(listener->TotalAlives() > 0); TEST(listener->TotalAlives() == listener->TotalByeByes()); TEST(listener->TotalAlives() % 5 == 0); TUint byebyes = listener->TotalByeByes(); Functor disabled = MakeFunctor(*this, &SuiteAlive::Disabled); device->SetDisabled(disabled); iSem.Wait(); blocker->Wait(1); /* semaphore being signalled implies that the device has been disabled. We may require some extra time to receive the multicast byebye confirming this */ TEST(listener->TotalByeByes() > byebyes); TEST(listener->TotalByeByes() % 5 == 0); TUint alives = listener->TotalAlives(); byebyes = listener->TotalByeByes(); device->SetEnabled(); blocker->Wait(1); TEST(listener->TotalAlives() > alives); TEST(listener->TotalAlives() - alives == listener->TotalByeByes() - byebyes); TEST(listener->TotalAlives() % 5 == 0); // Control point doesn't process ssdp:update notifications // check that updates are basically working by counting the extra alive messages instead alives = listener->TotalAlives(); device->SetAttribute("Upnp.TestUpdate", "1"); blocker->Wait(1); TEST(listener->TotalAlives() > alives); TEST(listener->TotalAlives() % 5 == 0); device->Destroy(); listenerMulticast->RemoveNotifyHandler(listenerId); delete listenerMulticast; delete listener; delete blocker; }
void SuiteThreadFunctor::Test() { iSem = new Semaphore("", 0); iFunctor = new ThreadFunctor("STFF", MakeFunctor(*this, &SuiteThreadFunctor::Run)); iFunctor->Start(); iSem->Wait(); delete iFunctor; delete iSem; }
status_t acquire_sem(int handle, bigtime_t timeout) { Semaphore *sem = static_cast<Semaphore*>(GetResource(handle, OBJ_SEMAPHORE)); if (sem == 0) return E_BAD_HANDLE; status_t ret = sem->Wait(timeout); sem->ReleaseRef(); return ret; }
// WaitTimeout //------------------------------------------------------------------------------ void TestSemaphore::WaitTimeout() const { Timer t; Semaphore s; s.Wait( 50 ); // wait 50ms // ensure some sensible time has elapsed ASSERT( t.GetElapsed() > 0.025f ); // 25ms (allow wide margin of error) }
void OpenHome::TestFramework::Runner::Main(TInt /*aArgc*/, TChar* /*aArgv*/[], Net::InitialisationParams* aInitParams) { Library* lib = new Library(aInitParams); std::vector<NetworkAdapter*>* subnetList = lib->CreateSubnetList(); TIpAddress subnet = (*subnetList)[0]->Subnet(); TIpAddress addr = (*subnetList)[0]->Address(); Endpoint endpt(0, addr); Endpoint::AddressBuf buf; endpt.AppendAddress(buf); Print("Connect to %s:%u then 'help' for options\n\n", buf.Ptr(), Shell::kServerPortDefault); Library::DestroySubnetList(subnetList); CpStack* cpStack = NULL; DvStack* dvStack = NULL; lib->StartCombined(subnet, cpStack, dvStack); Shell* shell = new Shell(cpStack->Env()); Semaphore* blocker = new Semaphore("BLCK", 0); std::vector<ShellTest> shellTests; shellTests.push_back(ShellTest("TestBuffer", RunTestBuffer)); shellTests.push_back(ShellTest("TestThread", RunTestThread)); shellTests.push_back(ShellTest("TestFifo", RunTestFifo)); shellTests.push_back(ShellTest("TestQueue", RunTestQueue)); shellTests.push_back(ShellTest("TestTextUtils", RunTestTextUtils)); shellTests.push_back(ShellTest("TestNetwork", RunTestNetwork, true)); shellTests.push_back(ShellTest("TestTimer", RunTestTimer)); shellTests.push_back(ShellTest("TestSsdpMListen", RunTestSsdpMListen, true)); shellTests.push_back(ShellTest("TestSsdpUListen", RunTestSsdpUListen, true)); shellTests.push_back(ShellTest("TestDeviceList", RunTestDeviceList, true)); shellTests.push_back(ShellTest("TestInvocation", RunTestInvocation)); shellTests.push_back(ShellTest("TestSubscription", RunTestSubscription)); shellTests.push_back(ShellTest("TestCpDeviceDv", RunTestCpDeviceDv)); shellTests.push_back(ShellTest("TestDviDiscovery", RunTestDviDiscovery)); shellTests.push_back(ShellTest("TestDviDeviceList", RunTestDviDeviceList)); shellTests.push_back(ShellTest("TestDvInvocation", RunTestDvInvocation)); shellTests.push_back(ShellTest("TestDvSubscription", RunTestDvSubscription)); shellTests.push_back(ShellTest("TestDvLpec", RunTestDvLpec)); shellTests.push_back(ShellTest("TestException", RunTestException)); shellTests.push_back(ShellTest("TestFunctorGeneric", RunTestFunctorGeneric)); shellTests.push_back(ShellTest("TestXmlParser", RunTestXmlParser)); ShellCommandRun* cmdRun = new ShellCommandRun(*cpStack, *dvStack, *shell, shellTests); ShellCommandDebug* cmdDebug = new ShellCommandDebug(*shell); ShellCommandQuit* cmdQuit = new ShellCommandQuit(*shell, *blocker); ShellCommandWatchDog* cmdWatchDog = new ShellCommandWatchDog(*shell, 60); // default to 60s watchdog. This can be changed at runtime by client. blocker->Wait(); // control never reaches here delete blocker; delete cmdWatchDog; delete cmdQuit; delete cmdDebug; delete cmdRun; delete shell; delete lib; }
void* _ThreadFun1(void *cxt) { Semaphore *pSem = (Semaphore *)cxt; assert(pSem); int i = 0; while (true) { pSem->Wait(); printf("waited - %d\n", i++); } return NULL; }
void PassengerThread::TakeRide() { strstream *Space; Space = Filler(3); // build leading spaces Queue.Wait(); // join the queue for a ride CheckIn.Wait(); // time to check in // save my name and increase the counter On_board_passenger_ID[On_board_passenger_counter] = passenger_Id; On_board_passenger_counter++; cout << Space->str() << ThreadName.str() <<" is on board the car" << endl; // if I am the last one to be on board, boarding completes and the car is full if (On_board_passenger_counter == Capacity) Boarding.Signal(); CheckIn.Signal(); // allow next passenger to check in Riding.Wait(); // I am riding in the car Unloading.Signal(); // get off the car }
void SuiteListen::Test() { // Debug::SetLevel(Debug::kSsdpMulticast); SsdpNotifyLoggerM notifyLogger; MSearchLogger msearchLogger; SsdpListenerMulticast mListener(NetworkIf(iInterfaceIndex)); TInt notifyId = mListener.AddNotifyHandler(¬ifyLogger); TInt msearchId = mListener.AddMsearchHandler(&msearchLogger); mListener.Start(); iTimer->FireIn(iDuration); iSem.Wait(); mListener.RemoveNotifyHandler(notifyId); mListener.RemoveMsearchHandler(msearchId); }
void ConsumerThread() { for(;;) { todo.Wait(); Mutex::Lock __(mutex); if(queue.GetCount()) { int *ptr = queue.Tail(); if(!ptr) break; queue.DropTail(); delete ptr; } MemoryCheckDebug(); } LOG("Consumer shutdown"); }
ANativeWindowDisplayAdapter::~ANativeWindowDisplayAdapter() { Semaphore sem; TIUTILS::Message msg; LOG_FUNCTION_NAME; ///If Frame provider exists if (mFrameProvider) { // Unregister with the frame provider mFrameProvider->disableFrameNotification(CameraFrame::ALL_FRAMES); delete mFrameProvider; mFrameProvider = NULL; } ///The ANativeWindow object will get destroyed here destroy(); ///If Display thread exists if(mDisplayThread.get()) { ///Kill the display thread sem.Create(); msg.command = DisplayThread::DISPLAY_EXIT; // Send the semaphore to signal once the command is completed msg.arg1 = &sem; ///Post the message to display thread mDisplayThread->msgQ().put(&msg); ///Wait for the ACK - implies that the thread is now started and waiting for frames sem.Wait(); // Exit and cleanup the thread mDisplayThread->requestExitAndWait(); // Delete the display thread mDisplayThread.clear(); } LOG_FUNCTION_NAME_EXIT; }
static DWORD WINAPI taskEntry(LPVOID arg) { #else static void *taskEntry(void *arg) { #endif while (true) { workerSemaphore.Wait(); // Try to get task from task queue Task *myTask = NULL; { MutexLock lock(*taskQueueMutex); if (taskQueue.size() == 0) break; myTask = taskQueue.back(); taskQueue.pop_back(); } // Do work for _myTask_ PBRT_STARTED_TASK(myTask); myTask->Run(); PBRT_FINISHED_TASK(myTask); tasksRunningCondition.Lock(); int unfinished = --numUnfinishedTasks; if (unfinished == 0) tasksRunningCondition.Signal(); tasksRunningCondition.Unlock(); } // Cleanup from task thread and exit #ifdef PBRT_HAS_PTHREADS pthread_exit(NULL); #endif // PBRT_HAS_PTHREADS return 0; } #endif // !PBRT_USE_GRAND_CENTRAL_DISPATCH void WaitForAllTasks() { #ifdef PBRT_USE_GRAND_CENTRAL_DISPATCH dispatch_group_wait(gcdGroup, DISPATCH_TIME_FOREVER); #else tasksRunningCondition.Lock(); while (numUnfinishedTasks > 0) tasksRunningCondition.Wait(); tasksRunningCondition.Unlock(); #endif }
void RwLock::EnterWrite() { LLOG("EnterWrite"); write_mutex.Enter(); LLOG("EnterWrite:write_mutex.Enter();"); lock_mutex.Enter(); ASSERT(!waiting_writer); waiting_writer = true; if(readers) { LLOG("EnterWrite:if(readers)"); lock_mutex.Leave(); writer_wait.Wait(); lock_mutex.Enter(); LLOG("EnterWrite:writer_wait.Wait();"); } waiting_writer = false; lock_mutex.Leave(); LLOG(".EnterWrite"); }
// WaitForSignal //------------------------------------------------------------------------------ void TestSemaphore::WaitForSignal() const { Semaphore s; // Create a thread which will signal the Semaphore Thread::ThreadHandle h = Thread::CreateThread( WaitForSignal_Thread, "Test::WaitForSignal", ( 32 * KILOBYTE ), &s ); // Wait or the expected signal count for ( size_t i=0; i<100; ++i ) { s.Wait(); } // Cleanup thread bool timedOut; Thread::WaitForThread( h, 1000, timedOut ); TEST_ASSERT( timedOut == false ); Thread::CloseHandle( h ); }
void DeviceList::PollInvoke() { Timer timer(MakeFunctor(*this, &DeviceList::TimerExpired)); for (TUint i=0; i<iList.size(); i++) { CpDeviceC device = iList[i]; TUint countBefore = gActionCount; Print("Device %s", CpDeviceCUdn(device)); iConnMgr = CpProxyUpnpOrgConnectionManager1Create(device); iStopTimeMs = Os::TimeInMs() + kDevicePollMs; timer.FireIn(kDevicePollMs); for (TUint j=0; j<Stack::InitParams().NumActionInvokerThreads(); j++) { CpProxyUpnpOrgConnectionManager1BeginGetProtocolInfo(iConnMgr, getProtocolInfoComplete, this); } iPollStop.Wait(); Print(" %u\n", gActionCount - countBefore); CpProxyUpnpOrgConnectionManager1Destroy(iConnMgr); free(iExpectedSink); iExpectedSink = NULL; } }
int ANativeWindowDisplayAdapter::enableDisplay(int width, int height, struct timeval *refTime, S3DParameters *s3dParams) { Semaphore sem; TIUTILS::Message msg; LOG_FUNCTION_NAME; if ( mDisplayEnabled ) { LOGINFO("Display is already enabled"); LOG_FUNCTION_NAME_EXIT; return NO_ERROR; } //Send START_DISPLAY COMMAND to display thread. Display thread will start and then wait for a message sem.Create(); msg.command = DisplayThread::DISPLAY_START; // Send the semaphore to signal once the command is completed msg.arg1 = &sem; ///Post the message to display thread mDisplayThread->msgQ().put(&msg); ///Wait for the ACK - implies that the thread is now started and waiting for frames sem.Wait(); // Register with the frame provider for frames mFrameProvider->enableFrameNotification(CameraFrame::PREVIEW_FRAME_SYNC); mDisplayEnabled = true; mPreviewWidth = width; mPreviewHeight = height; LOGINFO("mPreviewWidth = %d mPreviewHeight = %d", mPreviewWidth, mPreviewHeight); LOG_FUNCTION_NAME_EXIT; return NO_ERROR; }
void DeviceList::Poll() { Timer timer(*gEnv, MakeFunctor(*this, &DeviceList::TimerExpired), "TestInvocationStd"); FunctorAsync callback = MakeFunctorAsync(*this, &DeviceList::GetProtocolInfoComplete); const TUint count = (TUint)iList.size(); for (TUint i=0; i<count; i++) { CpDeviceCpp* device = iList[i]; TUint countBefore = gActionCount; Print("Device %s", device->Udn().c_str()); iConnMgr = new CpProxyUpnpOrgConnectionManager1Cpp(*device); iStopTimeMs = Os::TimeInMs(gEnv->OsCtx()) + kDevicePollMs; timer.FireIn(kDevicePollMs); for (TUint j=0; j<gEnv->InitParams()->NumActionInvokerThreads(); j++) { iConnMgr->BeginGetProtocolInfo(callback); } iPollStop.Wait(); Print(" %u\n", gActionCount - countBefore); delete iConnMgr; iExpectedSink.clear(); } }
void DeviceListTI::Poll() { Timer timer(iEnv, MakeFunctor(*this, &DeviceListTI::TimerExpired)); FunctorAsync callback = MakeFunctorAsync(*this, &DeviceListTI::GetProtocolInfoComplete); Brh tmp; const TUint count = (TUint)iList.size(); for (TUint i=0; i<count; i++) { CpDevice* device = iList[i]; TUint countBefore = gActionCount; Print("Device "); Print(device->Udn()); iConnMgr = new CpProxyUpnpOrgConnectionManager1(*device); iStopTimeMs = Os::TimeInMs(iEnv.OsCtx()) + kDevicePollMs; timer.FireIn(kDevicePollMs); for (TUint j=0; j<iEnv.InitParams()->NumActionInvokerThreads(); j++) { iConnMgr->BeginGetProtocolInfo(callback); } iPollStop.Wait(); Print(" %u\n", gActionCount - countBefore); delete iConnMgr; iExpectedSink.TransferTo(tmp); } }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow) { HANDLE runOnceMutex = NULL; bool allowMultipleInst = false; g_hinst = hInstance; // should we allow FreeAmp to run? struct stat st; char path[MAX_PATH]; char arg0[MAX_PATH]; getcwd(path, sizeof(path)); strcpy(arg0, __argv[0]); char* slash = strrchr(arg0, '\\'); if(slash) { *slash = 0x00; if(strcasecmp(path, arg0)) { chdir(arg0); strcpy(path, arg0); } } strcat(path, "\\NeedToRebootForUpdate"); if(!stat(path, &st)) { MessageBox(NULL, kReboot, "You Need To Reboot...", MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND); return 0; } FAContext *context = new FAContext; context->prefs = new Win32Prefs(); context->prefs->GetPrefBoolean(kAllowMultipleInstancesPref, &allowMultipleInst); context->hInstance = hInstance; if (!allowMultipleInst) { if(SendCommandLineToRealJukebox()) { return 0; } runOnceMutex = CreateMutex( NULL, TRUE, The_BRANDING" Should Only Run One Time!"); if(GetLastError() == ERROR_ALREADY_EXISTS) { SendCommandLineToHiddenWindow(); CloseHandle(runOnceMutex); return 0; } } // This causes a dynamic link error on some non NT systems, and // it didn't seem to help on multiprocessor NT systems, so I'm // commenting it. //if(IsWinNT() && IsMultiProcessor()) // SetProcessAffinityMask(GetCurrentProcess(), 0); WSADATA sGawdIHateMicrosoft; WSAStartup(0x0002, &sGawdIHateMicrosoft); context->log = new LogFile("freeamp.log"); // find all the plug-ins we use Registrar* registrar; Registry* lmc; Registry* pmi; Registry* pmo; Registry* ui; registrar = new Registrar; registrar->SetSubDir("plugins"); registrar->SetSearchString("*.lmc"); lmc = new Registry; registrar->InitializeRegistry(lmc, context->prefs); registrar->SetSearchString("*.pmi"); pmi = new Registry; registrar->InitializeRegistry(pmi, context->prefs); registrar->SetSearchString("*.pmo"); pmo = new Registry; registrar->InitializeRegistry(pmo, context->prefs); registrar->SetSearchString("*.ui"); ui = new Registry; registrar->InitializeRegistry(ui, context->prefs); delete registrar; bool reclaimFileTypes, askBeforeReclaiming; uint32 length = sizeof(path); context->prefs->GetPrefBoolean(kReclaimFiletypesPref, &reclaimFileTypes); context->prefs->GetPrefBoolean(kAskToReclaimFiletypesPref, &askBeforeReclaiming); context->prefs->GetPrefString(kInstallDirPref, path, &length); strcat(path, "\\freeamp.exe"); if(reclaimFileTypes) ReclaimFileTypes(path, askBeforeReclaiming); // create the player Player *player = Player::GetPlayer(context); // we are the first instance so create our hidden window Thread* thread = Thread::CreateThread(); thread->Create(CreateHiddenWindow, context); // need a way to signal main thread to quit... Semaphore *termination = new Semaphore(); // register items... we give up ownership here player->SetTerminationSemaphore(termination); player->RegisterLMCs(lmc); player->RegisterPMIs(pmi); player->RegisterPMOs(pmo); player->RegisterUIs(ui); // Let the player know if there are special requests from the user // __argc and __argv are magical variables provided for us // in MS's STDLIB.H file. player->SetArgs(__argc, __argv); // kick things off... player is now in charge! player->Run(); // sit around and twiddle our thumbs termination->Wait(); // clean up our act delete player; delete context; delete thread; if (!allowMultipleInst) CloseHandle(runOnceMutex); WSACleanup(); return 0; }
void ThreadPerformance::Run() { iSem.Wait(); }
TInt SemaphoreThread::Waits() { iWaitsGuard.Wait(); return iWaits; }