本文整理汇总了C++中Monitor类的典型用法代码示例。如果您正苦于以下问题:C++ Monitor类的具体用法?C++ Monitor怎么用?C++ Monitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Monitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sleep
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;
}
示例2: main
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;
}
示例3: lock
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();
}
}
示例4: GetForegroundWindow
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;
}
示例5: QTimer
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();
}
示例6: throw
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;
}
示例7: receive_request
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;
}
示例8: Monitor
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;
}
示例9: check_jvmti_error
/* 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;
}
示例10: executor_callback
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)));
}
}
示例11: beginTest
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);
}
}
示例12:
void *MDnsSdListener::Monitor::threadStart(void *obj) {
Monitor *monitor = reinterpret_cast<Monitor *>(obj);
monitor->run();
delete monitor;
pthread_exit(NULL);
return NULL;
}
示例13: malloc_block_recorder
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");
}
}
示例14: l
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();
}
示例15: expireTest
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;
}
}