Ejemplo n.º 1
0
bool ReadWriteLock::BeginWriteTimeout(long milliseconds)
{
	const int sleepMillis = 5;
	StopWatch watch;
	watch.Start();
	do
	{
		RETURN_TRUE_IF_TRUE(TryBeginWrite());
		Thread::Sleep(sleepMillis);
		watch.Shot();
	} while (watch.ElapsedMilliseconds() < milliseconds);
	return false;
}
Ejemplo n.º 2
0
bool ReadWriteLock::BeginReadTimeout(long milliseconds)
{
#if defined(MEDUSA_ANDROID)||defined(MEDUSA_IOS)
	const int sleepMillis = 5;
	StopWatch watch;
	watch.Start();
	do
	{
		RETURN_TRUE_IF_TRUE(TryBeginRead());
		Thread::Sleep(sleepMillis);
		watch.Shot();
	} while (watch.ElapsedMilliseconds() < milliseconds);
	return false;

#else
	struct timespec abstime = PerformanceCounter::ToAbsoluteTime(milliseconds);
	int result = pthread_rwlock_timedrdlock(&mLock, &abstime);
	return result == 0;
#endif
}
Ejemplo n.º 3
0
int main()
{
    int vertex;
    string str;
    Graph InitialGraph;
    pair<int, int> tuple;
    vector<string> tokens;
    StopWatch watch;

    ifstream ff("dijkstraData.txt");

    while(ff.good())
    {
        getline(ff, str);
        tokens = Tokenize(str);
        vertex = atoi(tokens[0].c_str());
        for (unsigned i = 1; i<tokens.size(); i++)
        {
            tuple = Split(tokens[i]);
            InitialGraph.AddEdge(Edge(vertex, tuple.first), tuple.second);
        }
    }
    ff.close();

    watch.Start();

    InitialGraph.ShortestPath(1);

    watch.Stop();

    cout << "Tempo impiegato: " << watch.ElapsedMilliseconds() << endl;

//    clock_t end = clock();
//    double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;
//    cout << "Tempo impiegato: " << elapsed_secs << endl;

    return 0;
}