PLASMA  2.4.5
PLASMA - Parallel Linear Algebra for Scalable Multi-core Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
quarkwinthread.h File Reference
#include <windows.h>
Include dependency graph for quarkwinthread.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pthread_s
struct  pthread_cond_s

Macros

#define PTHREAD_MUTEX_INITIALIZER   ((pthread_mutex_t) -1)
#define PTHREAD_SCOPE_SYSTEM   1
#define QUARK_DLLPORT
#define QUARK_CDECL   __cdecl

Typedefs

typedef struct pthread_s pthread_t
typedef HANDLE pthread_mutex_t
typedef int pthread_mutexattr_t
typedef int pthread_attr_t
typedef int pthread_condattr_t
typedef struct pthread_cond_s pthread_cond_t

Functions

QUARK_DLLPORT pthread_t QUARK_CDECL pthread_self (void)
QUARK_DLLPORT int QUARK_CDECL pthread_mutex_init (pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
QUARK_DLLPORT int QUARK_CDECL pthread_mutex_destroy (pthread_mutex_t *mutex)
QUARK_DLLPORT int QUARK_CDECL pthread_mutex_lock (pthread_mutex_t *mutex)
QUARK_DLLPORT int QUARK_CDECL pthread_mutex_trylock (pthread_mutex_t *mutex)
QUARK_DLLPORT int QUARK_CDECL pthread_mutex_unlock (pthread_mutex_t *mutex)
QUARK_DLLPORT int QUARK_CDECL pthread_attr_init (pthread_attr_t *attr)
QUARK_DLLPORT int QUARK_CDECL pthread_attr_destroy (pthread_attr_t *attr)
QUARK_DLLPORT int QUARK_CDECL pthread_attr_setscope (pthread_attr_t *attr, int scope)
QUARK_DLLPORT int QUARK_CDECL pthread_create (pthread_t *tid, const pthread_attr_t *attr, void *(*start)(void *), void *arg)
QUARK_DLLPORT int QUARK_CDECL pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr)
QUARK_DLLPORT int QUARK_CDECL pthread_cond_destroy (pthread_cond_t *cond)
QUARK_DLLPORT int QUARK_CDECL pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
QUARK_DLLPORT int QUARK_CDECL pthread_cond_broadcast (pthread_cond_t *cond)
QUARK_DLLPORT int QUARK_CDECL pthread_join (pthread_t thread, void **value_ptr)
QUARK_DLLPORT int QUARK_CDECL pthread_equal (pthread_t thread1, pthread_t thread2)
QUARK_DLLPORT int QUARK_CDECL pthread_setconcurrency (int)
QUARK_DLLPORT unsigned int
QUARK_CDECL 
pthread_self_id (void)

Detailed Description

This file handles the mapping from pthreads calls to windows threads QUARK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley and Univ. of Colorado Denver

Version:
2.4.5
Author:
Piotr Luszczek
Date:
2010-11-15

Note : this file is a copy of a PLASMA file for use of QUARK in a standalone library updated by Asim YarKhan

Definition in file quarkwinthread.h.


Macro Definition Documentation

#define PTHREAD_MUTEX_INITIALIZER   ((pthread_mutex_t) -1)

Definition at line 47 of file quarkwinthread.h.

#define PTHREAD_SCOPE_SYSTEM   1

Definition at line 49 of file quarkwinthread.h.

#define QUARK_CDECL   __cdecl

Definition at line 52 of file quarkwinthread.h.

#define QUARK_DLLPORT

Definition at line 51 of file quarkwinthread.h.


Typedef Documentation

typedef int pthread_attr_t

Definition at line 35 of file quarkwinthread.h.

typedef int pthread_condattr_t

Definition at line 36 of file quarkwinthread.h.

Definition at line 33 of file quarkwinthread.h.

typedef int pthread_mutexattr_t

Definition at line 34 of file quarkwinthread.h.

typedef struct pthread_s pthread_t

Function Documentation

QUARK_DLLPORT int QUARK_CDECL pthread_attr_destroy ( pthread_attr_t attr)

Definition at line 125 of file plasmawinthread.c.

{
*attr = 0;
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_attr_init ( pthread_attr_t attr)

Definition at line 120 of file plasmawinthread.c.

{
*attr = 1;
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_attr_setscope ( pthread_attr_t attr,
int  scope 
)

Definition at line 130 of file plasmawinthread.c.

References PTHREAD_SCOPE_SYSTEM.

{
if (*attr != 1)
return -1;
if (scope != PTHREAD_SCOPE_SYSTEM)
return -1;
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_cond_broadcast ( pthread_cond_t cond)

Definition at line 237 of file plasmawinthread.c.

References pthread_cond_s::cs, pthread_cond_s::hEvt, pthread_cond_s::hSem, and pthread_cond_s::waitCount.

{
int more_waiters = 0;
/* This is needed to ensure exclusive access to "waitCount" */
EnterCriticalSection (&cond->cs);
if (cond->waitCount > 0) {
/* always are broadcasting - no need for pthread_cond_singal() case */
more_waiters = 1;
}
if (more_waiters) {
/* this will wake up all the waiters atomically at once. */
ReleaseSemaphore(cond->hSem, cond->waitCount, 0);
LeaveCriticalSection(&cond->cs);
/* Wait for all the awakened threads to acquire the counting semaphore. */
WaitForSingleObject(cond->hEvt, INFINITE);
} else
LeaveCriticalSection(&cond->cs);
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_cond_destroy ( pthread_cond_t cond)

Definition at line 195 of file plasmawinthread.c.

References pthread_cond_s::cs, pthread_cond_s::hEvt, and pthread_cond_s::hSem.

{
DeleteCriticalSection( &cond->cs );
CloseHandle( cond->hSem );
CloseHandle( cond->hEvt );
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_cond_init ( pthread_cond_t cond,
const pthread_condattr_t attr 
)

Definition at line 181 of file plasmawinthread.c.

References pthread_cond_s::cs, FALSE, pthread_cond_s::hEvt, pthread_cond_s::hSem, and pthread_cond_s::waitCount.

{
InitializeCriticalSection( &cond->cs );
cond->hSem = CreateSemaphore( NULL, /* no security attributes */
0, /* initial count */
LONG_MAX, /* maximum count*/
NULL ); /* unnamed semaphore */
cond->hEvt = CreateEvent( NULL, /* no security attributes */
FALSE, /* reset to not-singaled automatically */
FALSE, /* set initial status to not-signaled */
NULL ); /* unnamed event */
cond->waitCount = 0;
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_cond_wait ( pthread_cond_t cond,
pthread_mutex_t mutex 
)

Definition at line 202 of file plasmawinthread.c.

References pthread_cond_s::cs, FALSE, pthread_cond_s::hEvt, pthread_cond_s::hSem, PTHREAD_MUTEX_INITIALIZER, and pthread_cond_s::waitCount.

{
int last;
if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) pthread_mutex_check_for_static_initialization( mutex );
/* Avoid race condition on waiting thread counter. */
EnterCriticalSection(&cond->cs);
cond->waitCount++;
LeaveCriticalSection(&cond->cs);
/* Releases _atomically_ the mutex and wait on the semaphore until
pthread_cond_signal() or pthread_cond_broadcast() are called (by another thread). */
SignalObjectAndWait(*mutex, cond->hSem, INFINITE, FALSE);
/* Avoid race condition on waiting thread counter. */
EnterCriticalSection(&cond->cs);
cond->waitCount--; /* this thread doesn't wait any more */
/* if this is the last thread to have waited */
last = cond->waitCount == 0;
LeaveCriticalSection(&cond->cs);
/* If this thread is the last waiter thread during this particular broadcast
then let all the other threads proceed. */
if (last)
/* This call ensures that two things happen atomically: signaling the hEvt event and
waiting until "mutex" can be acquired. */
SignalObjectAndWait(cond->hEvt, *mutex, INFINITE, FALSE);
else
WaitForSingleObject(*mutex, INFINITE); /* Upon return, this thread has to own "mutex". */
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_create ( pthread_t tid,
const pthread_attr_t attr,
void *(*)(void *)  start,
void *  arg 
)

Definition at line 150 of file plasmawinthread.c.

References HANDLE, pthread_s::hThread, PLASMA_realThStart, PLASMA_winThStart(), QUARK_realThStart, QUARK_winThStart(), and pthread_s::uThId.

{
/* this assumes that the threads call the same function, always; it also assumes there
is no race condition while assigning a pointer and using it from within threads
(this assumption is fulfilled by creating the new thread in suspended state) */
thread->hThread = (HANDLE)_beginthreadex(
NULL, /* default security */
0, /* stack size: use the size of calling thread */
arg,
CREATE_SUSPENDED,
/*0,*/ /* the thread will run immedietally (rather than get suspended) */
&thread->uThId );
/* We need to make sure that _beginthreadex() returns to the parent thread first
so we can safely fill up the members of the pthread_t structure without possible
race conditions. If the new thread is created in supsended state we eliminate
the race condition but now we have to resume the new thread. */
ResumeThread( thread->hThread );
return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_equal ( pthread_t  thread1,
pthread_t  thread2 
)

Definition at line 40 of file plasmawinthread.c.

References pthread_s::uThId.

{
if (thread1.uThId == thread2.uThId) // && thread1.hThread == thread2.hThread)
return 1;
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_join ( pthread_t  thread,
void **  value_ptr 
)

Definition at line 175 of file plasmawinthread.c.

References pthread_s::hThread.

{
WaitForSingleObject( thread.hThread, INFINITE );
CloseHandle( thread.hThread );
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_mutex_destroy ( pthread_mutex_t mutex)

Definition at line 115 of file plasmawinthread.c.

{
CloseHandle( *mutex );
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_mutex_init ( pthread_mutex_t mutex,
const pthread_mutexattr_t attr 
)

no security atributes

not owned (initialy) by the creating thread

no name provided: cannot be shared between processes

no security atributes

not owned (initialy) by the creating thread

no name provided: cannot be shared between processes

Definition at line 46 of file plasmawinthread.c.

References FALSE.

{
*mutex =
CreateMutex( NULL,
NULL
);
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_mutex_lock ( pthread_mutex_t mutex)

the wait was succesful

the wait failed

thread killed during the wait

impossible because of INFINITE

the wait was succesful

the wait failed

thread killed during the wait

impossible because of INFINITE

Definition at line 70 of file plasmawinthread.c.

References PTHREAD_MUTEX_INITIALIZER.

{
DWORD rv;
if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) pthread_mutex_check_for_static_initialization( mutex );
rv = WaitForSingleObject( *mutex, INFINITE );
switch (rv) {
case WAIT_OBJECT_0:
return 0;
case WAIT_FAILED:
return -1;
case WAIT_ABANDONED:
return -1;
case WAIT_TIMEOUT:
return -1;
default:
return -1;
}
}

Here is the caller graph for this function:

QUARK_DLLPORT int QUARK_CDECL pthread_mutex_trylock ( pthread_mutex_t mutex)

the wait was succesful

the wait failed

thread killed during the wait

impossible because of INFINITE

the wait was succesful

the wait failed

thread killed during the wait

impossible because of INFINITE

Definition at line 89 of file plasmawinthread.c.

References PTHREAD_MUTEX_INITIALIZER.

{
DWORD rv;
if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) pthread_mutex_check_for_static_initialization( mutex );
rv = WaitForSingleObject( *mutex, 0 );
switch (rv) {
case WAIT_OBJECT_0:
return 0;
case WAIT_FAILED:
return -1;
case WAIT_ABANDONED:
return -1;
case WAIT_TIMEOUT:
return -1;
default:
return -1;
}
}
QUARK_DLLPORT int QUARK_CDECL pthread_mutex_unlock ( pthread_mutex_t mutex)

Definition at line 108 of file plasmawinthread.c.

{
if (! ReleaseMutex( *mutex ))
return -1;
return 0;
}

Here is the caller graph for this function:

QUARK_DLLPORT pthread_t QUARK_CDECL pthread_self ( void  )

Definition at line 32 of file plasmawinthread.c.

References pthread_s::hThread, and pthread_s::uThId.

{
pt.hThread = GetCurrentThread();
pt.uThId = GetCurrentThreadId();
return pt;
}

Here is the caller graph for this function:

QUARK_DLLPORT unsigned int QUARK_CDECL pthread_self_id ( void  )

Definition at line 28 of file plasmawinthread.c.

{
return GetCurrentThreadId();
}
QUARK_DLLPORT int QUARK_CDECL pthread_setconcurrency ( int  )

Definition at line 264 of file plasmawinthread.c.

{
return 0;
}