bool IceUtilInternal::Semaphore::timedWait(const IceUtil::Time& timeout) const { long msec = (long)timeout.toMilliSeconds(); int rc = WaitForSingleObject(_sem, msec); if(rc != WAIT_TIMEOUT && rc != WAIT_OBJECT_0) { throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); } return rc != WAIT_TIMEOUT; }
bool IceUtilInternal::Semaphore::timedWait(const IceUtil::Time& timeout) const { IceUtil::Int64 msTimeout = timeout.toMilliSeconds(); if(msTimeout < 0 || msTimeout > 0x7FFFFFFF) { throw IceUtil::InvalidTimeoutException(__FILE__, __LINE__, timeout); } DWORD rc = WaitForSingleObject(_sem, static_cast<DWORD>(msTimeout)); if(rc != WAIT_TIMEOUT && rc != WAIT_OBJECT_0) { throw IceUtil::ThreadSyscallException(__FILE__, __LINE__, GetLastError()); } return rc != WAIT_TIMEOUT; }
void checkedSleep( gbxutilacfr::Stoppable* activity, const IceUtil::Time& duration, int checkIntervalMs ) { assert( activity && "Null activity pointer" ); // Handle durations less than the check interval if ( duration.toMilliSeconds() < checkIntervalMs ) { IceUtil::ThreadControl::sleep( duration ); return; } IceUtil::Time wakeupTime = IceUtil::Time::now() + duration; IceUtil::Time checkInterval = IceUtil::Time::milliSeconds( checkIntervalMs ); while ( !activity->isStopping() && IceUtil::Time::now() < wakeupTime ) { IceUtil::ThreadControl::sleep( checkInterval ); } }
int main(int argc, char* argv[]) { Ice::InitializationData initData; initData.properties = Ice::createProperties(); initData.properties->load("config"); Ice::CommunicatorPtr communicator = Ice::initialize(argc, argv, initData); if(argc > 1) { cerr << argv[0] << ": too many arguments" << endl; return EXIT_FAILURE; } Freeze::ConnectionPtr connection = Freeze::createConnection(communicator, "backup"); IntLongMap m(connection, "IntLongMap", true); const int size = 10000; if(m.size() == 0) { cout << "********* Creating new map ***********" << endl; Freeze::TransactionHolder txHolder(connection); IceUtil::Time time = IceUtil::Time::now(); IceUtil::Int64 ms = time.toMilliSeconds(); for(int i = 0; i < size; ++i) { m.insert(IntLongMap::value_type(i, ms)); } txHolder.commit(); } cout << "Updating map" << endl; for(;;) { int count = 0; Freeze::TransactionHolder txHolder(connection); IceUtil::Time time = IceUtil::Time::now(); IceUtil::Int64 ms = time.toMilliSeconds(); IntLongMap::iterator p = m.begin(); IceUtil::Int64 oldMs = p->second; do { if(p->second != oldMs) { cerr << "old time (ms) == " << oldMs << endl; cerr << "current current (ms) == " << p->second << endl; } test(p->second == oldMs); p.set(ms); count++; } while(++p != m.end()); cout << "Read " << IceUtil::Time::milliSeconds(oldMs).toDateTime() << " in all records;" << " updating with " << time.toDateTime() << " ... " << flush; txHolder.commit(); cout << "done" << endl; test(count == size); } connection->close(); communicator->destroy(); return EXIT_SUCCESS; }