MDAT library interface functions.
More...
Go to the source code of this file.
|
typedef const char *(* | CheckerFuncPtr )(int, const char *, const char *) |
| Function pointer type for checker function. More...
|
|
|
void | mdat_init (int numThreads, char *traceName, CheckerFuncPtr checkerFunc, int useInteractive, int useSeed, unsigned int seed) |
| Initializes MDAT library. More...
|
|
void | mdat_thread_start (int id, const char *property) |
| Starts a thread. More...
|
|
void | mdat_thread_finish () |
| Mark the currently running thread as completed. More...
|
|
void | mdat_invoke_scheduler (int location) |
| Invokes the scheduler, possibly causing a new thread to run. More...
|
|
void | mdat_mutex_init (const char *name, pthread_mutex_t *lock, pthread_mutexattr_t *attr) |
| Registers a new mutex lock. More...
|
|
void | mdat_mutex_lock (pthread_mutex_t *lock) |
| Implements the lock operation. More...
|
|
void | mdat_mutex_unlock (pthread_mutex_t *lock) |
| Implements the unlock operation. More...
|
|
void | mdat_sem_init (const char *name, sem_t *sem, int pshared, int value) |
| Registers a new semaphore. More...
|
|
void | mdat_sem_wait (sem_t *sem) |
| Implements the wait operation for a semaphore. More...
|
|
void | mdat_sem_post (sem_t *sem) |
| Implements the post operation for a semaphore. More...
|
|
void | mdat_enter_section (const char *section) |
| Enters the specific section. More...
|
|
This file contains the external library functions for MDAT.
typedef const char *(* CheckerFuncPtr)(int, const char *, const char *) |
See the CheckerWrapper documentation for more on the checker callback function.
void mdat_init |
( |
int |
numThreads, |
|
|
char * |
traceName, |
|
|
CheckerFuncPtr |
checkerFunc, |
|
|
int |
useInteractive, |
|
|
int |
useSeed, |
|
|
unsigned int |
seed |
|
) |
| |
This function initializes the MDAT library. The application must call mdat_init before calling any other functions.
- Parameters
-
[in] | numThreads | Number of threads that will concurrently executing. |
[in] | traceName | Name of the output trace file. Set to NULL to suppress tracing. |
[in] | checkerFunc | Program-specific checker. Set to NULL for no checker. |
[in] | useInteractive | If nonzero (true), interactive scheduling is used. Otherwise, random scheduling is used. |
[in] | useSeed | If nonzero (true), use the seed parameter as the random seed. If zero (false), generate a random seed based on the current time. This parameter is ignored if interactive scheduling is used. |
[in] | seed | The specified random seed. This parameter is ignored if interactive scheduling is used or if useSeed is zero. |
void mdat_thread_start |
( |
int |
id, |
|
|
const char * |
property |
|
) |
| |
This function registers a thread with MDAT. This function must be called before a thread makes any synchronization calls. MDAT takes over the scheduling of the thread in this function – threads may wait in this function until they are dispatched by MDAT.
- Parameters
-
[in] | id | Id number. Each thread must have a unique number from 0 to n-1 where n is the number of threads. |
[in] | property | String indicating the type of thread. For example, in the reader-writers problem, some threads will have the property “reader” and other threads will have the property “writer”. |
void mdat_thread_finish |
( |
) | |
|
Marks the currently running thread as complete – the thread will no longer be scheduled by MDAT. Threads cannot be restarted once they have finished.
void mdat_invoke_scheduler |
( |
int |
location) | |
|
Forces MDAT to make a scheduling decision based on the scheduling mode (see ThreadManager for more details). This call could be inserted manually by the programmer or inserted automatically by the instrumentation tool (recommended).
- Parameters
-
[in] | location | An id associated with the call. This parameter is used to update the location field in the trace. It is recommended but not required to have each location be unique. (Note: Only use positive integers as negative integers are used for calls internal to MDAT.) |
void mdat_mutex_init |
( |
const char * |
name, |
|
|
pthread_mutex_t * |
lock, |
|
|
pthread_mutexattr_t * |
attr |
|
) |
| |
Registers a new mutex lock with the LockManager.
- Parameters
-
[in] | name | name of the lock |
[in] | lock | lock variable |
[in] | attr | lock attributes (ignored by MDAT) |
void mdat_mutex_lock |
( |
pthread_mutex_t * |
lock) | |
|
Thread takes a lock if available. If the lock is unavailable, the thread will wait until it acquires the lock.
- Parameters
-
void mdat_mutex_unlock |
( |
pthread_mutex_t * |
lock) | |
|
Gives up the lock. If one or more threads are waiting, one thread will be woken up and given the lock. If no threads are waiting, the lock is returned to the unlocked state.
- Parameters
-
void mdat_sem_init |
( |
const char * |
name, |
|
|
sem_t * |
sem, |
|
|
int |
pshared, |
|
|
int |
value |
|
) |
| |
Registers a new semaphore with the Semaphore Manager
- Parameters
-
[in] | name | name of the semaphore |
[in] | sem | semaphore variable |
[in] | pshared | sharing value (ignored by MDAT) |
[in] | value | initial value of semaphore |
void mdat_sem_wait |
( |
sem_t * |
sem) | |
|
Decrement the semaphore. If the value is negative, the thread must wait until woken up by a subsequent post operation.
- Parameters
-
[in] | sem | semaphore variable |
void mdat_sem_post |
( |
sem_t * |
sem) | |
|
Increment the semaphore. If one or more threads are waiting, one thread will be woken up.
- Parameters
-
[in] | sem | semaphore variable |
void mdat_enter_section |
( |
const char * |
section) | |
|
Records that a thread has entered a particular section of the code. In addition, it notifies the checker that the current thread has entered the appropriate section.
- Parameters
-
[in] | section | The section that the thread has entered. Common sections include “Entry”, “Exit”, “Critical”, and “Remainder”. Note that you do not have to use these particular sections – any set of strings will so as long the strings are recognized by the checker. |