void RChannelFifoWriter::InterruptSupplier()
{
    bool waitForLatch;

    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_supplierState == SS_Running);

        /* remove any spare FIFO slots since we aren't going to send
           anything more to the supplier */
        m_availableUnits = 0;

        m_supplierState = SS_Interrupted;

        waitForLatch = m_sendLatch.Interrupt();
    }

    if (waitForLatch)
    {
        /* make sure all sends which were proceeding outside a lock
           have completed */
        m_sendLatch.Wait();
    }
}
Exemple #2
0
DWORD WINAPI UpdateThreadProc(LPVOID pData)
{
    Player *player = (Player *)pData;
    player_data_s &pd = *(player_data_s *)&player->data;

	DWORD prevTime = timeGetTime();

	while (WaitForSingleObject(pd.hQuitEvent, 17) != WAIT_OBJECT_0)
	{
		AutoCriticalSection acs(pd.critSect);

		DWORD time = timeGetTime();
		float dt = (time - prevTime)*(1/1000.f);

		for (int g=0; g<pd.sgCount; g++)
		{
			Slot *slots = pd.soundGroups[g].slots;
			for (int i=0, n=pd.soundGroups[g].active; i<n; i++) slots[i].update(player, dt, false);
		}

		/*if (dsListener) */pd.dsListener->CommitDeferredSettings();

		prevTime = time;
	}

	return 0;
}
Exemple #3
0
void DryadSubGraphVertex::VertexCompleted(DrError status,
                                          DryadMetaData* errorData)
{
    bool finished = false;

    {
        AutoCriticalSection acs(&m_baseCS);

        LogAssert(GetErrorCode() != DryadError_VertexCompleted);
        if (status == DryadError_VertexCompleted)
        {
            status = DrError_OK;
        }

        if (NoError())
        {
            ReportError(status, errorData);
        }

        LogAssert(m_outstandingVertices > 0);
        --m_outstandingVertices;

        if (m_outstandingVertices == 0)
        {
            finished = true;
        }
    }

    if (finished)
    {
        /* the real status will be returned in AsyncPostCompletion
           after we have exited all handlers. */
        m_handler->ProgramCompleted();
    }
}
void RChannelReaderImpl::AddUnitList(ChannelUnitList* unitList)
{
    ChannelProcessRequestList requestList;
    ChannelUnitList returnUnitList;

    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_state == RS_Running ||
                  m_state == RS_InterruptingSupplier);

        DrBListEntry* listEntry = unitList->RemoveHead();
        while (listEntry != NULL)
        {
            RChannelUnit* unit = unitList->CastOut(listEntry);
            AddUnitToQueue("RChannelReaderImpl::AddUnitList",
                           unit, &requestList, &returnUnitList);
            listEntry = unitList->RemoveHead();
        }

        FOO(&requestList);
        m_sendLatch.AcceptList(&requestList);
        m_unitLatch.AcceptList(&returnUnitList);
    }

    DispatchRequests("RChannelReaderImpl::AddUnitList",
                     &requestList, &returnUnitList);
}
Exemple #5
0
	void DeinitModuleDescriptions( 
                const wchar_t * module,
                bool            bLoc)
	{
        module = KLSTD::FixNullString(module);
        try
        {
            AutoCriticalSection acs(KLERR::g_pModulesCS);
            modules_t* pModules = GetModulesCS(bLoc);
            KLSTD_ASSERT(pModules);
            if(!pModules)
                return;
            ;
		    modules_t::iterator it=pModules->find(module);
		    if(it != pModules->end())
            {
			    delete it->second;
			    pModules->erase(it);
		    };
        }
        catch(std::exception& err)
        {
            KLERR_TRACE_UNEXPECTED();
        };
	};
void RChannelFifoWriter::Start()
{
    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_writerState == WS_Stopped);
        LogAssert(m_availableUnits == 0);
        LogAssert(m_blockedList.IsEmpty());
        LogAssert(m_reader != NULL);
        LogAssert(m_nextDataSequenceNumber == 0);
        LogAssert(m_nextDeliverySequenceNumber == 0);
        LogAssert(m_outstandingUnits == 0);
        LogAssert(m_terminationUnit == NULL);

        m_sendLatch.Start();
        m_returnLatch.Start();

        m_writerTerminationItem = NULL;
        m_readerTerminationItem = NULL;
        m_numberOfSubItemsWritten = 0;
        m_dataSizeWritten = 0;

        LogAssert(m_supplierEpoch == m_writerEpoch);

        BOOL bRet = ::ResetEvent(m_writerDrainEvent);
        LogAssert(bRet != 0);

        if (m_supplierState == SS_Running)
        {
            m_availableUnits = m_fifoLength;
        }
        m_writerState = WS_Running;
    }
}
RChannelItemType RChannelFifoWriterBase::
    WriteItemArraySync(RChannelItemArrayRef& itemArray,
                       bool flush,
                       RChannelItemArrayRef* pFailureArray)
{
    SyncHandler syncHandler;

    if (pFailureArray != NULL)
    {
        *pFailureArray = NULL;
    }

    EnqueueItemArray(itemArray, &syncHandler, &syncHandler);

    if (syncHandler.UsingEvent())
    {
        syncHandler.Wait();

        {
            AutoCriticalSection acs(&m_baseDR);

            m_eventCache.ReturnEvent(syncHandler.GetEvent());
        }
    }

    return syncHandler.GetStatusCode();
}
Exemple #8
0
 KLSTD_NOTHROW size_t CError::LocGetParCount() throw()
 {
     KLSTD::AutoCriticalSection acs(g_pErrorCS);
     return m_pLocInfo
                 ?   m_pLocInfo->m_vecArgs.size()
                 :   0u;
 };
void RChannelFifoNBWriter::AcceptReturningUnit(RChannelFifoUnit* unit)
{
    bool wakeUpSupplierDrain = false;

    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_outstandingUnits > 0);
        --m_outstandingUnits;

        if (m_supplierState == SS_Draining)
        {
            /* the supplier has requested a drain */
            if (m_outstandingUnits == 0)
            {
                m_supplierState = SS_Stopped;
                ++m_supplierEpoch;
                wakeUpSupplierDrain = true;
            }
        }
    }

    if (wakeUpSupplierDrain)
    {
        BOOL bRet = ::SetEvent(m_supplierDrainEvent);
        LogAssert(bRet != 0);
    }

    delete unit;
}
Exemple #10
0
void RChannelFifoWriterBase::ReturnHandlers(ChannelFifoUnitList* returnList)
{
    while (returnList->IsEmpty() == false)
    {
        RChannelFifoUnit* returnUnit =
            returnList->CastOut(returnList->RemoveHead());
        while (returnUnit != NULL)
        {
            RChannelItemArrayWriterHandler* handler;
            RChannelItemType statusCode;
            returnUnit->Disgorge(&handler, &statusCode);
            if (handler != NULL)
            {
                handler->ProcessWriteArrayCompleted(statusCode, NULL);
            }
            delete returnUnit;
            returnUnit =
                returnList->CastOut(returnList->RemoveHead());
        }

        {
            AutoCriticalSection acs(&m_baseDR);

            m_returnLatch.TransferList(returnList);
        }
    }
}
Exemple #11
0
//
// Notify GM of completed vertex
//
void DVertexPnController::Terminate(DrError vertexState,
                                    UInt32 exitCode)
{
    LogAssert(vertexState != DryadError_VertexRunning);

    if (vertexState == DrError_OK)
    {
        LogAssert(exitCode == DrExitCode_StillActive);
    }

    //
    // take Critical section to update vertex state
    //
    {
        AutoCriticalSection acs(&m_baseCS);

        m_currentStatus->SetVertexState(vertexState);
    }

    //
    // Log vertex termination
    //
    DrLogI( "Terminating vertex. Vertex %u.%u exitCode %s vertexState %s",
        m_currentStatus->GetProcessStatus()->GetVertexId(),
        m_currentStatus->GetProcessStatus()->GetVertexInstanceVersion(),
        DREXITCODESTRING(exitCode), DRERRORSTRING(vertexState));

    //
    // Send status to GM
    //
    SendStatus(exitCode, true);
}
Exemple #12
0
void RChannelFifoNBWriter::
    StartSupplier(RChannelBufferPrefetchInfo* prefetchCookie)
{
    ChannelUnitList unblockedList;

    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_supplierState == SS_Stopped);

        LogAssert(m_writerState != WS_Closed);
        LogAssert(m_outstandingUnits == 0);

        BOOL bRet = ::ResetEvent(m_supplierDrainEvent);
        LogAssert(bRet != 0);

        m_supplierState = SS_Running;

        while (m_blockedList.IsEmpty() == false)
        {
            ++m_outstandingUnits;

            RChannelFifoUnit* blockedUnit =
                m_blockedList.CastOut(m_blockedList.GetHead());

            unblockedList.TransitionToTail(unblockedList.
                                           CastIn(blockedUnit));
        }

        m_sendLatch.AcceptList(&unblockedList);
    }

    SendUnits(&unblockedList);
}
HRESULT SceneGraph::RegisterNotificationListener(__in ISceneChangesNotificationListener *pListener, SceneObjectContentType mask)
{
    if (pListener == NULL)
        return E_INVALIDARG;

    AutoCriticalSection acs(m_Validation);

    HRESULT hr;
    if (m_ValidateInProgress)
    {
        hr = E_FAIL;
    }
    else
    {
        NotificationListener nl;
        nl.listener = pListener;
        nl.notificationType = mask;
        hr = m_Listeners.Add(nl);
        if (SUCCEEDED(hr))
        {
            if (mask & SOCT_OBJECT_ADD)
            {
                hr = m_NewTopologyListeners.Add(pListener);
            }
        }
    }
    return hr;
}
void RChannelReaderImpl::
    ProcessItemArrayRequest(RChannelProcessRequest* request)
{
    RChannelItemArray* itemArray = request->GetItemArray();
    RChannelItemArrayReaderHandler* handler = request->GetHandler();
    LogAssert(handler != NULL);
    LogAssert(itemArray != NULL);

    void* cancelCookie = request->GetCookie();

    handler->ProcessItemArray(itemArray);

    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_state != RS_Stopped);

        /* now that the request has been processed remove it from our
           accounting */
        RemoveFromCancelMap(request, cancelCookie);
        /* if it was the last request with this cookie and somebody
           was blocked cancelling the cookie, wake them up */
        MaybeTriggerCancelEvent(cancelCookie);

        /* if it was the last request in the system and we are
           draining, wake up the drain thread */
        if (m_state == RS_Stopping && m_cookieMap.empty())
        {
            LogAssert(m_eventMap.empty());
            BOOL bRet = ::SetEvent(m_drainEvent);
            LogAssert(bRet != 0);
        }
    }
}
Exemple #15
0
	bool FindModuleString(
                    int             nCode, 
                    const wchar_t*  szwModule, 
                    AKWSTR&         wstrString,
                    bool            bLoc)
	{        
        szwModule = KLSTD::FixNullString(szwModule);
        AutoCriticalSection acs(KLERR::g_pModulesCS);
        try
        {
            modules_t* pModules = GetModulesCS(bLoc);
            KLSTD_ASSERT(pModules);
            if(!pModules)
                return false;
            modules_t::iterator it = pModules->find(szwModule);
            if( it != pModules->end())
            {
		        KLERR::strings_t::iterator it2=it->second->find(nCode);
		        if(it2!=it->second->end())
                {
                    wstrString = KLSTD::klwstr_t(it2->second).detach();
			        return true;
		        };
            };
        }
        catch(std::exception& err)
        {
            KLERR_TRACE_UNEXPECTED();
        };
		return false;
	};
Exemple #16
0
void RChannelFifoNBWriter::Start()
{
    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_writerState == WS_Stopped);
        LogAssert(m_outstandingUnits == 0);
        LogAssert(m_blockedList.IsEmpty());
        LogAssert(m_reader != NULL);
        LogAssert(m_nextDataSequenceNumber == 0);
        LogAssert(m_nextDeliverySequenceNumber == 0);

        m_sendLatch.Start();
        m_returnLatch.Start();

        m_writerTerminationItem = NULL;
        m_readerTerminationItem = NULL;
        m_numberOfSubItemsWritten = 0;
        m_dataSizeWritten = 0;

        LogAssert(m_supplierEpoch == m_writerEpoch);

        m_writerState = WS_Running;
    }
}
Exemple #17
0
 KLSTD_NOTHROW const wchar_t* CError::GetLocModuleName() throw()
 {
     KLSTD::AutoCriticalSection acs(g_pErrorCS);
     return (    !m_pLocInfo )
                 ?   GetModuleName()
                 :   m_pLocInfo->m_wstrLocModule.c_str();
 };
Exemple #18
0
void RChannelFifoWriterBase::CloseSupplier()
{
    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_supplierState == SS_Stopped);
        m_supplierState = SS_Closed;
    }
}
Exemple #19
0
/**
@todo JSON access errors lack specifier
@todo Check that omegas ar filled/exits
@todo Clean up nested checks for optional JSON arguments
@todo Eigenvalues should be computed independent of json output,
stored and used twice, for screen and file
*/
void run(const Settings &s) {
  // empty configurators
  unique_ptr<csmp::tperm::Configurator> mconf =
      make_unique<csmp::tperm::NullConfigurator>();
  unique_ptr<csmp::tperm::Configurator> fconf =
      make_unique<csmp::tperm::NullConfigurator>();
  // get matrix configurator
  Settings cs(s, "configuration");
  if (cs.json.count("matrix")) {
    Settings mcs(cs, "matrix");
    mconf = MatrixConfiguratorFactory().configurator(mcs);
  }
  // get fracture configurator
  if (cs.json.count("fractures")) {
    Settings fcs(cs, "fractures");
    fconf = FractureConfiguratorFactory().configurator(fcs);
  }
  // get omega generator
  Settings acs(s, "analysis");
  auto ogen = make_omega_generator(acs);
  // load model...
  Settings ms(s, "model");
  auto model = load_model(ms);
  // configure material properties
  mconf->configure(*model);
  fconf->configure(*model);
  // sort boundaries
  auto bds = sort_boundaries(*model, s);
  // ready to solve
  solve(bds, *model);
  // generate omegas
  auto omegas = ogen->generate(*model);
  auto nomegas = named_omegas(omegas);
  // get upscaled tensors
  auto omega_tensors = fetch(*model, nomegas);
  // results
  string jres_fname = "";
  if (s.json.count("output")) {
    Settings outs(s, "output");
    if (outs.json.count("save final binary")) // write to csmp binary
      if (outs.json["save final binary"].get<string>() != "")
        save_model(*model,
                   outs.json["save final binary"].get<string>().c_str());
    if (outs.json.count("vtu")) { // write to vtu
      if (outs.json["vtu"].get<bool>()) {
        make_omega_regions(nomegas, *model);
        vtu(omega_tensors, *model);
      }
      if (outs.json.count("vtu regions"))
        vtu(outs.json["vtu regions"].get<vector<string>>(), *model);
    }
    if (outs.json.count("results file name")) // write to json
      jres_fname = s.json["output"]["results file name"].get<string>();
  }
  report(omega_tensors, *model, jres_fname.c_str());
}
Exemple #20
0
 KLSTD_NOTHROW bool CError::Clone(KLERR::Error2** ppError) throw()
 {
     KLSTD_ASSERT(ppError && !(*ppError));
     KLSTD::AutoCriticalSection acs(g_pErrorCS);
     KLERR::Error2Ptr pResult;
     KLERR::CError* pNew = new CError(*this);
     pResult.Attach( static_cast<KLERR::Error2*>(pNew) );
     pResult.CopyTo(ppError);
     return !!pResult;
 };
void RChannelReaderImpl::
    ThreadSafeSetItemArray(RChannelItemArrayRef* dstItemArray,
                           RChannelItemArray* srcItemArray)
{
    {
        AutoCriticalSection acs(&m_baseDR);

        dstItemArray->Set(srcItemArray);
    }
}
Exemple #22
0
    KLSTD_NOTHROW void CError::GetPreviousError2(KLERR::Error2** ppError) throw()
    {
        KLSTD::AutoCriticalSection acs(g_pErrorCS);
        if(ppError && !(*ppError) && m_pParentError)
        {
            KLSTD::CAutoPtr<KLERR::Error2> pRes;
			pRes = ErrAdapt(m_pParentError);
            pRes.CopyTo(ppError);
        };
    };
Exemple #23
0
void RChannelFifoWriter::GetTerminationItems(RChannelItemRef* pWriterDrainItem,
                                             RChannelItemRef* pReaderDrainItem)
{
    {
        AutoCriticalSection acs(&m_baseDR);

        *pWriterDrainItem = m_writerTerminationItem;
        *pReaderDrainItem = m_readerTerminationItem;
    }
}
Exemple #24
0
void RChannelFifoWriter::DrainSupplier(RChannelItem* drainItem)
{
    ChannelFifoUnitList returnList;

    bool wakeUpWriterDrain = false;
    bool wakeUpSupplierDrain = false;
    bool waitForSupplierDrain = false;

    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_supplierState == SS_Interrupted);
        LogAssert(m_availableUnits == 0);

        LogAssert(drainItem != NULL);
        RChannelItemType drainType = drainItem->GetType();

        m_readerTerminationItem = drainItem;

        if (m_outstandingUnits > 0)
        {
            m_supplierState = SS_Draining;
            waitForSupplierDrain = true;
        }
        else
        {
            wakeUpWriterDrain = ReWriteBlockedListForEarlyReturn(drainType);
            returnList.TransitionToTail(&m_blockedList);
            m_returnLatch.AcceptList(&returnList);
            m_supplierState = SS_Stopped;
            ++m_supplierEpoch;
            wakeUpSupplierDrain = true;
        }
    }

    if (wakeUpWriterDrain)
    {
        BOOL bRet = ::SetEvent(m_writerDrainEvent);
        LogAssert(bRet != 0);
    }

    if (wakeUpSupplierDrain)
    {
        LogAssert(waitForSupplierDrain == false);
        BOOL bRet = ::SetEvent(m_supplierDrainEvent);
        LogAssert(bRet != 0);
    }
    else if (waitForSupplierDrain)
    {
        DWORD dRet = ::WaitForSingleObject(m_supplierDrainEvent, INFINITE);
        LogAssert(dRet == WAIT_OBJECT_0);
    }

    ReturnHandlers(&returnList);
}
Exemple #25
0
extern void
tty_print_alt_char(int c)
{
#ifdef HAVE_SLANG
    SLsmg_draw_object(SLsmg_get_row(), SLsmg_get_column(), c);
#else
    acs();
    addch(c);
    noacs();
#endif
}
Exemple #26
0
void RChannelFifoWriterBase::Close()
{
    {
        AutoCriticalSection acs(&m_baseDR);

        LogAssert(m_writerState == WS_Stopped);
        m_writerState = WS_Closed;
        m_writerTerminationItem = NULL;
        m_readerTerminationItem = NULL;
    }
}
Exemple #27
0
 KLSTD_NOTHROW const wchar_t* CError::LocGetPar(size_t nIndex)throw()
 {
     KLSTD::AutoCriticalSection acs(g_pErrorCS);
     return (    nIndex < 1 || 
                 nIndex > c_nMaxArgs || 
                 !m_pLocInfo || 
                 m_pLocInfo->m_vecArgs.size() < nIndex
             )
                 ?   L""
                 :   m_pLocInfo->m_vecArgs[nIndex-1].c_str();
 };
Exemple #28
0
 KLSTD_NOTHROW bool CError::IsLocalized() throw()
 {
     KLSTD::AutoCriticalSection acs(g_pErrorCS);
     return (    m_pLocInfo && 
                 (   m_pLocInfo->m_nFormat || 
                     !m_pLocInfo->m_wstrFormat.empty() 
                 )
             )
                 ?   true
                 :   false;
 };
bool RChannelReaderImpl::IsRunning()
{
    bool retval;

    {
        AutoCriticalSection acs(&m_baseDR);

        retval = (m_state == RS_Running);
    }

    return retval;
}
HRESULT SceneGraph::RegisterForValidate(__in ISceneObject *pObject)
{
    if (!pObject)
        return E_INVALIDARG;

    AutoCriticalSection acs(m_Validation);

    if (m_ValidateInProgress)
        return E_FAIL;

    return m_InvalidObjects.Add(pObject);
}