Esempio n. 1
0
int get_shmem_lock(const char *caller_file_name, int caller_line_number)
{
	unsigned int i = 0;

#ifdef PARAM_LOCK_DEBUG
	PX4_INFO("lock value %d before get from %s, line: %d\n", mem_lock.value, strrchr(caller_file_name, '/'),
		 caller_line_number);
#endif

	while (!atomic_compare_and_set(&mem_lock, 1, 0)) {
		i++;
		usleep(1000);

		if (i > 100) {
			break;
		}
	}

	if (i > 100) {
		PX4_INFO("Could not get lock, file name: %s, line number: %d.\n",
			 strrchr(caller_file_name, '/'), caller_line_number);
		return -1;

	} else {
		PX4_DEBUG("Lock acquired, file name: %s, line number: %d\n",
			  caller_file_name, caller_line_number);
	}

	return 0; //got the lock

}
Esempio n. 2
0
int get_shmem_lock(const char *caller_file_name, int caller_line_number)
{
	// TODO: don't do this for now
	return 0;

	unsigned char *lock = (unsigned char *)(MAP_ADDRESS + LOCK_OFFSET);
	unsigned int i = 0;

	while (!atomic_compare_and_set(lock, 1, 0)) {
		PX4_INFO("Could not get lock, file name: %s, line number: %d.\n",
			 caller_file_name, caller_line_number);
		i++;
		usleep(1000);

		if (i > 100) { break; }
	}

	if (i > 100) {
		return -1;

	} else {
		PX4_DEBUG("Lock acquired, file name: %s, line number: %d\n", caller_file_name, caller_line_number);
	}

	return 0; //got the lock

}