Beispiel #1
0
void Threads::ThreadRenderJob(int r, int c, const FractalJobHandeler & job, int)
{
	if (densityR == 0 || densityC==0) return;
	
	double UNITC = area.Width() / (densityC * cols);
	double UNITR = area.Height() / (densityR * rows);
	int iter, y0, x0;
	RGBA *l;
	
	ImageBuffer  ib(densityC, densityR);
	
	for (y0 = 0; y0< densityR; y0++)
	{
		l = ib[y0];
		for (x0 = 0; x0< densityC; x0++)
		{
			Complex tmp(area.left + UNITC *( c*densityC + x0), area.top + UNITR*( y0 + r*densityR));
			job(tmp, &iter);
			
			l->a = 0xFF;
			l->r = ( iter == maxIter ) ? 0  : 255 - (int)(250 * log10((double)iter) / logmax);//255 - iter * 120 / maxIter ;
			l->g = ( iter == maxIter ) ? 0  : 20 ;//iter * 125 / maxIter;
			l->b = ( iter == maxIter ) ? 0  : 40 + (int)(205 * log10((double)iter) / logmax) ;//120 + iter * 125 / maxIter ;
			l++;
		}
	}
	
	AtomicDec(threads);
	INTERLOCKED_(job_lock) 
		active.RemoveKey(r * cols + c);
	INTERLOCKED_(image_lock) 
		rendered.Add(r * cols + c, ib);
	waitforfinish.Release();
}
Beispiel #2
0
static
#ifdef PLATFORM_WIN32
#ifdef CPU_64
unsigned int
#else
uintptr_t __stdcall
#endif
#else
void *
#endif
sThreadRoutine(void *arg)
{
	LLOG("sThreadRoutine");
	Callback *cb = (Callback *)arg;
	try {
		(*cb)();
	}
	catch(Exc e) {
		Panic(e);
	}
	catch(ExitExc) {}
	AtomicDec(sThreadCount);
	delete cb;
	if(sExit)
		(*sExit)();
#ifdef UPP_HEAP
	MemoryFreeThread();
#endif
	return 0;
}
Beispiel #3
0
void _NGM::FinishThread(int tid) {
	AtomicDec(&m_ActiveThreads);

	Log.Verbose("Thread %i finished (%i worker threads remaining)", tid, m_ActiveThreads);
	m_Tasks[tid]->FinishStage();
	delete m_Tasks[tid];
	m_Tasks[tid] = 0;
}
Beispiel #4
0
void Layer::MakeLayerAsThread(Layer* pLayer,double op,void* pMain,int n)
{
	ImageMT* ptr = (ImageMT*)pMain;

	Layer* pNewLayer = new Layer(pLayer,op,pMain);

	ptr->AddLayer(pNewLayer);
	ptr->Refresh();
	AtomicDec(ptr->threads); // the last thing this thread does is clean up
}
Beispiel #5
0
/// atomic update the destVal
static int atomic_update_val(int& destVal, int with, int updateType)
{
	switch (updateType)
	{
	case position::POS_OP_ADD:		return AtomicAdd(&destVal, with);
	case position::POS_OP_DEC:		return AtomicDec(&destVal, with);
	case position::POS_OP_ASSIGN:	return (destVal = with);
	default:
		return destVal;
	}
}
Beispiel #6
0
void String0::LFree()
{
	if(IsRef()) {
		if(ptr != (char *)(voidptr + 1)) {
			Rc *rc = Ref();
			ASSERT(rc->refcount > 0);
			if(AtomicDec(rc->refcount) == 0) MFree(rc);
		}
	}
	else
		MFree_S(ptr);
}
Beispiel #7
0
void String::LFree()
{
	if(IsRef()) {
		if(ptr != VoidPtr()) {
			Rc *rc = Ref();
			ASSERT(rc->refcount > 0);
			if(AtomicDec(rc->refcount) == 0) MFree(rc);
		}
	}
	else
		MFree_S(ptr);
}
Beispiel #8
0
void TimerTest::Test()
{
	int a = AtomicInc(demo);
	ASSERT(a==2);

	Info("O");
	RLOG("O");

	a = AtomicDec(demo);
	if(a<=0)
		return;
	ASSERT(a>=0);
	
#ifdef REPEAT_TEST
#else
	t.SetTimeCallback(TIMEOUT, THISBACK(Test), (int)this);
#endif
}
Beispiel #9
0
	void MScheduler::DecIdleWorker()
	{
		AtomicDec( &m_cIdleWorkers );
	}
Beispiel #10
0
	void LWorker::Sleep()
	{
		AtomicInc( &m_Scheduler.m_cSleepingWorkers );
		m_Scheduler.m_WakeSemaphore.Wait();
		AtomicDec( &m_Scheduler.m_cSleepingWorkers );
	}
Beispiel #11
0
    void ConnectorInterface::Close()
    {
        AtomicInc(m_terminating);
        AtomicDec(m_isConnectedFinished);

        AtomicInc(m_isDisconnected);

        if (s_tracerThread)
        {
            if (!thread::IsThreadTerminated(s_tracerThread))
            {
                while (IsConnected() && !thread::IsThreadTerminated(s_tracerThread))
                {
                    behaviac::Thread::Sleep(1);
                }
            }

            {
                ScopedLock lock(m_packetBuffersLock);

                for (int i = 0; i < this->m_maxTracedThreads; ++i)
                {
                    BEHAVIAC_DELETE(m_packetBuffers[i]);
                }

                BEHAVIAC_G_DELETE_ARRAY(m_packetBuffers);
                m_packetBuffers = 0;
            }

            if (!thread::IsThreadTerminated(s_tracerThread))
            {
                thread::StopThread(s_tracerThread);
            }

            s_tracerThread = 0;
        }

        if (m_packetCollection)
        {
            m_packetCollection->Close();
            BEHAVIAC_DELETE(m_packetCollection);
            m_packetCollection = 0;
        }

        BEHAVIAC_DELETE(m_packetPool);
        m_packetPool = 0;
#if BEHAVIAC_COMPILER_MSVC

        if (t_packetBufferIndex != TLS_OUT_OF_INDEXES)
        {
            TlsFree(t_packetBufferIndex);
            t_packetBufferIndex = TLS_OUT_OF_INDEXES;
        }

#else
        t_packetBufferIndex = 0;
#endif
        behaviac::Socket::ShutdownSockets();

        AtomicDec(m_isInited);
    }
Beispiel #12
0
void Thread::EndShutdownThreads()
{
	AtomicDec(sShutdown);
}
Beispiel #13
0
void TimerTest::Close()
{
	t.KillTimeCallback((intptr_t)this);
	int a = AtomicDec(demo);
	Thread::Start(THISBACK(Close0));
}