Ejemplo n.º 1
0
bool Thread::sleep(unsigned int time)
{
   bool rval = true;

   // enter an arbitrary monitor
   Monitor m;
   m.enter();
   {
      // wait to re-enter the monitor until the specified time
      uint32_t remaining = time;
      uint64_t st = System::getCurrentMilliseconds();
      uint64_t et;
      uint64_t dt;
      while(rval && (time == 0 || remaining > 0))
      {
         rval = waitToEnter(&m, remaining);
         if(rval && time > 0)
         {
            // update remaining time
            et = System::getCurrentMilliseconds();
            dt = et - st;
            remaining = (dt >= remaining ? 0 : remaining - dt);
            st = et;
         }
      }
   }
   m.exit();

   return rval;
}
Ejemplo n.º 2
0
int main()
{
	try
	{
		win.Read(NULL, 0);
		WugSSH ircsox;
		ircsox.BindProxy("wuggl.es", 22);
		ircsox.Bind("chat.freenode.net", 6667);

		CommandReader ui;

		Monitor iomon;
		iomon.Activate();
		CommandReader *cr = (CommandReader *) iomon.AddDataSource(ui);
		WugSSH *wssh = (WugSSH *) iomon.ConnectDataSocket(ircsox);
		cr->ircsock = wssh;

		while (true) iomon.ServiceRoutine(Interval(1000, 0));
	}
	catch (IOException &ioe)
	{
		wout.Write(String::ToString(ioe.errorcode) + "\n" + ioe.description + "\n");
	}
	return 0;
}
Ejemplo n.º 3
0
void Thread::interrupt()
{
   lock();

   // only interrupt if not already interrupted
   if(!isInterrupted())
   {
      // set interrupted flag
      mInterrupted = true;

      // Note: disabled due to lack of support in windows
      // send SIGINT to thread
      //sendSignal(SIGINT);

      // store thread's current monitor
      Monitor* m = mWaitMonitor;
      unlock();

      // wake up thread it is inside of a monitor
      if(m != NULL)
      {
         m->enter();
         m->signalAll();
         m->exit();
      }
   }
   else
   {
      unlock();
   }
}
Ejemplo n.º 4
0
bool DisplayManager::IsFullscreen(HWND hWnd) {
    HWND fg = GetForegroundWindow();
    if (hWnd == NULL || fg == NULL) {
        return false;
    }

    HWND shell = GetShellWindow();
    if (fg == shell) {
        return false;
    }

    HWND dt = GetDesktopWindow();
    if (fg == dt) {
        return false;
    }

    RECT wndRect = { 0 };
    GetWindowRect(fg, &wndRect);
    Monitor wm = MonitorAtWindow(hWnd);
    if ((wndRect.bottom - wndRect.top) == wm.Height() &&
            (wndRect.right - wndRect.left) == wm.Width()) {
        return true;
    }
    return false;
}
Ejemplo n.º 5
0
MsgBufferModel::MsgBufferModel(QObject *parent)
	:QAbstractTableModel(parent)
{
	/* Object Variables. */
	lastValue = 0;



	/* GUI Refresh. */
	timer = new QTimer(this);
	connect(timer, SIGNAL(timeout()), this, SLOT(timerHit()));
	timer->start(1000);

	/* Monitor Threads. */
	QThread *threadx = new QThread;
	Monitor *monitor = new Monitor;

	connect(monitor, SIGNAL(messageInBuffer(canMessage*)), this, SLOT(newMsg(canMessage*)));
	connect(this, SIGNAL(start()), monitor, SLOT(start()));
	connect(this, SIGNAL(stop()), monitor, SLOT(stop()));
	monitor->moveToThread(threadx);
	threadx->start();

	emit start();
}
Ejemplo n.º 6
0
 ~MutexUnlockerEx() {
   if (_no_safepoint_check == Mutex::_no_safepoint_check_flag) {
     _mutex->lock_without_safepoint_check();
   } else {
     _mutex->lock();
   }
 }
Ejemplo n.º 7
0
bool DirectoryMonitor::Server::addDirectory(const string& aPath) throw(MonitorException) {
	{
		RLock l(cs);
		if (monitors.find(aPath) != monitors.end())
			return false;
	}

	init();

	Monitor* mon = new Monitor(aPath, this, 0, 32 * 1024, true);
	try {
		mon->openDirectory(m_hIOCP);

		{
			WLock l(cs);
			mon->beginRead();
			monitors.emplace(aPath, mon);
			failedDirectories.erase(aPath);
		}
	} catch (MonitorException& e) {
		mon->stopMonitoring();
		delete mon;

		{
			WLock l(cs);
			failedDirectories.insert(aPath);
		}

		throw e;
	}

	return true;
}
Ejemplo n.º 8
0
    CFDataRef Monitor::receive_request(CFMessagePortRef local, SInt32 msgid, CFDataRef data, void *info) {
        Monitor *monitor = (Monitor *)info;
        CFIndex length = CFDataGetLength(data);
        memcpy(monitor->_request, CFDataGetBytePtr(data), length);

        CFDataRef reply = monitor->_response_buffer = CFDataCreateMutable(kCFAllocatorMallocZone, 0);
        
        // sample the stack.
        monitor->_stack_bottom = (void*) auto_get_sp();
        
        // scan args
        monitor->tokenize_args();
        
        // prevent the collector from collecting until we've processed the request.
        Zone *zone = Zone::zone();
        if (zone) zone->block_collector();

        // process request generating report
        monitor->process_request();
        
        // unblock the collector.
        if (zone) zone->unblock_collector();

        // return the response.
        CFDataAppendBytes(monitor->_response_buffer, (const UInt8*)"\0", 1);
        monitor->_response_buffer = NULL;
        return reply;
    }
Ejemplo n.º 9
0
static void *handle_connection(void *c) {
    size_t r_len = 1;
    Monitor *monitor = new Monitor();
    Connection *conn = (Connection *)c;
    char *data = NULL;
    
    syslog(LOG_INFO, "accepted connection from engine: %s", conn->address());

    while(r_len != 0) {
        try {
            data = conn->receive(data);
            if (r_len < 1 || data == NULL) continue;
            process_command(conn, monitor, data);
            free(data);
            data = NULL;
        } catch(char const* ex) {
            syslog(LOG_ERR, "%s", ex);
            continue;
        }
    }

    syslog(LOG_INFO, "disconnected from engine: %s", conn->address());

    if (monitor != NULL) {
        monitor->terminate();
        monitor->stop();
        delete monitor;
    }
    conn->terminate();
    delete conn;
}
Ejemplo n.º 10
0
/* Given a jvmtiEnv* and jobject, find the Monitor instance or create one */
Monitor *
Agent::get_monitor(jvmtiEnv *jvmti, JNIEnv *env, jobject object)
{
    jvmtiError err;
    Monitor   *m;
    jlong      tag;

    m   = NULL;
    tag = (jlong)0;
    err = jvmti->GetTag(object, &tag);
    check_jvmti_error(jvmti, err, "get tag");
    /*LINTED*/
    m = (Monitor *)(void *)(ptrdiff_t)tag;
    if ( m == NULL ) {
        m = new Monitor(jvmti, env, object);
        /* Save monitor on list */
        if (monitor_count == monitor_list_size) {
            monitor_list_size += monitor_list_grow_size;
            monitor_list = (Monitor**)realloc((void*)monitor_list,
                (monitor_list_size)*(int)sizeof(Monitor*));
        }
        monitor_list[monitor_count] = m;
        m->set_slot(monitor_count);
        monitor_count++;
        /*LINTED*/
        tag = (jlong)(ptrdiff_t)(void *)m;
        err = jvmti->SetTag(object, tag);
        check_jvmti_error(jvmti, err, "set tag");
    }
    return m;
}
Ejemplo n.º 11
0
inline void Monitor::executor_callback(const char *name, NDArrayHandle handle,
    void *monitor_ptr) {
  Monitor *monitor = static_cast<Monitor*>(monitor_ptr);
  if (monitor->activated && std::regex_match(name, monitor->pattern)) {
    monitor->stats.emplace_back(monitor->step, name, monitor->stat_func(NDArray(handle)));
  }
}
    void run() {
        m.wait();
	cout << "Done waiting in second thread." << endl;
	sleep_in_seconds(5);
	m.notify();
	sleep_in_seconds(5);
    }
Ejemplo n.º 13
0
void MonitorTests::multiThreadedCallBackTest()
{
    beginTest("Concurrent CallBack Test");
    
    Monitor monitor;
    monitor.startMonitoring();
    
    
    OwnedArray<SocketListener> listeners;
    
    for (int i = 0; i < 50 ; i++) {
        SocketListener* listener = new SocketListener();
        listener->initializeSockets((40780 + (5*i)), &monitor, String("quassel") + String(i*20));
        listeners.add(listener);
    }
    
    for (int i = 0; i < 50 ; i++) {
        pool->addJob(listeners[i], false);
    }
    
    while(pool->getNumJobs() > 0 )
    {
        Thread::sleep(20);
    }
    
    monitor.stop();
    for (int i = 0; i < 50 ; i++) {
        
        expectEquals(listeners[i]->was_informed , true);
        
    }
    
}
void *MDnsSdListener::Monitor::threadStart(void *obj) {
    Monitor *monitor = reinterpret_cast<Monitor *>(obj);

    monitor->run();
    delete monitor;
    pthread_exit(NULL);
    return NULL;
}
Ejemplo n.º 15
0
 static void malloc_block_recorder(task_t task, void *context, unsigned type, vm_range_t *range, unsigned count) {
     Monitor *monitor = reinterpret_cast<Monitor*>(context);
     for (unsigned i = 0; i < count; i++, range++) {
         monitor->print("block");
         monitor->send_malloc_block_info((void*)range->address, range->size);
         monitor->print("\n");
     }
 }
Ejemplo n.º 16
0
std::string Dashboard::Watch(const std::string& name) {
  std::lock_guard<std::mutex> l(m_);
  std::string result;
  if (record_.find(name) == record_.end()) return result;
  Monitor* monitor = record_[name];
  CHECK_NOTNULL(monitor);
  return monitor->info_string();
}
Ejemplo n.º 17
0
void expireTest(int64_t numWorkers, int64_t expirationTimeMs) {
  int64_t maxPendingTasks = numWorkers;
  size_t activeTasks = numWorkers + maxPendingTasks;
  Monitor monitor;

  std::shared_ptr<ThreadManager> threadManager =
    ThreadManager::newSimpleThreadManager(numWorkers, maxPendingTasks);
  std::shared_ptr<PosixThreadFactory> threadFactory =
    std::shared_ptr<PosixThreadFactory>(new PosixThreadFactory());
  threadManager->threadFactory(threadFactory);
  threadManager->setExpireCallback(
      std::bind(expireTestCallback, std::placeholders::_1,
                     &monitor, &activeTasks));
  threadManager->start();

  // Add numWorkers + maxPendingTasks to fill up the ThreadManager's task queue
  std::vector<std::shared_ptr<BlockTask>> tasks;
  tasks.reserve(activeTasks);

  Monitor bmonitor;
  bool blocked = true;
  for (int64_t n = 0; n < numWorkers + maxPendingTasks; ++n) {
    std::shared_ptr<BlockTask> task(new BlockTask(&monitor, &bmonitor,
                                             &blocked, &activeTasks));
    tasks.push_back(task);
    threadManager->add(task, 0, expirationTimeMs);
  }

  // Sleep for more than the expiration time
  usleep(expirationTimeMs * Util::US_PER_MS * 1.10);

  // Unblock the tasks
  {
    Synchronized s(bmonitor);
    blocked = false;
    bmonitor.notifyAll();
  }
  // Wait for all tasks to complete or expire
  {
    Synchronized s(monitor);
    while (activeTasks != 0) {
      monitor.wait();
    }
  }

  // The first numWorkers tasks should have completed,
  // the remaining ones should have expired without running
  size_t index = 0;
  for (const auto& task : tasks) {
    if (index < numWorkers) {
      BOOST_CHECK(tasks[index]->started_);
    } else {
      BOOST_CHECK(!tasks[index]->started_);
    }
    ++index;
  }
}
Ejemplo n.º 18
0
void Kernel::serialize() {

    for (LMonitor::iterator it = monitors_->begin();
         it != monitors_->end(); it++)
    {
        Monitor *monitor = *it;
        monitor->serialize();
    }
}
Ejemplo n.º 19
0
void Kernel::initWindows() {

    for (LMonitor::iterator it = monitors_->begin();
         it != monitors_->end(); it++)
    {
        Monitor *monitor = (Monitor *)*it;
        monitor->scanWindows();
    }
}
Ejemplo n.º 20
0
/* This function is called once at start up ----------------------------------*/
void setup()
{
    //Initialize the Monitor
    mon.begin();
    
    //Set up the variables to be monitored
    mon.variable("robotSays",roboto,STRING);
    mon.variable("random",&rondo,INT);
    
}
Ejemplo n.º 21
0
 Thread_Impl(concurrent_queue<Task *> &q, Monitor &mon)
   : queue(q)
   , monitor(mon.GetMutex())
   , live(true)
   , started(false)
   , thread(ThreadFunction, ThreadFunctionArg(*this, started)) {
     while(!started){
         monitor.NotifyAll();
     }
 }
Ejemplo n.º 22
0
void MonitorManager::updateAudioIcons()
{
    Monitor *m = static_cast<Monitor *> (m_activeMonitor);
    if (!m) return;
    int volume = m->render->volume();
    m_muteAction->blockSignals(true);
    m_muteAction->setChecked(volume == 0);
    m_muteAction->blockSignals(false);
    m->mute(volume == 0, true);
}
Ejemplo n.º 23
0
void Kernel::updateBars() {

    for (LMonitor::iterator it = monitors_->begin();
         it != monitors_->end(); it++)
    {
        Monitor *monitor = (Monitor *)*it;
        monitor->statusBar()->illuminate();
        monitor->clientBar()->illuminate();
    }
}
Ejemplo n.º 24
0
int main(int argc, char* argv[])
{
  Monitor<std::stringstream> ss;

  std::vector<std::thread> threads;

  
	threads.emplace_back([&]()
                       {
                         ss([](auto& ss)
                                   {
                                     ss << "Hello 1 : "
                                        << std::this_thread::get_id()
                                        << std::endl;
                                   });
                       });
  
	threads.emplace_back([&]()
                       {
                         ss([](auto& ss)
                                   {
                                     ss << "Hello 2 : "
                                        << std::this_thread::get_id()
                                        << std::endl;
                                   });
                       });
  
	threads.emplace_back([&]()
                       {
                         ss([](auto& ss)
                                   {
                                     ss << "Hello 3 : "
                                        << std::this_thread::get_id()
                                        << std::endl;
                                   });
                       });
  
	threads.emplace_back([&]()
                       {
                         ss([](auto& ss)
                                   {
                                     ss << "Hello 4 : "
                                        << std::this_thread::get_id()
                                        << std::endl;
                                   });
                       });

  for (auto& t : threads)
  {
    t.join();
  }

	ss([](auto& ss){ std::cout << ss.str() << std::endl; });
}
Ejemplo n.º 25
0
 MutexLockerEx(Monitor * mutex, bool no_safepoint_check = !Mutex::_no_safepoint_check_flag) {
   _mutex = mutex;
   if (_mutex != NULL) {
     assert(mutex->rank() > Mutex::special || no_safepoint_check,
       "Mutexes with rank special or lower should not do safepoint checks");
     if (no_safepoint_check)
       _mutex->lock_without_safepoint_check();
     else
       _mutex->lock();
   }
 }
Ejemplo n.º 26
0
int main(int argc, char* argv[])
{
    Monitor monitor;

    monitor.Initialize();
    if (monapi_notify_server_start("INIT") != M_OK) {
        exit(-1);
    }
    monitor.Service();
    return 0;
}
Ejemplo n.º 27
0
void Kernel::grabShortcutOnAllMonitors(Shortcut *shortcut) {

    Binder *bm = Binder::instance();

    for (LMonitor::iterator it = monitors_->begin();
         it != monitors_->end(); it++)
    {
        Monitor *monitor = (Monitor *)*it;
        bm->grabShortcut(shortcut, monitor->rootWindow());
    }
}
int main (int argc, char *argv[]) {
    Thread t;
    t.start(*new MarkTime);
    sleep_in_seconds(5);
    m.notify();
    m.wait();
    cout << "Done waiting in main thread." << endl;
    t.lock();
    return 0;
    // It will take a while for the return to complete, because it
    // locks t, which waits on the completion of its thread.
}
Ejemplo n.º 29
0
 void go2sleep(int thread, int seconds) {
   Monitor m;
   Synchronized s(m);
   for (int i = 0; i < seconds; ++i) {
     fprintf(stderr, "Thread %d: sleep %d\n", thread, i);
     try {
       m.wait(1000);
     } catch(const TimedOutException&) {
     }
   }
   fprintf(stderr, "THREAD %d DONE\n", thread);
 }
Ejemplo n.º 30
0
void Kernel::initKeys() {

    XCORE->ungrabKeyboard();
    Binder *bm = Binder::instance();

    for (LMonitor::iterator it = monitors_->begin();
         it != monitors_->end(); it++)
    {
        Monitor *monitor = (Monitor *)*it;
        bm->initKeys(monitor->rootWindow());
    }
}