diff options
author | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-04 18:08:00 +0000 |
---|---|---|
committer | binji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-10-04 18:08:00 +0000 |
commit | d03f4d4224b568111e11adf44db5c84f38c85b05 (patch) | |
tree | c6bb5238a15c99b4478c0fadd7da01fe22e1c590 /native_client_sdk | |
parent | 9e91883a9f7aa6915b92d567edcc60e2473b7064 (diff) | |
download | chromium_src-d03f4d4224b568111e11adf44db5c84f38c85b05.zip chromium_src-d03f4d4224b568111e11adf44db5c84f38c85b05.tar.gz chromium_src-d03f4d4224b568111e11adf44db5c84f38c85b05.tar.bz2 |
[NaCl SDK] Build pthreads_win32 library using .dsc file.
* generate_make.py: Added DEFINES. It was already supported, but it wouldn't validate the .dsc if you used it. :-/
* common.js: Send a fake 'load' event when running host examples. NaCl modules send it properly, but host modules don't.
* pi_generator: I was using pi_generator as my test for pthreads functionality, fixed some bugs there too. Changed it to use rand(), not rand_r() (because rand_r isn't supported on Windows).
BUG=122229
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/11051021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
6 files changed, 186 insertions, 11 deletions
diff --git a/native_client_sdk/src/build_tools/generate_make.py b/native_client_sdk/src/build_tools/generate_make.py index 0bb745c..0ba4098 100755 --- a/native_client_sdk/src/build_tools/generate_make.py +++ b/native_client_sdk/src/build_tools/generate_make.py @@ -202,6 +202,7 @@ DSC_FORMAT = { 'SOURCES': (list, '', True), 'CCFLAGS': (list, '', False), 'CXXFLAGS': (list, '', False), + 'DEFINES': (list, '', False), 'LDFLAGS': (list, '', False), 'INCLUDES': (list, '', False), 'LIBS' : (list, '', False) diff --git a/native_client_sdk/src/examples/common.js b/native_client_sdk/src/examples/common.js index a457715..257773c 100644 --- a/native_client_sdk/src/examples/common.js +++ b/native_client_sdk/src/examples/common.js @@ -29,7 +29,8 @@ var common = (function () { moduleEl.setAttribute('src', path + '/' + name + '.nmf'); // For NaCL modules use application/x-nacl. var mimetype = 'application/x-nacl'; - if (tool == 'win' || tool == 'linux' || tool == 'mac') { + var isHost = tool == 'win' || tool == 'linux' || tool == 'mac'; + if (isHost) { // For non-nacl PPAPI plugins use the x-ppapi-debug/release // mime type. if (path.toLowerCase().indexOf('release') != -1) @@ -46,6 +47,15 @@ var common = (function () { // event fires. var listenerDiv = document.getElementById('listener'); listenerDiv.appendChild(moduleEl); + + // Host plugins don't send a moduleDidLoad message. We'll fake it here. + if (isHost) { + window.setTimeout(function () { + var evt = document.createEvent('Event'); + evt.initEvent('load', true, true); // bubbles, cancelable + moduleEl.dispatchEvent(evt); + }, 100); // 100 ms + } } /** diff --git a/native_client_sdk/src/examples/pi_generator/example.dsc b/native_client_sdk/src/examples/pi_generator/example.dsc index 90958f8..9e177e0 100644 --- a/native_client_sdk/src/examples/pi_generator/example.dsc +++ b/native_client_sdk/src/examples/pi_generator/example.dsc @@ -1,5 +1,5 @@ { - 'TOOLS': ['newlib', 'glibc', 'pnacl'], + 'TOOLS': ['newlib', 'glibc', 'pnacl', 'win'], 'TARGETS': [ { 'NAME' : 'pi_generator', @@ -9,6 +9,7 @@ 'pi_generator.h', 'pi_generator_module.cc' ], + 'DEFINES': ['PTW32_STATIC_LIB'], 'LIBS': ['ppapi_cpp', 'ppapi', 'pthread'] } ], diff --git a/native_client_sdk/src/examples/pi_generator/pi_generator.cc b/native_client_sdk/src/examples/pi_generator/pi_generator.cc index 6e31158..27bdbf9 100644 --- a/native_client_sdk/src/examples/pi_generator/pi_generator.cc +++ b/native_client_sdk/src/examples/pi_generator/pi_generator.cc @@ -29,6 +29,7 @@ const uint32_t kBlueShift = 0; void FlushCallback(void* data, int32_t result) { static_cast<pi_generator::PiGenerator*>(data)->set_flush_pending(false); } + } // namespace namespace pi_generator { @@ -79,14 +80,14 @@ PiGenerator::PiGenerator(PP_Instance instance) pixel_buffer_(NULL), flush_pending_(false), quit_(false), - compute_pi_thread_(0), + thread_create_result_(0), pi_(0.0) { pthread_mutex_init(&pixel_buffer_mutex_, NULL); } PiGenerator::~PiGenerator() { quit_ = true; - if (compute_pi_thread_) { + if (thread_create_result_ == 0) { pthread_join(compute_pi_thread_, NULL); } DestroyContext(); @@ -117,8 +118,9 @@ void PiGenerator::DidChangeView(const pp::View& view) { } bool PiGenerator::Init(uint32_t argc, const char* argn[], const char* argv[]) { - pthread_create(&compute_pi_thread_, NULL, ComputePi, this); - return true; + thread_create_result_ = pthread_create(&compute_pi_thread_, NULL, ComputePi, + this); + return thread_create_result_ == 0; } uint32_t* PiGenerator::LockPixels() { @@ -201,8 +203,9 @@ void PiGenerator::FlushPixelBuffer() { void* PiGenerator::ComputePi(void* param) { int count = 0; // The number of points put inside the inscribed quadrant. unsigned int seed = 1; - PiGenerator* pi_generator = static_cast<PiGenerator*>(param); srand(seed); + + PiGenerator* pi_generator = static_cast<PiGenerator*>(param); for (int i = 1; i <= kMaxPointCount && !pi_generator->quit(); ++i) { ScopedPixelLock scoped_pixel_lock(pi_generator); uint32_t* pixel_bits = scoped_pixel_lock.pixels(); @@ -214,8 +217,8 @@ void* PiGenerator::ComputePi(void* param) { // initialized. continue; } - double x = static_cast<double>(rand_r(&seed)) / RAND_MAX; - double y = static_cast<double>(rand_r(&seed)) / RAND_MAX; + double x = static_cast<double>(rand()) / RAND_MAX; + double y = static_cast<double>(rand()) / RAND_MAX; double distance = sqrt(x * x + y * y); int px = x * pi_generator->width(); int py = (1.0 - y) * pi_generator->height(); diff --git a/native_client_sdk/src/examples/pi_generator/pi_generator.h b/native_client_sdk/src/examples/pi_generator/pi_generator.h index f69b1ff..556b091 100644 --- a/native_client_sdk/src/examples/pi_generator/pi_generator.h +++ b/native_client_sdk/src/examples/pi_generator/pi_generator.h @@ -101,6 +101,7 @@ class PiGenerator : public pp::Instance { bool flush_pending_; bool quit_; pthread_t compute_pi_thread_; + int thread_create_result_; double pi_; // ComputePi() estimates Pi using Monte Carlo method and it is executed by a diff --git a/native_client_sdk/src/libraries/pthread/library.dsc b/native_client_sdk/src/libraries/pthread/library.dsc index 6822244..e4838a52 100644 --- a/native_client_sdk/src/libraries/pthread/library.dsc +++ b/native_client_sdk/src/libraries/pthread/library.dsc @@ -1,18 +1,177 @@ { 'TOOLS': ['win'], + 'SEARCH': [ + '../third_party/pthreads-win32', + ], 'TARGETS': [ { 'NAME' : 'pthread', 'TYPE' : 'lib', - 'SOURCES' : ['pthread.c'], + 'DEFINES': [ + 'PTW32_STATIC_LIB', + ], + 'SOURCES' : [ + 'autostatic.c', + 'cleanup.c', + 'create.c', + 'errno.c', + 'fork.c', + 'global.c', + 'pthread_attr_destroy.c', + 'pthread_attr_getdetachstate.c', + 'pthread_attr_getinheritsched.c', + 'pthread_attr_getschedparam.c', + 'pthread_attr_getschedpolicy.c', + 'pthread_attr_getscope.c', + 'pthread_attr_getstackaddr.c', + 'pthread_attr_getstacksize.c', + 'pthread_attr_init.c', + 'pthread_attr_setdetachstate.c', + 'pthread_attr_setinheritsched.c', + 'pthread_attr_setschedparam.c', + 'pthread_attr_setschedpolicy.c', + 'pthread_attr_setscope.c', + 'pthread_attr_setstackaddr.c', + 'pthread_attr_setstacksize.c', + 'pthread_barrier_destroy.c', + 'pthread_barrier_init.c', + 'pthread_barrier_wait.c', + 'pthread_barrierattr_destroy.c', + 'pthread_barrierattr_getpshared.c', + 'pthread_barrierattr_init.c', + 'pthread_barrierattr_setpshared.c', + 'pthread_cancel.c', + 'pthread_cond_destroy.c', + 'pthread_cond_init.c', + 'pthread_cond_signal.c', + 'pthread_cond_wait.c', + 'pthread_condattr_destroy.c', + 'pthread_condattr_getpshared.c', + 'pthread_condattr_init.c', + 'pthread_condattr_setpshared.c', + 'pthread_delay_np.c', + 'pthread_detach.c', + 'pthread_equal.c', + 'pthread_exit.c', + 'pthread_getconcurrency.c', + 'pthread_getschedparam.c', + 'pthread_getspecific.c', + 'pthread_getunique_np.c', + 'pthread_getw32threadhandle_np.c', + 'pthread_join.c', + 'pthread_key_create.c', + 'pthread_key_delete.c', + 'pthread_kill.c', + 'pthread_mutex_consistent.c', + 'pthread_mutex_destroy.c', + 'pthread_mutex_init.c', + 'pthread_mutex_lock.c', + 'pthread_mutex_timedlock.c', + 'pthread_mutex_trylock.c', + 'pthread_mutex_unlock.c', + 'pthread_mutexattr_destroy.c', + 'pthread_mutexattr_getkind_np.c', + 'pthread_mutexattr_getpshared.c', + 'pthread_mutexattr_getrobust.c', + 'pthread_mutexattr_gettype.c', + 'pthread_mutexattr_init.c', + 'pthread_mutexattr_setkind_np.c', + 'pthread_mutexattr_setpshared.c', + 'pthread_mutexattr_setrobust.c', + 'pthread_mutexattr_settype.c', + 'pthread_num_processors_np.c', + 'pthread_once.c', + 'pthread_rwlock_destroy.c', + 'pthread_rwlock_init.c', + 'pthread_rwlock_rdlock.c', + 'pthread_rwlock_timedrdlock.c', + 'pthread_rwlock_timedwrlock.c', + 'pthread_rwlock_tryrdlock.c', + 'pthread_rwlock_trywrlock.c', + 'pthread_rwlock_unlock.c', + 'pthread_rwlock_wrlock.c', + 'pthread_rwlockattr_destroy.c', + 'pthread_rwlockattr_getpshared.c', + 'pthread_rwlockattr_init.c', + 'pthread_rwlockattr_setpshared.c', + 'pthread_self.c', + 'pthread_setcancelstate.c', + 'pthread_setcanceltype.c', + 'pthread_setconcurrency.c', + 'pthread_setschedparam.c', + 'pthread_setspecific.c', + 'pthread_spin_destroy.c', + 'pthread_spin_init.c', + 'pthread_spin_lock.c', + 'pthread_spin_trylock.c', + 'pthread_spin_unlock.c', + 'pthread_testcancel.c', + 'pthread_timechange_handler_np.c', + 'pthread_win32_attach_detach_np.c', + 'ptw32_calloc.c', + 'ptw32_callUserDestroyRoutines.c', + 'ptw32_cond_check_need_init.c', + 'ptw32_getprocessors.c', + 'ptw32_is_attr.c', + 'ptw32_MCS_lock.c', + 'ptw32_mutex_check_need_init.c', + 'ptw32_new.c', + 'ptw32_processInitialize.c', + 'ptw32_processTerminate.c', + 'ptw32_relmillisecs.c', + 'ptw32_reuse.c', + 'ptw32_rwlock_cancelwrwait.c', + 'ptw32_rwlock_check_need_init.c', + 'ptw32_semwait.c', + 'ptw32_spinlock_check_need_init.c', + 'ptw32_threadDestroy.c', + 'ptw32_threadStart.c', + 'ptw32_throw.c', + 'ptw32_timespec.c', + 'ptw32_tkAssocCreate.c', + 'ptw32_tkAssocDestroy.c', + 'sched_get_priority_max.c', + 'sched_get_priority_min.c', + 'sched_getscheduler.c', + 'sched_setscheduler.c', + 'sched_yield.c', + 'sem_close.c', + 'sem_destroy.c', + 'sem_getvalue.c', + 'sem_init.c', + 'sem_open.c', + 'sem_post.c', + 'sem_post_multiple.c', + 'sem_timedwait.c', + 'sem_trywait.c', + 'sem_unlink.c', + 'sem_wait.c', + 'signal.c', + 'w32_CancelableWait.c', + ], } ], 'HEADERS': [ { - 'FILES': ['pthread.h'], + 'FILES': [ + 'config.h', + 'context.h', + 'implement.h', + 'need_errno.h', + 'pthread.h', + 'sched.h', + 'semaphore.h', + ], 'DEST': 'include/win', } ], + 'DATA': [ + 'CONTRIBUTORS', + 'COPYING', + 'COPYING.LIB', + 'MAINTAINERS', + 'README', + ], 'DEST': 'src', 'NAME': 'pthread', } |