Пример #1
0
void *start_work_writer(void *sigcache_ptr)
{
  assert(sigcache_ptr);
  for (;;) {
    if (finishup) break;
    SignatureFlush();
    ThreadYield();
  }
  while (threads_running > 0) {
    SignatureFlush();
    ThreadYield();
  }
  return NULL;
}
Пример #2
0
void Flush_Threaded()
{
  if (jobs_start == -1) { // single-threaded
    SignatureFlush();
    return;
  } else {
    int jobs_ready = 1;
    while (jobs_ready > 0) {
      GetSemaphoreValue(&sem_jobs_ready, &jobs_ready);
      ThreadYield();
    }
    if (jobs_start != -1) {
      finishup = 1;

      for (int i = 0; i < threadpool_size; i++) {
        PostSemaphore(&sem_jobs_ready);
      }
      for (int i = 0; i < threadpool_size; i++) {
        pthread_join(threadpool[i], NULL);
      }
      SignatureFlush();
    }
    return;
  }
}
Пример #3
0
int
WinShowImage(int iWin, IMAGE *image, int which)
{
  DIAG_WINDOW       *pwin ;

  pwin = HandleToPtr(iWin) ;
  XVshowImage(pwin->xvf, which, image, 0) ;
  ThreadYield() ;
  return(NO_ERROR) ;
}
 void Pause()
 {
     if (mCount <= mLimit)
     {
         Concurrency::Pause(mCount);
         mCount *= 2;
     }
     else
     {
         ThreadYield();
     }
 }
Пример #5
0
/*------------------------------------------------------------------------
       Parameters:

      Description:

    Return Values:
            0 on success, < 0 otherwise.

------------------------------------------------------------------------*/
static Notify_value
winPoll(void)
{
  static int ncalls = 0 ;

  if (ncalls++ == 4)
    ThreadSignal(0, SIG_ALL) ;

  ThreadYield() ;
  /*  ThreadSleep(TID_SELF, 100) ;*/
  return(NOTIFY_DONE) ;
}
Пример #6
0
bool Mutex::AwaitImpl(const Condition &cond, int64 end_time) {
  // end_time is milliseconds since the epoch. A value of zero indicates no
  // timeout.
  while (!cond.Eval() && (end_time == 0 || GetCurrentTimeMillis() < end_time)) {
    Unlock();

    // Yield the rest of our CPU timeslice before reacquiring the lock.
    // Otherwise we'll spin pointlessly here, hurting performance.
    // (The Condition cannot possibly change when no other thread runs.)
    ThreadYield();
    Lock();
  }
  return cond.Eval();
}
Пример #7
0
void ThreadMain()
{
    int t1, t2, t3, t4;

    t1 = ThreadCreate(f, 1);
    printf("create a new thread (i=%d) [id=%d]\n", 1, t1);
    t2 = ThreadCreate(f, 2);
    printf("create a new thread (i=%d) [id=%d]\n", 2, t2);
    t3 = ThreadCreate(f, 3);
    printf("create a new thread (i=%d) [id=%d]\n", 4, t3);

    t4 = ThreadCreate(f, 4);
    printf("create a new thread (i=%d) [id=%d]\n", 4, t4);
    ThreadYield();

    printf("main thread invoked.\n");
}
Пример #8
0
void AcquireAdaptiveLockSlow(TAtomic* lock) {
    unsigned t = MIN_SLEEP_TIME;
    unsigned c = 0;

    while (!AtomicTryAndTryLock(lock)) {
        ++c;

        if (c == MAX_SPIN_COUNT) {
            ThreadYield();
        } else if (c % MAX_SPIN_COUNT == 0) {
            usleep(RandomizeSleepTime(t));

            t = Min<unsigned>((t * 3) / 2, 20000);
        } else {
            SpinLockPause();
        }
    }
}
Пример #9
0
void *tbp_thread_daemon(void *threaddata_vp) {
  TBPDaemon *D = threaddata_vp;

  int mytask = 0;

  for (;;) {
    // Wait for a new task
    int newtask;
    while (atomicCompareAndSwap(&D->H->current_task, mytask+1, mytask+1) == 0) {
      ThreadYield();
    }
    newtask = D->H->current_task;
    if (newtask == -1) { // Terminate
      break;
    }
    // new task
    mytask = newtask;
    D->result = D->H->current_task_start_routine(D->threaddata, D->H->current_task_data);
    atomicFetchAndAdd(&D->H->jobs_complete, 1);

    // and wait for a new task.
  }
  return NULL;
}
    void StandardSensors::OnThreadExecute(void)
    {
        // Pre-load what files we can... reduces open/close overhead (which is significant)

        // Setup CPU Clocks Support...
        FileHandle cpuOnlineFiles[g_maxCpus];
        FileHandle cpuFreqFiles[g_maxCpus];
        for(unsigned int i=0; i<g_maxCpus; i++)
        {
            cpuOnlineFiles[i] = cpuFreqFiles[i] = NullFileHandle;
        }
        if(CheckConnectionFlag(Enable_CPU_Zones))
        {
            for(unsigned int i=0; i<g_maxCpus; i++)
            {
                const CpuSensorDesc &desc = g_cpuDescs[i];
                cpuOnlineFiles[i] = OpenFile(desc.onlinePath);
                cpuFreqFiles[i]   = NullFileHandle;
                if(cpuOnlineFiles[i] != NullFileHandle)
                {
                    const int maxFreq = ReadIntFile(desc.maxFreqPath);
                    SensorSetRange(desc.label, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_KHz);
                }
            }
        }

        // Setup GPU Clocks Support...
        FileHandle gpuFreqFile = NullFileHandle;
        if(CheckConnectionFlag(Enable_GPU_Clocks))
        {
            gpuFreqFile = OpenFile("/sys/class/kgsl/kgsl-3d0/gpuclk");
        }
        if(gpuFreqFile != NullFileHandle)
        {
            const int maxFreq = ReadIntFile("/sys/class/kgsl/kgsl-3d0/max_gpuclk");
            SensorSetRange(g_gpuLabel, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_Hz);
        }

        // Setup Memory Clocks Support...
        FileHandle memFreqFile = NullFileHandle;
        //memFreqFile = OpenFile("/sys/class/devfreq/0.qcom,cpubw/cur_freq");
        if(memFreqFile != NullFileHandle)
        {
            const int maxFreq = ReadIntFile("/sys/class/devfreq/0.qcom,cpubw/max_freq");
            SensorSetRange(g_memLabel, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_MByte_Second);
        }

        // Setup thermal sensors...
        static const unsigned int maxThermalSensors = 20;
        static ThermalSensorDesc  thermalDescs[maxThermalSensors];
        FileHandle                thermalFiles[maxThermalSensors];
        for(unsigned int i=0; i<maxThermalSensors; i++)
        {
            thermalFiles[i] = NullFileHandle;
        }
        if(CheckConnectionFlag(Enable_Thermal_Sensors))
        {
            for(unsigned int i=0; i<maxThermalSensors; i++)
            {
                ThermalSensorDesc &desc = thermalDescs[i];

                char typePath[64] = {0};
                char tempPath[64] = {0};
                char modePath[64] = {0};
                sprintf(typePath, "/sys/devices/virtual/thermal/thermal_zone%d/type", i);
                sprintf(tempPath, "/sys/devices/virtual/thermal/thermal_zone%d/temp", i);
                sprintf(modePath, "/sys/devices/virtual/thermal/thermal_zone%d/mode", i);

                // If either of these files don't exist, then we got to the end of the thermal zone list...
                if(!CheckFileExists(typePath) || !CheckFileExists(tempPath))
                    break;

                // check to see if the zone is disabled... its okay if there is no mode file...
                char mode[16] = {0};
                if(ReadFileLine(modePath, mode, sizeof(mode))>0 && !strcmp(mode, "disabled"))
                    continue;

                if(!desc.initialized)
                {
                    // Read the sensor name in...
                    ReadFileLine(typePath, desc.name, sizeof(desc.name));

                    // Initialize the Label...
                    desc.initialized = desc.label.ConditionalInit(desc.name);
                }

                // Finally... open the file.
                thermalFiles[i] = OpenFile(tempPath);
        
                if(thermalFiles[i] != NullFileHandle)
                {
                    // by default 0 to 100 degrees...
                    SensorSetRange(desc.label, 0, 100, Sensor_Interp_Linear);
                }
            }
        }

        // For clocks, we store the last value and only send updates when it changes since we
        // use blocking chart rendering.
        int lastCpuFreq[g_maxCpus] = {0};
        int lastGpuFreq            = 0;
        int lastMemValue           = 0;

        unsigned int sampleCount = 0;

        while(!QuitSignaled() && IsConnected())
        {
            // Sample CPU Frequencies...
            for(unsigned int i=0; i<g_maxCpus; i++)
            {
                // If the 'online' file can't be found, then we just assume this CPU doesn't even exist
                if(cpuOnlineFiles[i] == NullFileHandle)
                    continue;

                const CpuSensorDesc &desc   = g_cpuDescs[i];
                const bool           online = ReadIntFile(desc.onlinePath);
                if(online && cpuFreqFiles[i]==NullFileHandle)
                {
                    // Open the frequency file if we are online and its not already open...
                    cpuFreqFiles[i] = OpenFile(desc.freqPath);
                }
                else if(!online && cpuFreqFiles[i]!=NullFileHandle)
                {
                    // close the frequency file if we are no longer online
                    CloseFile(cpuFreqFiles[i]);
                    cpuFreqFiles[i] = NullFileHandle;
                }
                const int freq = cpuFreqFiles[i]==NullFileHandle ? 0 : ReadIntFile(cpuFreqFiles[i]);
                if(freq != lastCpuFreq[i])
                {
                    // Convert from KHz to Hz
                    SensorSetValue(desc.label, (float)freq);
                    lastCpuFreq[i] = freq;
                }
                ThreadYield();
            }

            // Sample GPU Frequency...
            if(gpuFreqFile != NullFileHandle)
            {
                const int freq = ReadIntFile(gpuFreqFile);
                if(freq != lastGpuFreq)
                {
                    SensorSetValue(g_gpuLabel, (float)freq);
                    lastGpuFreq = freq;
                }
            }

            // Sample Memory Bandwidth
            if(memFreqFile != NullFileHandle)
            {
                const int value = ReadIntFile(memFreqFile);
                if(value != lastMemValue)
                {
                    SensorSetValue(g_memLabel, (float)value);
                    lastMemValue = value;
                }
            }

            // Sample thermal sensors...
            if((sampleCount&15) == 0) // sample temperature at a much lower frequency as clocks... thermals don't change that fast.
            {
                for(unsigned int i=0; i<maxThermalSensors; i++)
                {
                    FileHandle file = thermalFiles[i];
                    if(file != NullFileHandle)
                    {
                        SensorSetValue(thermalDescs[i].label, (float)ReadIntFile(file));
                    }
                }
                ThreadYield();
            }

            // Sleep 5ms between samples...
            ThreadSleepMicroseconds(5000);
            sampleCount++;
        }

        // Close down cached file handles...
        for(unsigned int i=0; i<g_maxCpus; i++)
        {
            if(cpuOnlineFiles[i] != NullFileHandle) CloseFile(cpuOnlineFiles[i]);
            if(cpuFreqFiles[i]   != NullFileHandle) CloseFile(cpuFreqFiles[i]);
        }
        if(gpuFreqFile != NullFileHandle) CloseFile(gpuFreqFile);
        if(memFreqFile != NullFileHandle) CloseFile(memFreqFile);
        for(unsigned int i=0; i<maxThermalSensors; i++)
        {
            if(thermalFiles[i] != NullFileHandle) CloseFile(thermalFiles[i]);
        }
    }
	void StandardSensors::OnThreadExecute(void)
	{
		SetThreadName("CaptureSensors");

		// Pre-load what files we can... reduces open/close overhead (which is significant)

		// Setup CPU Clocks Support...
		static const UInt32 maxCpus = 8;
		static SensorLabelDesc cpuDescs[maxCpus];
		FileHandle cpuOnlineFiles[maxCpus];
		FileHandle cpuFreqFiles[maxCpus];
		for(UInt32 i=0; i<maxCpus; i++)
		{
			cpuOnlineFiles[i] = cpuFreqFiles[i] = NullFileHandle;
			SensorLabelDesc &desc = cpuDescs[i];
			FormatString(desc.name, sizeof(desc.name), "CPU%u Clocks", i);
			desc.label.ConditionalInit(desc.name);
		}
		if(CheckConnectionFlag(Enable_CPU_Zones))
		{
			int maxFreq = 0;
			for(UInt32 i=0; i<maxCpus; i++)
			{
				char onlinePath[64] = {0};
				FormatString(onlinePath, sizeof(onlinePath), "/sys/devices/system/cpu/cpu%u/online", i);
				cpuOnlineFiles[i] = OpenFile(onlinePath);
				cpuFreqFiles[i]   = NullFileHandle;
				if(cpuOnlineFiles[i] != NullFileHandle)
				{
					char maxFreqPath[64] = {0};
					FormatString(maxFreqPath, sizeof(maxFreqPath), "/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_max_freq", i);
					maxFreq = std::max(maxFreq, ReadIntFile(maxFreqPath));
				}
			}
			for(UInt32 i=0; i<maxCpus; i++)
			{
				const SensorLabelDesc &desc = cpuDescs[i];
				SensorSetRange(desc.label, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_KHz);
			}
		}

		// Setup GPU Clocks Support...
		FileHandle gpuFreqFile = NullFileHandle;
		if(CheckConnectionFlag(Enable_GPU_Clocks))
		{
			if(gpuFreqFile == NullFileHandle) // Adreno
			{
				gpuFreqFile = OpenFile("/sys/class/kgsl/kgsl-3d0/gpuclk");
				if(gpuFreqFile != NullFileHandle)
				{
					const int maxFreq = ReadIntFile("/sys/class/kgsl/kgsl-3d0/max_gpuclk");
					SensorSetRange(g_gpuLabel, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_Hz);
				}
			}
			if(gpuFreqFile == NullFileHandle) // Mali
			{
				gpuFreqFile = OpenFile("/sys/devices/14ac0000.mali/clock");
				if(gpuFreqFile != NullFileHandle)
				{
					// TODO: query max GPU clocks on Mali, for now hacked to what we know the S6 is
					SensorSetRange(g_gpuLabel, 0, 0, Sensor_Interp_Nearest, Sensor_Unit_MHz);
				}
			}
		}

		// Setup Memory Clocks Support...
		FileHandle memFreqFile = NullFileHandle;
		//memFreqFile = OpenFile("/sys/class/devfreq/0.qcom,cpubw/cur_freq");
		if(memFreqFile != NullFileHandle)
		{
			const int maxFreq = ReadIntFile("/sys/class/devfreq/0.qcom,cpubw/max_freq");
			SensorSetRange(g_memLabel, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_MByte_Second);
		}

		// Setup thermal sensors...
		static const UInt32 maxThermalSensors = 20;
		static SensorLabelDesc  thermalDescs[maxThermalSensors];
		FileHandle              thermalFiles[maxThermalSensors];
		for(UInt32 i=0; i<maxThermalSensors; i++)
		{
			thermalFiles[i] = NullFileHandle;
		}
		if(CheckConnectionFlag(Enable_Thermal_Sensors))
		{
			for(UInt32 i=0; i<maxThermalSensors; i++)
			{
				SensorLabelDesc &desc = thermalDescs[i];

				char typePath[64]      = {0};
				char tempPath[64]      = {0};
				char tripPointPath[64] = {0};
				FormatString(typePath,      sizeof(typePath),      "/sys/devices/virtual/thermal/thermal_zone%u/type", i);
				FormatString(tempPath,      sizeof(tempPath),      "/sys/devices/virtual/thermal/thermal_zone%u/temp", i);
				FormatString(tripPointPath, sizeof(tripPointPath), "/sys/devices/virtual/thermal/thermal_zone%u/trip_point_0_temp", i);

				// If either of these files don't exist, then we got to the end of the thermal zone list...
				if(!CheckFileExists(typePath) || !CheckFileExists(tempPath) || !CheckFileExists(tripPointPath))
					break;

				// Initialize the Label...
				if(ReadFileLine(typePath, desc.name, sizeof(desc.name)) <= 0)
					continue; // failed to read sensor name...
				desc.label.ConditionalInit(desc.name);

				char modePath[64] = {0};
				FormatString(modePath, sizeof(modePath), "/sys/devices/virtual/thermal/thermal_zone%d/mode", i);

				// check to see if the zone is disabled... its okay if there is no mode file...
				char mode[16] = {0};
				if(ReadFileLine(modePath, mode, sizeof(mode))>0 && !strcmp(mode, "disabled"))
					continue;

				// Finally... open the file.
				thermalFiles[i] = OpenFile(tempPath);

				// Check to see if the temperature file was found...
				if(thermalFiles[i] == NullFileHandle)
					continue;

				// Read in the critical temperature value.
				const int tripPoint = ReadIntFile(tripPointPath);
				if(tripPoint > 0)
				{
					SensorSetRange(desc.label, 0, (float)tripPoint, Sensor_Interp_Linear);
				}
			}
		}

		// For clocks, we store the last value and only send updates when it changes since we
		// use blocking chart rendering.
		int lastCpuFreq[maxCpus] = {0};
		int lastGpuFreq          = 0;
		int lastMemValue         = 0;

		UInt32 sampleCount = 0;

		while(!QuitSignaled() && IsConnected())
		{
			// Sample CPU Frequencies...
			for(UInt32 i=0; i<maxCpus; i++)
			{
				// If the 'online' file can't be found, then we just assume this CPU doesn't even exist
				if(cpuOnlineFiles[i] == NullFileHandle)
					continue;

				const SensorLabelDesc &desc   = cpuDescs[i];
				const bool             online = ReadIntFile(cpuOnlineFiles[i]) ? true : false;
				if(online && cpuFreqFiles[i]==NullFileHandle)
				{
					// Open the frequency file if we are online and its not already open...
					char freqPath[64] = {0};
					FormatString(freqPath, sizeof(freqPath), "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq", i);
					cpuFreqFiles[i] = OpenFile(freqPath);
				}
				else if(!online && cpuFreqFiles[i]!=NullFileHandle)
				{
					// close the frequency file if we are no longer online
					CloseFile(cpuFreqFiles[i]);
					cpuFreqFiles[i] = NullFileHandle;
				}
				const int freq = cpuFreqFiles[i]==NullFileHandle ? 0 : ReadIntFile(cpuFreqFiles[i]);
				if(freq != lastCpuFreq[i])
				{
					// Convert from KHz to Hz
					SensorSetValue(desc.label, (float)freq);
					lastCpuFreq[i] = freq;
				}
				ThreadYield();
			}

			// Sample GPU Frequency...
			if(gpuFreqFile != NullFileHandle)
			{
				const int freq = ReadIntFile(gpuFreqFile);
				if(freq != lastGpuFreq)
				{
					SensorSetValue(g_gpuLabel, (float)freq);
					lastGpuFreq = freq;
				}
			}

			// Sample Memory Bandwidth
			if(memFreqFile != NullFileHandle)
			{
				const int value = ReadIntFile(memFreqFile);
				if(value != lastMemValue)
				{
					SensorSetValue(g_memLabel, (float)value);
					lastMemValue = value;
				}
			}

			// Sample thermal sensors...
			if((sampleCount&15) == 0) // sample temperature at a much lower frequency as clocks... thermals don't change that fast.
			{
				for(UInt32 i=0; i<maxThermalSensors; i++)
				{
					FileHandle file = thermalFiles[i];
					if(file != NullFileHandle)
					{
						SensorSetValue(thermalDescs[i].label, (float)ReadIntFile(file));
					}
				}
				ThreadYield();
			}

			// Sleep 5ms between samples...
			ThreadSleepMicroseconds(5000);
			sampleCount++;
		}

		// Close down cached file handles...
		for(UInt32 i=0; i<maxCpus; i++)
		{
			if(cpuOnlineFiles[i] != NullFileHandle) CloseFile(cpuOnlineFiles[i]);
			if(cpuFreqFiles[i]   != NullFileHandle) CloseFile(cpuFreqFiles[i]);
		}
		if(gpuFreqFile != NullFileHandle) CloseFile(gpuFreqFile);
		if(memFreqFile != NullFileHandle) CloseFile(memFreqFile);
		for(UInt32 i=0; i<maxThermalSensors; i++)
		{
			if(thermalFiles[i] != NullFileHandle) CloseFile(thermalFiles[i]);
		}
	}
Пример #12
0
///=====================================================
/// 
///=====================================================
void Thread::YieldThread(){
	ThreadYield();
}
Пример #13
0
/*
 * Class:     org_jdesktop_jdic_dock_internal_impl_UnixDockService
 * Method:    eventLoop
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_org_jdesktop_jdic_dock_internal_impl_UnixDockService_eventLoop(JNIEnv *env, jclass klass)
{
    XEvent        report;
    /*  Enter event loop  */
    static struct pollfd pollFds[2];
    int timeout = 100;
    int result;
    int fdX =  ConnectionNumber(display) ;
    pollFds[0].fd = fdX;
    pollFds[0].events = POLLRDNORM;
    pollFds[0].revents = 0;

   dprintf("Starting event loop ...\n");

    while ( 1 ) {

        (*LockIt)(env);
        while ((XEventsQueued(display, QueuedAfterReading) == 0) &&
                (XEventsQueued(display, QueuedAfterFlush) == 0)) {

            XFlush(display);
            (*UnLockIt)(env);
            ThreadYield(env);
            result = poll( pollFds, 1, (int32_t) timeout );
            (*LockIt)(env);

        }
        XNextEvent(display, &report);
        (*UnLockIt)(env);

        switch ( report.type ) {

            case Expose:
                dprintf("Expose\n");
                break;
            case PropertyNotify:
                dprintf("PropertyNotify\n");
                break;
            case ClientMessage:
                dprintf("ClientMessage\n");
                break;
            case ReparentNotify:
                dprintf("ReparentNotify\n");
                dprintf("window = %x parent = %x\n", report.xreparent.window,report.xreparent.parent);

                break;
            case ConfigureNotify:
                dprintf("ConfigureNotify win = %x x = %d y=%d w=%d h=%d\n",report.xconfigure.window, report.xconfigure.x,report.xconfigure.y, report.xconfigure.width, report.xconfigure.height);
                configureNotify(env,report.xconfigure.window,report.xconfigure.x,report.xconfigure.y, report.xconfigure.width, report.xconfigure.height);

                break;
            case ButtonPress:
                dprintf("ButtonPress\n");
                break;
	    case MapRequest:
		dprintf("MapRequest\n");
		break;
	    case MapNotify:
                dprintf("MapNotify %x\n", report.xconfigure.window);
                break;
	    case UnmapNotify:
                dprintf("UnmapNotify\n");
                break;




        }
    }
}