diff options
| author | rpj <rpj> | 2004-10-01 07:17:09 +0000 | 
|---|---|---|
| committer | rpj <rpj> | 2004-10-01 07:17:09 +0000 | 
| commit | b0cf9efa6afeb8a7dbddf124dae173a2d633c801 (patch) | |
| tree | 8f208f15bd63cf69ae9e2ceb2d523296db8bca76 /tests | |
| parent | 531ca4db4794aab863a898b4d079ccd59b424b25 (diff) | |
Mutex speedups
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/GNUmakefile | 2 | ||||
| -rw-r--r-- | tests/benchlib.c | 25 | ||||
| -rw-r--r-- | tests/benchtest.h | 3 | ||||
| -rw-r--r-- | tests/benchtest1.c | 42 | ||||
| -rw-r--r-- | tests/mutex4.c | 6 | 
5 files changed, 76 insertions, 2 deletions
| diff --git a/tests/GNUmakefile b/tests/GNUmakefile index 04f9943..cc36b53 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -273,7 +273,7 @@ sizes.pass: sizes.exe  	@ $(ECHO) Passed  	@ $(TOUCH) $@ -%.bench: $(XXLIBS) %.exe +%.bench: $(LIB) $(DLL) $(HDR) $(QAPC) $(XXLIBS) %.exe  	@ $(ECHO) Running $*  	$*  	@ $(ECHO) Done diff --git a/tests/benchlib.c b/tests/benchlib.c index 78ec3c8..3fa7171 100644 --- a/tests/benchlib.c +++ b/tests/benchlib.c @@ -51,6 +51,31 @@ int old_mutex_use = OLD_WIN32CS;  BOOL (WINAPI *ptw32_try_enter_critical_section)(LPCRITICAL_SECTION) = NULL;  HINSTANCE ptw32_h_kernel32; +void +dummy_call(int * a) +{ +} + +void +interlocked_inc_with_conditionals(int * a) +{ +  if (a != NULL) +    if (InterlockedIncrement((long *) a) == -1) +      { +        *a = 0; +      } +} + +void +interlocked_dec_with_conditionals(int * a) +{ +  if (a != NULL) +    if (InterlockedDecrement((long *) a) == -1) +      { +        *a = 0; +      } +} +  int  old_mutex_init(old_mutex_t *mutex, const old_mutexattr_t *attr)  { diff --git a/tests/benchtest.h b/tests/benchtest.h index 2401622..64af6c8 100644 --- a/tests/benchtest.h +++ b/tests/benchtest.h @@ -59,6 +59,9 @@ extern HINSTANCE ptw32_h_kernel32;  #define PTW32_OBJECT_AUTO_INIT ((void *) -1) +void dummy_call(int * a); +void interlocked_inc_with_conditionals(int *a); +void interlocked_dec_with_conditionals(int *a);  int old_mutex_init(old_mutex_t *mutex, const old_mutexattr_t *attr);  int old_mutex_lock(old_mutex_t *mutex);  int old_mutex_unlock(old_mutex_t *mutex); diff --git a/tests/benchtest1.c b/tests/benchtest1.c index 1a553dc..ce45cf2 100644 --- a/tests/benchtest1.c +++ b/tests/benchtest1.c @@ -101,6 +101,7 @@ runTest (char * testNameString, int mType)  int  main (int argc, char *argv[])  { +  int i = 0;    CRITICAL_SECTION cs;    old_mutex_t ox;    pthread_mutexattr_init(&ma); @@ -127,6 +128,45 @@ main (int argc, char *argv[])    overHeadMilliSecs = durationMilliSecs; +  TESTSTART +  assert((dummy_call(&i), 1) == one); +  assert((dummy_call(&i), 1) == one); +  TESTSTOP + +  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; + +  printf( "%-45s %15ld %15.3f\n", +	    "Dummy call x 2", +          durationMilliSecs, +          (float) durationMilliSecs * 1E3 / ITERATIONS); + + +  TESTSTART +  assert((interlocked_inc_with_conditionals(&i), 1) == one); +  assert((interlocked_dec_with_conditionals(&i), 1) == one); +  TESTSTOP + +  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; + +  printf( "%-45s %15ld %15.3f\n", +	    "Dummy call -> Interlocked with cond x 2", +          durationMilliSecs, +          (float) durationMilliSecs * 1E3 / ITERATIONS); + + +  TESTSTART +  assert((InterlockedIncrement(&i), 1) == one); +  assert((InterlockedDecrement(&i), 1) == one); +  TESTSTOP + +  durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs; + +  printf( "%-45s %15ld %15.3f\n", +	    "InterlockedOp x 2", +          durationMilliSecs, +          (float) durationMilliSecs * 1E3 / ITERATIONS); + +    InitializeCriticalSection(&cs);    TESTSTART @@ -139,7 +179,7 @@ main (int argc, char *argv[])    durationMilliSecs = GetDurationMilliSecs(currSysTimeStart, currSysTimeStop) - overHeadMilliSecs;    printf( "%-45s %15ld %15.3f\n", -	    "Simple Critical Section", +	    "Simple Critical Section x 2",            durationMilliSecs,            (float) durationMilliSecs * 1E3 / ITERATIONS); diff --git a/tests/mutex4.c b/tests/mutex4.c index 74ec159..75880fd 100644 --- a/tests/mutex4.c +++ b/tests/mutex4.c @@ -69,6 +69,9 @@ main()    assert(pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_DEFAULT) == 0);    assert(pthread_mutex_init(&mutex1, &ma) == 0);    assert(pthread_mutex_lock(&mutex1) == 0); +  /* +   * NORMAL (fast) mutexes don't check ownership. +   */    assert(pthread_create(&t, NULL, unlocker, (void *) 0) == 0);    assert(pthread_join(t, NULL) == 0);    assert(pthread_mutex_unlock(&mutex1) == EPERM); @@ -78,6 +81,9 @@ main()    assert(pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_NORMAL) == 0);    assert(pthread_mutex_init(&mutex1, &ma) == 0);    assert(pthread_mutex_lock(&mutex1) == 0); +  /* +   * NORMAL (fast) mutexes don't check ownership. +   */    assert(pthread_create(&t, NULL, unlocker, (void *) 0) == 0);    assert(pthread_join(t, NULL) == 0);    assert(pthread_mutex_unlock(&mutex1) == EPERM); | 
