Example #1
0
static PLT_THREAD* findCurrentThread(void) {
    PLT_THREAD* current_thread;

    PltLockMutex(&thread_list_lock);
    current_thread = thread_head;
    while (current_thread != NULL) {
#if defined(LC_WINDOWS)
        if (current_thread->tid == GetCurrentThreadId()) {
#else
        if (pthread_equal(current_thread->thread, pthread_self())) {
#endif
            break;
        }

        current_thread = current_thread->next;
    }
    PltUnlockMutex(&thread_list_lock);

    LC_ASSERT(current_thread != NULL);
    
    return current_thread;
}
#endif

int PltCreateMutex(PLT_MUTEX* mutex) {
#if defined(LC_WINDOWS)
    *mutex = CreateMutexEx(NULL, NULL, 0, MUTEX_ALL_ACCESS);
    if (!*mutex) {
        return -1;
    }
    return 0;
#else
    return pthread_mutex_init(mutex, NULL);
#endif
}
Example #2
0
void pthread_mutex_init(pthread_mutex_t *mutex, const void* attr)
{
	*mutex = CreateMutexEx(
		NULL,				// default security attributes
		NULL,				// No need to specify a name
		0,					// Flags
		STANDARD_RIGHTS_ALL);				// Default security descriptor
}
//----------------------------------------------------------------------------------------
amf_handle AMF_CDECL_CALL amf_create_mutex(amf_bool bInitiallyOwned, const wchar_t* pName)
{
#if defined(METRO_APP)
    DWORD flags = (bInitiallyOwned) ? CREATE_MUTEX_INITIAL_OWNER : 0;
    return CreateMutexEx(NULL, pName, flags, STANDARD_RIGHTS_ALL);

#else
    return CreateMutexW(NULL, bInitiallyOwned == true, pName);

#endif
}
Example #4
0
	Mutex::Mutex()
	{
#ifdef _WIN32
#ifndef _WINRT // WinXP does not have CreateMutexEx()
		this->handle = CreateMutex(0, 0, 0);
#else
		this->handle = CreateMutexEx(NULL, NULL, 0, SYNCHRONIZE);
#endif
		if (this->handle == 0)
		{
			throw hl_exception("Could not create mutex.");
		}
#else
		this->handle = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t));
		pthread_mutex_init((pthread_mutex_t*)this->handle, 0);
#endif
	}
Example #5
0
/**@ingroup tsk_mutex_group
 * Creates new recursive mutex handle.
 * @param recursive Whether we want a recursive/reentrant mutex or not. For more inforation about reentrant mutexes: http://en.wikipedia.org/wiki/Reentrant_mutex.
 * @retval New mutex handle. It is up to you free the returned handle using  @ref tsk_mutex_destroy.
 * @sa @ref tsk_mutex_destroy.
 */
tsk_mutex_handle_t* tsk_mutex_create_2(tsk_bool_t recursive)
{
    MUTEX_T handle = tsk_null;

#if TSK_UNDER_WINDOWS
#	if TSK_UNDER_WINDOWS_RT
    handle = CreateMutexEx(NULL, NULL, 0x00000000, MUTEX_ALL_ACCESS);
#	else
    handle = CreateMutex(NULL, FALSE, NULL);
#	endif
#else
    int ret;
    pthread_mutexattr_t   mta;

    if((ret = pthread_mutexattr_init(&mta))) {
        TSK_DEBUG_ERROR("pthread_mutexattr_init failed with error code %d", ret);
        return tsk_null;
    }
    if(recursive && (ret = pthread_mutexattr_settype(&mta, TSK_RECURSIVE_MUTEXATTR))) {
        TSK_DEBUG_ERROR("pthread_mutexattr_settype failed with error code %d", ret);
        pthread_mutexattr_destroy(&mta);
        return tsk_null;
    }

    /* if we are here: all is ok */
    handle = tsk_calloc(1, sizeof(MUTEX_S));
    if(pthread_mutex_init((MUTEX_T)handle, &mta)) {
        TSK_FREE(handle);
    }
    pthread_mutexattr_destroy(&mta);
#endif

    if(!handle) {
        TSK_DEBUG_ERROR("Failed to create new mutex.");
    }
    return handle;
}
Example #6
0
NS_CC_BEGIN

void pthread_mutex_init(pthread_mutex_t* m, void* attributes) {
	*m = CreateMutexEx(NULL,FALSE,0,NULL);
}