Exemple #1
0
bool
LocalLockTable::downgrade_lock(handle_t& h, const char *path)
{
	bool result = false;
	string hid = handle_id(h);
	lock_entry_t& e = lookup(path);
	ScopedMutex lock(&e.entry_lock);
	if (e.writer_hid == hid)
	{
		e.writer_hid = "";
		result = true;
	}
	return result;
}
Exemple #2
0
bool ContextClosest::parseCmdArgs(int argc, char **argv, int skipFirstArgs){
	_argc = argc;
	_argv = argv;
	_skipFirstArgs = skipFirstArgs;
	if (_argc < 2) {
		setShowHelp(true);
		return false;
	}

	setProgram(_programNames[argv[0]]);

	_argsProcessed.resize(_argc - _skipFirstArgs, false);

	for (_i=_skipFirstArgs; _i < argc; _i++) {
		if (isUsed(_i - _skipFirstArgs)) {
			continue;
		}
		if (strcmp(_argv[_i], "-c") == 0) {
			//bypass intersect's use of the -c option, because -c
			//means writeCount for intersect, but means columns for map.
			if (!ContextBase::handle_c()) return false;
		}
        else if (strcmp(_argv[_i], "-d") == 0) {
           if (!handle_d()) return false;
        }
        else if (strcmp(_argv[_i], "-D") == 0) {
        	if (!handle_D()) return false;
        }
        else if (strcmp(_argv[_i], "-io") == 0) {
        	if (!handle_io()) return false;
        }
        else if (strcmp(_argv[_i], "-iu") == 0) {
        	if (!handle_iu()) return false;
        }
        else if (strcmp(_argv[_i], "-id") == 0) {
        	if (!handle_id()) return false;
        }
        else if (strcmp(_argv[_i], "-N") == 0) {
        	if (!handle_N()) return false;
        }
        else if (strcmp(_argv[_i], "-t") == 0) {
        	if (!handle_t()) return false;
        }
        else if (strcmp(_argv[_i], "-mdb") == 0) {
        	if (!handle_mdb()) return false;
        }

	}
	return ContextIntersect::parseCmdArgs(argc, argv, _skipFirstArgs);
}
Exemple #3
0
bool
LocalLockTable::read_lock(handle_t& h, const char *path, bool wait)
{
	lock_entry_t& e = lookup(path);
	e.entry_lock.lock();
	while (!e.writer_hid.empty())
	{
		e.entry_lock.unlock();
		e.entry_cv.wait();
		e.entry_lock.lock();
		e.reader_hid.push_front(handle_id(h));
	}
	e.entry_lock.unlock();
	return true;
}
Exemple #4
0
bool
LocalLockTable::is_read_locked(handle_t& h, const char *path)
{
	bool result = false;
#if 1
	string hid = handle_id(h);
	lock_entry_t& e = lookup(path);
	ScopedMutex lock(&e.entry_lock);

	for (string_list_t::iterator it = e.reader_hid.begin(); !result && it != e.reader_hid.end(); it++)
	{
		if (*it == hid)
		{
			result = true;
		}
	}
#endif
	return result;
}
Exemple #5
0
bool
LocalLockTable::unlock(handle_t& h, const char *path)
{
	bool result = false;
	string hid = handle_id(h);
	lock_entry_t& e = lookup(path);
	ScopedMutex lock(&e.entry_lock);
	if (e.writer_hid == hid)
	{
		e.writer_hid = "";
		result = true;
	}
	else
	{
		e.reader_hid.remove(hid);
		result = !(e.writer_hid.empty());
	}

	return result;
}
Exemple #6
0
bool
LocalLockTable::upgrade_lock(handle_t& h, const char *path)
{
	lock_entry_t& e = lookup(path);
	string hid = handle_id(h);
	e.entry_lock.lock();
	while (!e.writer_hid.empty())
	{
		e.entry_lock.unlock();
		e.entry_cv.wait();
		e.entry_lock.lock();
		if (e.writer_hid.empty())
		{
			e.writer_hid = hid;
			e.reader_hid.remove(hid);
		}
	}
	e.entry_lock.unlock();
	return true;
}
Exemple #7
0
bool
LocalLockTable::write_lock(handle_t& h, const char *path, bool wait)
{
	bool result = false;
	lock_entry_t& e = lookup(path);
	string hid = handle_id(h);
	e.entry_lock.lock();
	while (!e.writer_hid.empty() && e.writer_hid != hid)
	{
		e.entry_lock.unlock();
		e.entry_cv.wait();
		e.entry_lock.lock();
		if (e.writer_hid.empty())
		{
			e.writer_hid = hid;
			result = true;
		}
	}
	e.entry_lock.unlock();
	return result;
}