Example #1
0
BOOL MutexCloseHandle(HANDLE handle)
{
	WINPR_MUTEX* mutex = (WINPR_MUTEX*) handle;
	int rc;

	if (!MutexIsHandled(handle))
		return FALSE;

	rc = pthread_mutex_trylock(&mutex->mutex);
	switch(rc)
	{
		case 0: /* The mutex is now locked. */
			break;
		/* If we already own the mutex consider it a success. */
		case EDEADLK:
		case EBUSY:
			break;
		default:
#if defined(WITH_DEBUG_MUTEX)
		{
			size_t used = 0, i;
			void* stack = winpr_backtrace(20);
			char **msg = NULL;

			if (stack)
				msg = winpr_backtrace_symbols(stack, &used);

			if (msg)
			{
				for(i=0; i<used; i++)
					WLog_ERR(TAG, "%2d: %s", i, msg[i]);
			}
			free (msg);
			winpr_backtrace_free(stack);
		}
#endif
		WLog_ERR(TAG, "pthread_mutex_trylock failed with %s [%d]", strerror(rc), rc);
		return FALSE;
	}

	rc = pthread_mutex_unlock(&mutex->mutex);
	if (rc != 0)
	{
		WLog_ERR(TAG, "pthread_mutex_unlock failed with %s [%d]", strerror(rc), rc);
		return FALSE;
	}

	rc = pthread_mutex_destroy(&mutex->mutex);
	if (rc != 0)
	{
		WLog_ERR(TAG, "pthread_mutex_destroy failed with %s [%d]", strerror(rc), rc);
		return FALSE;
	}

	free(handle);

	return TRUE;
}
Example #2
0
static int MutexGetFd(HANDLE handle)
{
	WINPR_MUTEX *mux = (WINPR_MUTEX *)handle;
	if (!MutexIsHandled(handle))
		return -1;

	/* TODO: Mutex does not support file handles... */
	(void)mux;
	return -1;
}
Example #3
0
BOOL MutexCloseHandle(HANDLE handle)
{
	WINPR_MUTEX* mutex = (WINPR_MUTEX*) handle;
	int rc;

	if (!MutexIsHandled(handle))
		return FALSE;

	if ((rc = pthread_mutex_destroy(&mutex->mutex)))
	{
		WLog_ERR(TAG, "pthread_mutex_destroy failed with %s [%d]", strerror(rc), rc);
#if defined(WITH_DEBUG_MUTEX)
		{
			size_t used = 0, i;
			void* stack = winpr_backtrace(20);
			char **msg = NULL;

			if (stack)
				msg = winpr_backtrace_symbols(stack, &used);

			if (msg)
			{
				for(i=0; i<used; i++)
					WLog_ERR(TAG, "%2"PRIdz": %s", i, msg[i]);
			}
			free (msg);
			winpr_backtrace_free(stack);
		}
#endif
		/**
		 * Note: unfortunately we may not return FALSE here since CloseHandle(hmutex) on
		 * Windows always seems to succeed independently of the mutex object locking state
		 */
	}

	free(handle);

	return TRUE;
}