Add testing of Emscripten intrinsics in the spinlock test. Fix test_pthread_mutex to pass the test params to compilation.
This commit is contained in:
Родитель
a58c2fe0af
Коммит
8ceb2b2474
|
@ -1,19 +1,25 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <pthread.h>
|
||||
#include <emscripten.h>
|
||||
#include <emscripten/emscripten.h>
|
||||
#include <emscripten/threading.h>
|
||||
#include <unistd.h> // usleep
|
||||
#include <assert.h>
|
||||
|
||||
volatile int counter = 0; // Shared data
|
||||
volatile int lock = 0; // spinlock "mutex" variable
|
||||
|
||||
|
||||
void *ThreadMain(void *arg)
|
||||
{
|
||||
printf("Thread started.\n");
|
||||
for(int i = 0; i < 100; ++i)
|
||||
{
|
||||
#ifdef USE_EMSCRIPTEN_INTRINSICS
|
||||
while(emscripten_atomic_exchange_u32((void*)&lock, 1))
|
||||
#else
|
||||
while(__sync_lock_test_and_set(&lock, 1))
|
||||
#endif
|
||||
{
|
||||
/*nop*/;
|
||||
}
|
||||
|
@ -21,7 +27,11 @@ void *ThreadMain(void *arg)
|
|||
usleep(5 * 1000); // Create contention on the lock.
|
||||
++c;
|
||||
counter = c;
|
||||
#ifdef USE_EMSCRIPTEN_INTRINSICS
|
||||
emscripten_atomic_store_u32((void*)&lock, 0);
|
||||
#else
|
||||
__sync_lock_release(&lock);
|
||||
#endif
|
||||
}
|
||||
printf("Thread done.\n");
|
||||
pthread_exit(0);
|
||||
|
|
|
@ -2542,7 +2542,8 @@ window.close = function() {
|
|||
|
||||
# Test the __sync_lock_test_and_set and __sync_lock_release primitives.
|
||||
def test_pthread_gcc_spinlock(self):
|
||||
self.btest(path_from_root('tests', 'pthread', 'test_pthread_gcc_spinlock.cpp'), expected='800', args=['-lpthread', '-s', 'PTHREAD_POOL_SIZE=8'])
|
||||
for arg in [[], ['-DUSE_EMSCRIPTEN_INTRINSICS']]:
|
||||
self.btest(path_from_root('tests', 'pthread', 'test_pthread_gcc_spinlock.cpp'), expected='800', args=['-lpthread', '-s', 'PTHREAD_POOL_SIZE=8'] + arg)
|
||||
|
||||
# Test that basic thread creation works.
|
||||
def test_pthread_create(self):
|
||||
|
@ -2575,7 +2576,7 @@ window.close = function() {
|
|||
# Tests the pthread mutex api.
|
||||
def test_pthread_mutex(self):
|
||||
for arg in [[], ['-DSPINLOCK_TEST']]:
|
||||
self.btest(path_from_root('tests', 'pthread', 'test_pthread_mutex.cpp'), expected='50', args=['-lpthread', '-s', 'PTHREAD_POOL_SIZE=8'])
|
||||
self.btest(path_from_root('tests', 'pthread', 'test_pthread_mutex.cpp'), expected='50', args=['-lpthread', '-s', 'PTHREAD_POOL_SIZE=8'] + arg)
|
||||
|
||||
# Test that memory allocation is thread-safe.
|
||||
def test_pthread_malloc(self):
|
||||
|
|
Загрузка…
Ссылка в новой задаче