├── .editorconfig ├── .github └── workflows │ ├── npm-publish.yml │ ├── prebuild.yml │ └── test.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── bin └── qjsc.js ├── binding.gyp ├── compat └── win32 │ ├── atomic │ └── stdatomic.h │ └── pthreads │ ├── .gitignore │ ├── ANNOUNCE │ ├── BUGS │ ├── Bmakefile │ ├── CONTRIBUTORS │ ├── COPKG │ ├── .buildinfo │ ├── all.bat │ ├── pthreads.autopkg │ ├── pthreads.vcxproj │ └── pthreads.vcxproj.filters │ ├── COPYING │ ├── COPYING.LIB │ ├── ChangeLog │ ├── FAQ │ ├── GNUmakefile │ ├── MAINTAINERS │ ├── Makefile │ ├── NEWS │ ├── Nmakefile │ ├── Nmakefile.tests │ ├── PROGRESS │ ├── README │ ├── README.Borland │ ├── README.CV │ ├── README.NONPORTABLE │ ├── README.Watcom │ ├── README.WinCE │ ├── TODO │ ├── WinCE-PORT │ ├── attr.c │ ├── autostatic.c │ ├── barrier.c │ ├── builddmc.bat │ ├── cancel.c │ ├── cleanup.c │ ├── condvar.c │ ├── config.h │ ├── context.h │ ├── create.c │ ├── dll.c │ ├── errno.c │ ├── exit.c │ ├── fork.c │ ├── global.c │ ├── implement.h │ ├── misc.c │ ├── mutex.c │ ├── need_errno.h │ ├── nonportable.c │ ├── private.c │ ├── pthread.c │ ├── pthread.dsp │ ├── pthread.dsw │ ├── pthread.h │ ├── 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_MCS_lock.c │ ├── ptw32_OLL_lock.c │ ├── ptw32_callUserDestroyRoutines.c │ ├── ptw32_calloc.c │ ├── ptw32_cond_check_need_init.c │ ├── ptw32_getprocessors.c │ ├── ptw32_is_attr.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 │ ├── rwlock.c │ ├── sched.c │ ├── sched.h │ ├── 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 │ ├── semaphore.c │ ├── semaphore.h │ ├── signal.c │ ├── spin.c │ ├── sync.c │ ├── tests │ ├── Bmakefile │ ├── ChangeLog │ ├── Debug.dsp │ ├── Debug.dsw │ ├── Debug.plg │ ├── Debug.txt │ ├── GNUmakefile │ ├── Makefile │ ├── README │ ├── README.BENCHTESTS │ ├── SIZES.GC │ ├── SIZES.GCE │ ├── SIZES.VC │ ├── SIZES.VCE │ ├── SIZES.VSE │ ├── Wmakefile │ ├── barrier1.c │ ├── barrier2.c │ ├── barrier3.c │ ├── barrier4.c │ ├── barrier5.c │ ├── barrier6.c │ ├── benchlib.c │ ├── benchtest.h │ ├── benchtest1.c │ ├── benchtest2.c │ ├── benchtest3.c │ ├── benchtest4.c │ ├── benchtest5.c │ ├── cancel1.c │ ├── cancel2.c │ ├── cancel3.c │ ├── cancel4.c │ ├── cancel5.c │ ├── cancel6a.c │ ├── cancel6d.c │ ├── cancel7.c │ ├── cancel8.c │ ├── cancel9.c │ ├── cleanup0.c │ ├── cleanup1.c │ ├── cleanup2.c │ ├── cleanup3.c │ ├── condvar1.c │ ├── condvar1_1.c │ ├── condvar1_2.c │ ├── condvar2.c │ ├── condvar2_1.c │ ├── condvar3.c │ ├── condvar3_1.c │ ├── condvar3_2.c │ ├── condvar3_3.c │ ├── condvar4.c │ ├── condvar5.c │ ├── condvar6.c │ ├── condvar7.c │ ├── condvar8.c │ ├── condvar9.c │ ├── context1.c │ ├── count1.c │ ├── create1.c │ ├── create2.c │ ├── create3.c │ ├── delay1.c │ ├── delay2.c │ ├── detach1.c │ ├── equal1.c │ ├── errno1.c │ ├── exception1.c │ ├── exception2.c │ ├── exception3.c │ ├── exit1.c │ ├── exit2.c │ ├── exit3.c │ ├── exit4.c │ ├── exit5.c │ ├── eyal1.c │ ├── inherit1.c │ ├── join0.c │ ├── join1.c │ ├── join2.c │ ├── join3.c │ ├── kill1.c │ ├── loadfree.c │ ├── mutex1.c │ ├── mutex1e.c │ ├── mutex1n.c │ ├── mutex1r.c │ ├── mutex2.c │ ├── mutex2e.c │ ├── mutex2r.c │ ├── mutex3.c │ ├── mutex3e.c │ ├── mutex3r.c │ ├── mutex4.c │ ├── mutex5.c │ ├── mutex6.c │ ├── mutex6e.c │ ├── mutex6es.c │ ├── mutex6n.c │ ├── mutex6r.c │ ├── mutex6rs.c │ ├── mutex6s.c │ ├── mutex7.c │ ├── mutex7e.c │ ├── mutex7n.c │ ├── mutex7r.c │ ├── mutex8.c │ ├── mutex8e.c │ ├── mutex8n.c │ ├── mutex8r.c │ ├── once1.c │ ├── once2.c │ ├── once3.c │ ├── once4.c │ ├── openmp1.c │ ├── priority1.c │ ├── priority2.c │ ├── reuse1.c │ ├── reuse2.c │ ├── robust1.c │ ├── robust2.c │ ├── robust3.c │ ├── robust4.c │ ├── robust5.c │ ├── rwlock1.c │ ├── rwlock2.c │ ├── rwlock2_t.c │ ├── rwlock3.c │ ├── rwlock3_t.c │ ├── rwlock4.c │ ├── rwlock4_t.c │ ├── rwlock5.c │ ├── rwlock5_t.c │ ├── rwlock6.c │ ├── rwlock6_t.c │ ├── rwlock6_t2.c │ ├── rwlock7.c │ ├── rwlock8.c │ ├── self1.c │ ├── self2.c │ ├── semaphore1.c │ ├── semaphore2.c │ ├── semaphore3.c │ ├── semaphore4.c │ ├── semaphore4t.c │ ├── semaphore5.c │ ├── sequence1.c │ ├── sizes.c │ ├── spin1.c │ ├── spin2.c │ ├── spin3.c │ ├── spin4.c │ ├── stress1.c │ ├── test.h │ ├── tryentercs.c │ ├── tryentercs2.c │ ├── tsd1.c │ ├── tsd2.c │ ├── valid1.c │ └── valid2.c │ ├── tsd.c │ ├── version.rc │ └── w32_CancelableWait.c ├── deps └── quickjs_2021_03_27 │ ├── Changelog │ ├── LICENSE │ ├── Makefile │ ├── TODO │ ├── VERSION │ ├── cutils.c │ ├── cutils.h │ ├── doc │ ├── jsbignum.texi │ └── quickjs.texi │ ├── examples │ ├── fib.c │ ├── fib_module.js │ ├── hello.js │ ├── hello_module.js │ ├── pi_bigdecimal.js │ ├── pi_bigfloat.js │ ├── pi_bigint.js │ ├── point.c │ ├── test_fib.js │ └── test_point.js │ ├── libbf.c │ ├── libbf.h │ ├── libregexp-opcode.h │ ├── libregexp.c │ ├── libregexp.h │ ├── libunicode-table.h │ ├── libunicode.c │ ├── libunicode.h │ ├── list.h │ ├── qjs.c │ ├── qjsc.c │ ├── qjscalc.js │ ├── quickjs-atom.h │ ├── quickjs-libc.c │ ├── quickjs-libc.h │ ├── quickjs-opcode.h │ ├── quickjs.c │ ├── quickjs.h │ ├── readme.txt │ ├── release.sh │ ├── repl.js │ ├── run-test262.c │ ├── test262.conf │ ├── test262_errors.txt │ ├── test262o.conf │ ├── test262o_errors.txt │ ├── tests │ ├── bjson.c │ ├── microbench.js │ ├── test262.patch │ ├── test_bignum.js │ ├── test_bjson.js │ ├── test_builtin.js │ ├── test_closure.js │ ├── test_language.js │ ├── test_loop.js │ ├── test_op_overloading.js │ ├── test_qjscalc.js │ ├── test_std.js │ ├── test_worker.js │ └── test_worker_module.js │ ├── unicode_download.sh │ ├── unicode_gen.c │ └── unicode_gen_def.h ├── index.js ├── install.js ├── package-lock.json ├── package.json ├── prebuilds ├── darwin-arm64 │ └── node.napi.node ├── darwin-x64 │ └── node.napi.node ├── linux-x64 │ └── node.napi.node └── win32-x64 │ └── node.napi.node ├── src └── qjsc_20210327.cc └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # Apply the following rules to these file types 2 | [*] 3 | end_of_line = lf #Unix type line endings 4 | insert_final_newline = true 5 | indent_style = space 6 | indent_size = 2 7 | trim_trailing_whitespace = true 8 | max_line_length = 120 9 | -------------------------------------------------------------------------------- /.github/workflows/npm-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages 3 | 4 | name: Publish Node.js Package 5 | 6 | on: 7 | release: 8 | types: [created] 9 | workflow_dispatch: 10 | jobs: 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: actions/setup-node@v2 16 | with: 17 | node-version: 14 18 | - run: npm ci 19 | - run: npm test 20 | 21 | publish-npm: 22 | needs: build 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/checkout@v2 26 | - uses: actions/setup-node@v2 27 | with: 28 | node-version: 14 29 | registry-url: https://registry.npmjs.org/ 30 | - run: npm publish 31 | env: 32 | NODE_AUTH_TOKEN: ${{secrets.npm_token}} 33 | -------------------------------------------------------------------------------- /.github/workflows/prebuild.yml: -------------------------------------------------------------------------------- 1 | name: Prebuild the binaries. 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | prebuild: 8 | strategy: 9 | matrix: 10 | os: [windows, linux, macos] 11 | node: [16] 12 | runs-on: ${{ matrix.os }}-latest 13 | env: 14 | VCINSTALLDIR: 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC' 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: actions/setup-node@v3 18 | with: 19 | node-version: ${{ matrix.node }} 20 | - if: ${{ matrix.os == 'windows' }} 21 | shell: powershell 22 | run: | 23 | npm config set msvs_version 2022 -g 24 | - run: npm install --ignore-scripts 25 | - run: npm run build -- --msvs_version=2022 26 | - uses: actions/upload-artifact@v3 27 | with: 28 | name: qjsc-prebuild-${{ matrix.os }}-node${{ matrix.node }} 29 | path: build/Release/qjsc_20210327.node 30 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages 3 | 4 | name: Test 5 | 6 | on: 7 | push: 8 | workflow_dispatch: 9 | jobs: 10 | build: 11 | strategy: 12 | matrix: 13 | os: [ubuntu-latest, windows-latest, macos-latest] 14 | node: [14] 15 | runs-on: ${{ matrix.os }} 16 | steps: 17 | - uses: actions/checkout@v2 18 | - uses: actions/setup-node@v2 19 | with: 20 | node-version: ${{ matrix.node }} 21 | - run: npm ci 22 | - run: npm test 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | 78 | # Next.js build output 79 | .next 80 | 81 | # Nuxt.js build / generate output 82 | .nuxt 83 | dist 84 | 85 | # Gatsby files 86 | .cache/ 87 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 88 | # https://nextjs.org/blog/next-9-1#public-directory-support 89 | # public 90 | 91 | # vuepress build output 92 | .vuepress/dist 93 | 94 | # Serverless directories 95 | .serverless/ 96 | 97 | # FuseBox cache 98 | .fusebox/ 99 | 100 | # DynamoDB Local files 101 | .dynamodb/ 102 | 103 | # TernJS port file 104 | .tern-port 105 | 106 | compile_commands.json 107 | 108 | build/ 109 | .clangd 110 | .idea/ 111 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Build linux prebuild binary 2 | 3 | # syntax=docker/dockerfile:1 4 | FROM centos:centos7 5 | RUN yum install centos-release-scl-rh -y 6 | RUN yum install rh-nodejs12 -y 7 | RUN yum install python3 -y 8 | RUN yum install devtoolset-7 -y 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # node-qjsc 2 | > Node.js addon for the [QuickJS](https://github.com/bellard/quickjs) compiler. 3 | 4 | Current supported version: 5 | + 20210327 6 | 7 | ## Install 8 | 9 | ``` 10 | npm install qjsc --save 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```javascript 16 | const Qjsc = require('qjsc'); 17 | const qjsc = new Qjsc(); 18 | 19 | // Dump bytecode from javascript source; 20 | qjsc.compile('function hello() { return 1 + 1};'); // 21 | 22 | // Use specified quickjs version 23 | qjsc = new Qjsc({version: '20210327'}); 24 | 25 | // Get all supported versions. 26 | qjsc.getSupportedVersions(); 27 | ``` 28 | 29 | ## Contribute 30 | 31 | **Generate compile_commands.json** 32 | 33 | ``` 34 | node-gyp configure -- -f gyp.generator.compile_commands_json.py 35 | ``` 36 | 37 | **Prebuild linux binary** 38 | 39 | 1. Install docker 40 | 2. Build local image with Dockerfile 41 | ``` 42 | docker build -t qjsc . 43 | ``` 44 | 3. Enter into images 45 | ``` 46 | docker run --rm -it -v $(pwd):/project qjsc 47 | ``` 48 | 4. Set up env in docker container 49 | ``` 50 | cd project 51 | scl enable rh-nodejs12 bash 52 | scl enable devtoolset-7 bash 53 | ``` 54 | 5. Build your binary 55 | ``` 56 | npm install 57 | npm run prebuild 58 | ``` 59 | -------------------------------------------------------------------------------- /bin/qjsc.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const path = require('path'); 3 | const fs = require('fs'); 4 | const { program } = require('commander'); 5 | const packageConfig = require('../package.json'); 6 | const Qjsc = require('../index'); 7 | 8 | program 9 | .version(packageConfig.version) 10 | .description('QuickJS Compiler') 11 | .requiredOption('-s, --source ', 'the Javascript source file path') 12 | .requiredOption('-d, --dist ', 'the generated bytecode file path') 13 | .parse(process.argv); 14 | 15 | let options = program.opts(); 16 | let source = options.source; 17 | let dist = options.dist; 18 | 19 | if (!path.isAbsolute(source)) { 20 | source = path.join(process.cwd(), source); 21 | } 22 | if (!path.isAbsolute(dist)) { 23 | dist = path.join(process.cwd(), dist); 24 | } 25 | 26 | const qjsc = new Qjsc(); 27 | 28 | const sourceFileName = source.split('/').slice(-1)[0].split('.')[0]; 29 | const sourceCode = fs.readFileSync(source, {encoding: 'utf-8'}); 30 | 31 | let buffer = qjsc.compile(sourceCode); 32 | let distPath = path.join(dist, sourceFileName + '.kbc1'); 33 | fs.writeFileSync(distPath, buffer); 34 | console.log('Quickjs bytecode generated at: \n' + distPath); 35 | -------------------------------------------------------------------------------- /compat/win32/pthreads/.gitignore: -------------------------------------------------------------------------------- 1 | *.obj 2 | pthread*.dll 3 | pthread*.exp 4 | pthread*.ilk 5 | pthread*.lib 6 | pthread*.pdb 7 | *.res 8 | -------------------------------------------------------------------------------- /compat/win32/pthreads/COPKG/.buildinfo: -------------------------------------------------------------------------------- 1 | @import default_tools; 2 | 3 | default { 4 | ("V110,V100", "win32,X64", "Release,Debug", "Dynamic,Static", "cdecl,stdcall") => { 5 | .PushEnvironment{}; 6 | .LoadSystemEnvironment{}; 7 | .Message.Text = @"envTarg = vc_${0}_${1} -- ${2} ${3} ${4}"; 8 | 9 | .SetEnvironmentFromTarget.Target = "VC_${0}_${1}"; 10 | 11 | .Message.Text = @"EnvValid = $(IsEnvironmentValid)"; 12 | 13 | .Exec { 14 | Condition="$(IsEnvironmentValid)"; 15 | Command = @"msbuild pthreads.vcxproj /p:PlatformToolset=${0};Platform=${1};Configuration=${2};ConfigurationType=${3}Library;CallingConvention=${4}"; 16 | }; 17 | 18 | .PopEnvironment{}; 19 | }; 20 | 21 | }; 22 | 23 | clean { 24 | .RemoveDir.Directories = @".\intermediate"; 25 | }; 26 | 27 | nuke { 28 | .RemoveDir.Directories = @".\output"; 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /compat/win32/pthreads/COPKG/all.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | 4 | if "%1"=="clean" goto :clean 5 | if "%1"=="noclean" ( 6 | set __NOCLEAN__=true 7 | shift) 8 | 9 | setlocal 10 | call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" amd64 11 | call :build x64 Release v110 || goto :eof 12 | call :build x64 Debug v110 || goto :eof 13 | endlocal 14 | 15 | setlocal 16 | call "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86 17 | call :build Win32 Release v110 || goto :eof 18 | call :build Win32 Debug v110 || goto :eof 19 | endlocal 20 | 21 | setlocal 22 | call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" amd64 23 | call :build x64 Release v100 || goto :eof 24 | call :build x64 Debug v100 || goto :eof 25 | endlocal 26 | 27 | setlocal 28 | call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86 29 | call :build Win32 Release v100 || goto :eof 30 | call :build Win32 Debug v100 || goto :eof 31 | endlocal 32 | 33 | if "%__NOCLEAN__%"=="true" goto :eof 34 | 35 | goto :clean 36 | 37 | goto :eof 38 | 39 | :build 40 | msbuild /P:Platform=%1 /P:Configuration=%2 /P:PlatformToolset=%3 /P:ConfigurationType=DynamicLibrary /P:CallingConvention=Cdecl .\pthread.vcxproj || goto :eof 41 | msbuild /P:Platform=%1 /P:Configuration=%2 /P:PlatformToolset=%3 /P:ConfigurationType=StaticLibrary /P:CallingConvention=Cdecl .\pthread.vcxproj || goto :eof 42 | msbuild /P:Platform=%1 /P:Configuration=%2 /P:PlatformToolset=%3 /P:ConfigurationType=DynamicLibrary /P:CallingConvention=stdcall .\pthread.vcxproj || goto :eof 43 | msbuild /P:Platform=%1 /P:Configuration=%2 /P:PlatformToolset=%3 /P:ConfigurationType=StaticLibrary /P:CallingConvention=stdcall .\pthread.vcxproj || goto :eof 44 | 45 | goto :eof 46 | 47 | :clean 48 | REM rd /s /q v90 49 | rd /s /q intermediate 50 | 51 | -------------------------------------------------------------------------------- /compat/win32/pthreads/COPKG/pthreads.autopkg: -------------------------------------------------------------------------------- 1 | 2 | nuget { 3 | // the nuspec file metadata. Gets created/updated on build 4 | nuspec { 5 | id = pthreads; 6 | version : 2.9.1.4; 7 | title: Pthreads Library; 8 | authors: {Pthreads contributors, Tim Rogers}; 9 | owners: {CoApp Project, Garrett Serack, Tom Hanrahan}; 10 | licenseUrl: "https://raw.github.com/coapp-packages/pthreads/master/COPYING.LIB"; 11 | projectUrl: "http://github.com/coapp-packages/pthreads"; 12 | iconUrl: http://www.sourceware.org/pthreads-win32/images/Pthreads-win32-small.gif; 13 | requireLicenseAcceptance:false; 14 | summary: Pthreads - POSIX threads API for Windows; 15 | description: @"A library for writing multithreaded applications with POSIX threads. 16 | Pthreads homepage: http://www.sourceware.org/pthreads-win32/"; 17 | releaseNotes: "Release of pthreads-win32 2.9.1"; 18 | copyright: Copyright 2013; 19 | tags: { pthread, libpthread, native, CoApp }; 20 | 21 | }; 22 | 23 | // the files that go into the content folders 24 | // (inserted into the nuspec file) 25 | files { 26 | include: { 27 | ..\need_errno.h, 28 | ..\pthread.h, 29 | ..\sched.h, 30 | ..\semaphore.h, 31 | }; 32 | 33 | source: { 34 | ..\*.c, 35 | ..\*.h, 36 | }; 37 | 38 | docs: { 39 | ..\manual\* 40 | }; 41 | 42 | ("v100,v110", "Win32,x64", "release,debug", "dynamic,static", "cdecl,stdcall") => { 43 | [${0},${1},${2},${3},${4}] { 44 | lib: { .\output\${0}\${1}\${2}\${3}Library\${4}\lib\*.lib }; 45 | }; 46 | }; 47 | 48 | ("v100,v110", "Win32,x64", "release,debug", "dynamic", "cdecl,stdcall") => { 49 | [${0},${1},${2},${3},${4}] { 50 | bin: { .\output\${0}\${1}\${2}\${3}Library\${4}\lib\*.dll }; 51 | symbols: { .\output\${0}\${1}\${2}\${3}Library\${4}\lib\*.pdb }; 52 | }; 53 | }; 54 | 55 | 56 | }; 57 | 58 | // the VC++ .props file that gets generated and inserted into the ${d_content} folder 59 | props { 60 | // we're going to generate a number of properties anyway. 61 | // so even if the packager doesn't specify the props object 62 | // we're going to make this file. 63 | }; 64 | 65 | // the VC++ .targets file that gets generated and inserted into the ${d_content} folder 66 | targets { 67 | // every configuration needs to reference the include directories. 68 | Defines += HAS_PTHREAD; 69 | [static] 70 | Defines += PTW32_STATIC_LIB; 71 | }; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /compat/win32/pthreads/COPKG/pthreads.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /compat/win32/pthreads/MAINTAINERS: -------------------------------------------------------------------------------- 1 | CVS Repository maintainers 2 | 3 | Ross Johnson rpj@ise.canberra.edu.au 4 | Ben Elliston bje@cygnus.com 5 | -------------------------------------------------------------------------------- /compat/win32/pthreads/Nmakefile: -------------------------------------------------------------------------------- 1 | /* 2 | * nmake file for uwin pthread library 3 | */ 4 | 5 | VERSION = - 6 | CCFLAGS = -V -g $(CC.DLL) 7 | HAVE_PTW32_CONFIG_H == 1 8 | _MT == 1 9 | _timeb == timeb 10 | _ftime == ftime 11 | _errno == _ast_errno 12 | 13 | $(INCLUDEDIR) :INSTALLDIR: pthread.h sched.h 14 | 15 | pthread $(VERSION) :LIBRARY: attr.c barrier.c cancel.c cleanup.c condvar.c \ 16 | create.c dll.c exit.c fork.c global.c misc.c mutex.c private.c \ 17 | rwlock.c sched.c semaphore.c spin.c sync.c tsd.c nonportable.c 18 | 19 | :: ANNOUNCE CONTRIBUTORS COPYING.LIB ChangeLog FAQ GNUmakefile MAINTAINERS \ 20 | Makefile Makefile.in Makefile.vc NEWS PROGRESS README README.WinCE \ 21 | TODO WinCE-PORT install-sh errno.c tests tests.mk acconfig.h \ 22 | config.guess config.h.in config.sub configure configure.in signal.c \ 23 | README.CV README.NONPORTABLE pthread.dsp pthread.dsw 24 | 25 | -------------------------------------------------------------------------------- /compat/win32/pthreads/PROGRESS: -------------------------------------------------------------------------------- 1 | Please see the ANNOUNCE file "Level of Standards Conformance" 2 | or the web page: 3 | 4 | http://sources.redhat.com/pthreads-win32/conformance.html 5 | -------------------------------------------------------------------------------- /compat/win32/pthreads/README.Watcom: -------------------------------------------------------------------------------- 1 | Watcom compiler notes 2 | ===================== 3 | 4 | Status 5 | ------ 6 | Not yet usable. Although the library builds under Watcom it 7 | substantially fails the test suite. 8 | 9 | There is a working Wmakefile for wmake for the library build. 10 | 11 | invoke as any of: 12 | wmake -f Wmakefile clean WC 13 | wmake -f Wmakefile clean WC-inlined 14 | wmake -f Wmakefile clean WCE 15 | wmake -f Wmakefile clean WCE-inlined 16 | 17 | These build pthreadWC.dll and pthreadWCE.dll. 18 | 19 | There is a working Wmakefile for wmake for the test suite. 20 | 21 | invoke as any of: 22 | wmake -f Wmakefile clean WC 23 | wmake -f Wmakefile clean WCX 24 | wmake -f Wmakefile clean WCE 25 | wmake -f Wmakefile clean WC-bench 26 | wmake -f Wmakefile clean WCX-bench 27 | wmake -f Wmakefile clean WCE-bench 28 | 29 | 30 | Current known problems 31 | ---------------------- 32 | 33 | Library build: 34 | The Watcom compiler uses a different default call convention to MS C or GNU C and so 35 | applications are not compatible with pthreadVC.dll etc using pre 2003-10-14 versions 36 | of pthread.h, sched.h, or semaphore.h. The cdecl attribute can be used on exposed 37 | function prototypes to force compatibility with MS C built DLLs. 38 | 39 | However, there appear to be other incompatibilities. Errno.h, for example, defines 40 | different values for the standard C and POSIX errors to those defined by the MS C 41 | errno.h. It may be that references to Watcom's threads compatible 'errno' do set 42 | and return translated numbers consistently, but I have not verified this. 43 | 44 | Watcom defines errno as a dereferenced pointer returned by the function 45 | _get_errno_ptr(). This is similar to both the MS and GNU C environments for 46 | multithreaded use. However, the Watcom version appears to have a number of problems: 47 | 48 | - different threads return the same pointer value. Compare with the MS and GNU C 49 | versions which correctly return different values (since each thread must maintain 50 | a thread specific errno value). 51 | 52 | - an errno value set within the DLL appears as zero in the application even though 53 | both share the same thread. 54 | 55 | Therefore applications built using the Watcom compiler may need to use 56 | a Watcom built version of the library (pthreadWC.dll). If this is the case, then 57 | the cdecl function attribute should not be required. 58 | 59 | Application builds: 60 | The test suite fails with the Watcom compiler. 61 | 62 | Test semaphore1.c fails for pthreadWC.dll because errno returns 0 instead of EAGAIN. 63 | -------------------------------------------------------------------------------- /compat/win32/pthreads/README.WinCE: -------------------------------------------------------------------------------- 1 | WinCE port 2 | ---------- 3 | (See the file WinCE-PORT for a detailed explanation.) 4 | 5 | Make sure you define "WINCE" amongst your compiler flags (eg. -DWINCE). 6 | The config.h file will define all the necessary defines for you. 7 | -------------------------------------------------------------------------------- /compat/win32/pthreads/TODO: -------------------------------------------------------------------------------- 1 | Things that aren't done yet 2 | --------------------------- 3 | 4 | 1. Implement PTHREAD_PROCESS_SHARED for semaphores, mutexes, 5 | condition variables, read/write locks, barriers. 6 | 7 | 8 | -------------------------------------------------------------------------------- /compat/win32/pthreads/attr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * attr.c 3 | * 4 | * Description: 5 | * This translation unit agregates operations on thread attribute objects. 6 | * It is used for inline optimisation. 7 | * 8 | * The included modules are used separately when static executable sizes 9 | * must be minimised. 10 | * 11 | * -------------------------------------------------------------------------- 12 | * 13 | * Pthreads-win32 - POSIX Threads Library for Win32 14 | * Copyright(C) 1998 John E. Bossom 15 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 16 | * 17 | * Contact Email: rpj@callisto.canberra.edu.au 18 | * 19 | * The current list of contributors is contained 20 | * in the file CONTRIBUTORS included with the source 21 | * code distribution. The list can also be seen at the 22 | * following World Wide Web location: 23 | * http://sources.redhat.com/pthreads-win32/contributors.html 24 | * 25 | * This library is free software; you can redistribute it and/or 26 | * modify it under the terms of the GNU Lesser General Public 27 | * License as published by the Free Software Foundation; either 28 | * version 2 of the License, or (at your option) any later version. 29 | * 30 | * This library is distributed in the hope that it will be useful, 31 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 33 | * Lesser General Public License for more details. 34 | * 35 | * You should have received a copy of the GNU Lesser General Public 36 | * License along with this library in the file COPYING.LIB; 37 | * if not, write to the Free Software Foundation, Inc., 38 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 39 | */ 40 | 41 | #include "pthread.h" 42 | #include "implement.h" 43 | 44 | #include "pthread_attr_init.c" 45 | #include "pthread_attr_destroy.c" 46 | #include "pthread_attr_getdetachstate.c" 47 | #include "pthread_attr_setdetachstate.c" 48 | #include "pthread_attr_getstackaddr.c" 49 | #include "pthread_attr_setstackaddr.c" 50 | #include "pthread_attr_getstacksize.c" 51 | #include "pthread_attr_setstacksize.c" 52 | #include "pthread_attr_getscope.c" 53 | #include "pthread_attr_setscope.c" 54 | -------------------------------------------------------------------------------- /compat/win32/pthreads/barrier.c: -------------------------------------------------------------------------------- 1 | /* 2 | * barrier.c 3 | * 4 | * Description: 5 | * This translation unit implements barrier primitives. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | #include "pthread_barrier_init.c" 42 | #include "pthread_barrier_destroy.c" 43 | #include "pthread_barrier_wait.c" 44 | #include "pthread_barrierattr_init.c" 45 | #include "pthread_barrierattr_destroy.c" 46 | #include "pthread_barrierattr_getpshared.c" 47 | #include "pthread_barrierattr_setpshared.c" 48 | -------------------------------------------------------------------------------- /compat/win32/pthreads/builddmc.bat: -------------------------------------------------------------------------------- 1 | ; Build the pthreads library with the Digital Mars Compiler 2 | ; 3 | set DMCDIR=c:\dm 4 | 5 | ; RELEASE 6 | %DMCDIR%\bin\dmc -D_WIN32_WINNT -D_MT -DHAVE_PTW32_CONFIG_H -I.;c:\dm\include -o+all -WD pthread.c user32.lib+kernel32.lib+wsock32.lib -L/impl -L/NODEBUG -L/SU:WINDOWS 7 | 8 | ; DEBUG 9 | %DMCDIR%\bin\dmc -g -D_WIN32_WINNT -D_MT -DHAVE_PTW32_CONFIG_H -I.;c:\dm\include -o+all -WD pthread.c user32.lib+kernel32.lib+wsock32.lib -L/impl -L/SU:WINDOWS 10 | -------------------------------------------------------------------------------- /compat/win32/pthreads/cancel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cancel.c 3 | * 4 | * Description: 5 | * POSIX thread functions related to thread cancellation. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | #include "pthread_setcancelstate.c" 42 | #include "pthread_setcanceltype.c" 43 | #include "pthread_testcancel.c" 44 | #include "pthread_cancel.c" 45 | -------------------------------------------------------------------------------- /compat/win32/pthreads/condvar.c: -------------------------------------------------------------------------------- 1 | /* 2 | * condvar.c 3 | * 4 | * Description: 5 | * This translation unit implements condition variables and their primitives. 6 | * 7 | * 8 | * -------------------------------------------------------------------------- 9 | * 10 | * Pthreads-win32 - POSIX Threads Library for Win32 11 | * Copyright(C) 1998 John E. Bossom 12 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 13 | * 14 | * Contact Email: rpj@callisto.canberra.edu.au 15 | * 16 | * The current list of contributors is contained 17 | * in the file CONTRIBUTORS included with the source 18 | * code distribution. The list can also be seen at the 19 | * following World Wide Web location: 20 | * http://sources.redhat.com/pthreads-win32/contributors.html 21 | * 22 | * This library is free software; you can redistribute it and/or 23 | * modify it under the terms of the GNU Lesser General Public 24 | * License as published by the Free Software Foundation; either 25 | * version 2 of the License, or (at your option) any later version. 26 | * 27 | * This library is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 30 | * Lesser General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU Lesser General Public 33 | * License along with this library in the file COPYING.LIB; 34 | * if not, write to the Free Software Foundation, Inc., 35 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 36 | * 37 | */ 38 | 39 | #include "pthread.h" 40 | #include "implement.h" 41 | 42 | #include "ptw32_cond_check_need_init.c" 43 | #include "pthread_condattr_init.c" 44 | #include "pthread_condattr_destroy.c" 45 | #include "pthread_condattr_getpshared.c" 46 | #include "pthread_condattr_setpshared.c" 47 | #include "pthread_cond_init.c" 48 | #include "pthread_cond_destroy.c" 49 | #include "pthread_cond_wait.c" 50 | #include "pthread_cond_signal.c" 51 | -------------------------------------------------------------------------------- /compat/win32/pthreads/exit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * exit.c 3 | * 4 | * Description: 5 | * This translation unit implements routines associated with exiting from 6 | * a thread. 7 | * 8 | * -------------------------------------------------------------------------- 9 | * 10 | * Pthreads-win32 - POSIX Threads Library for Win32 11 | * Copyright(C) 1998 John E. Bossom 12 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 13 | * 14 | * Contact Email: rpj@callisto.canberra.edu.au 15 | * 16 | * The current list of contributors is contained 17 | * in the file CONTRIBUTORS included with the source 18 | * code distribution. The list can also be seen at the 19 | * following World Wide Web location: 20 | * http://sources.redhat.com/pthreads-win32/contributors.html 21 | * 22 | * This library is free software; you can redistribute it and/or 23 | * modify it under the terms of the GNU Lesser General Public 24 | * License as published by the Free Software Foundation; either 25 | * version 2 of the License, or (at your option) any later version. 26 | * 27 | * This library is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 30 | * Lesser General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU Lesser General Public 33 | * License along with this library in the file COPYING.LIB; 34 | * if not, write to the Free Software Foundation, Inc., 35 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 36 | */ 37 | 38 | #include "pthread.h" 39 | #include "implement.h" 40 | #if ! defined(_UWIN) && ! defined(WINCE) 41 | # include 42 | #endif 43 | 44 | #include "pthread_exit.c" 45 | -------------------------------------------------------------------------------- /compat/win32/pthreads/fork.c: -------------------------------------------------------------------------------- 1 | /* 2 | * fork.c 3 | * 4 | * Description: 5 | * Implementation of fork() for POSIX threads. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | 38 | #include "pthread.h" 39 | #include "implement.h" 40 | -------------------------------------------------------------------------------- /compat/win32/pthreads/misc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * misc.c 3 | * 4 | * Description: 5 | * This translation unit implements miscellaneous thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | #include "pthread_kill.c" 42 | #include "pthread_once.c" 43 | #include "pthread_self.c" 44 | #include "pthread_equal.c" 45 | #include "pthread_setconcurrency.c" 46 | #include "pthread_getconcurrency.c" 47 | #include "ptw32_new.c" 48 | #include "ptw32_calloc.c" 49 | #include "ptw32_reuse.c" 50 | #include "w32_CancelableWait.c" 51 | -------------------------------------------------------------------------------- /compat/win32/pthreads/mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutex.c 3 | * 4 | * Description: 5 | * This translation unit implements mutual exclusion (mutex) primitives. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #if ! defined(_UWIN) && ! defined(WINCE) 38 | # include 39 | #endif 40 | #if !defined(NEED_FTIME) 41 | #include 42 | #endif 43 | #include "pthread.h" 44 | #include "implement.h" 45 | 46 | 47 | #include "ptw32_mutex_check_need_init.c" 48 | #include "pthread_mutex_init.c" 49 | #include "pthread_mutex_destroy.c" 50 | #include "pthread_mutexattr_init.c" 51 | #include "pthread_mutexattr_destroy.c" 52 | #include "pthread_mutexattr_getpshared.c" 53 | #include "pthread_mutexattr_setpshared.c" 54 | #include "pthread_mutexattr_settype.c" 55 | #include "pthread_mutexattr_gettype.c" 56 | #include "pthread_mutexattr_setrobust.c" 57 | #include "pthread_mutexattr_getrobust.c" 58 | #include "pthread_mutex_lock.c" 59 | #include "pthread_mutex_timedlock.c" 60 | #include "pthread_mutex_unlock.c" 61 | #include "pthread_mutex_trylock.c" 62 | #include "pthread_mutex_consistent.c" 63 | -------------------------------------------------------------------------------- /compat/win32/pthreads/nonportable.c: -------------------------------------------------------------------------------- 1 | /* 2 | * nonportable.c 3 | * 4 | * Description: 5 | * This translation unit implements non-portable thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | #include "pthread_mutexattr_setkind_np.c" 41 | #include "pthread_mutexattr_getkind_np.c" 42 | #include "pthread_getw32threadhandle_np.c" 43 | #include "pthread_getunique_np.c" 44 | #include "pthread_delay_np.c" 45 | #include "pthread_num_processors_np.c" 46 | #include "pthread_win32_attach_detach_np.c" 47 | #include "pthread_timechange_handler_np.c" 48 | -------------------------------------------------------------------------------- /compat/win32/pthreads/private.c: -------------------------------------------------------------------------------- 1 | /* 2 | * private.c 3 | * 4 | * Description: 5 | * This translation unit implements routines which are private to 6 | * the implementation and may be used throughout it. 7 | * 8 | * -------------------------------------------------------------------------- 9 | * 10 | * Pthreads-win32 - POSIX Threads Library for Win32 11 | * Copyright(C) 1998 John E. Bossom 12 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 13 | * 14 | * Contact Email: rpj@callisto.canberra.edu.au 15 | * 16 | * The current list of contributors is contained 17 | * in the file CONTRIBUTORS included with the source 18 | * code distribution. The list can also be seen at the 19 | * following World Wide Web location: 20 | * http://sources.redhat.com/pthreads-win32/contributors.html 21 | * 22 | * This library is free software; you can redistribute it and/or 23 | * modify it under the terms of the GNU Lesser General Public 24 | * License as published by the Free Software Foundation; either 25 | * version 2 of the License, or (at your option) any later version. 26 | * 27 | * This library is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 30 | * Lesser General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU Lesser General Public 33 | * License along with this library in the file COPYING.LIB; 34 | * if not, write to the Free Software Foundation, Inc., 35 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 36 | */ 37 | 38 | #include "pthread.h" 39 | #include "implement.h" 40 | 41 | #include "ptw32_MCS_lock.c" 42 | #include "ptw32_is_attr.c" 43 | #include "ptw32_processInitialize.c" 44 | #include "ptw32_processTerminate.c" 45 | #include "ptw32_threadStart.c" 46 | #include "ptw32_threadDestroy.c" 47 | #include "ptw32_tkAssocCreate.c" 48 | #include "ptw32_tkAssocDestroy.c" 49 | #include "ptw32_callUserDestroyRoutines.c" 50 | #include "ptw32_semwait.c" 51 | #include "ptw32_timespec.c" 52 | #include "ptw32_relmillisecs.c" 53 | #include "ptw32_throw.c" 54 | #include "ptw32_getprocessors.c" 55 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread.c 3 | * 4 | * Description: 5 | * This translation unit agregates pthreads-win32 translation units. 6 | * It is used for inline optimisation of the library, 7 | * maximising for speed at the expense of size. 8 | * 9 | * -------------------------------------------------------------------------- 10 | * 11 | * Pthreads-win32 - POSIX Threads Library for Win32 12 | * Copyright(C) 1998 John E. Bossom 13 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 14 | * 15 | * Contact Email: rpj@callisto.canberra.edu.au 16 | * 17 | * The current list of contributors is contained 18 | * in the file CONTRIBUTORS included with the source 19 | * code distribution. The list can also be seen at the 20 | * following World Wide Web location: 21 | * http://sources.redhat.com/pthreads-win32/contributors.html 22 | * 23 | * This library is free software; you can redistribute it and/or 24 | * modify it under the terms of the GNU Lesser General Public 25 | * License as published by the Free Software Foundation; either 26 | * version 2 of the License, or (at your option) any later version. 27 | * 28 | * This library is distributed in the hope that it will be useful, 29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 31 | * Lesser General Public License for more details. 32 | * 33 | * You should have received a copy of the GNU Lesser General Public 34 | * License along with this library in the file COPYING.LIB; 35 | * if not, write to the Free Software Foundation, Inc., 36 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 37 | */ 38 | 39 | #include "pthread.h" 40 | #include "implement.h" 41 | 42 | /* The following are ordered for inlining */ 43 | 44 | #include "private.c" 45 | #include "attr.c" 46 | #include "barrier.c" 47 | #include "cancel.c" 48 | #include "cleanup.c" 49 | #include "condvar.c" 50 | #include "create.c" 51 | #include "dll.c" 52 | #include "autostatic.c" 53 | #include "errno.c" 54 | #include "exit.c" 55 | #include "fork.c" 56 | #include "global.c" 57 | #include "misc.c" 58 | #include "mutex.c" 59 | #include "nonportable.c" 60 | #include "rwlock.c" 61 | #include "sched.c" 62 | #include "semaphore.c" 63 | #include "signal.c" 64 | #include "spin.c" 65 | #include "sync.c" 66 | #include "tsd.c" 67 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "pthread"=.\pthread.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_attr_getinheritsched.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_attr_getinheritsched.c 3 | * 4 | * Description: 5 | * POSIX thread functions that deal with thread scheduling. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | #include "sched.h" 40 | 41 | int 42 | pthread_attr_getinheritsched (const pthread_attr_t * attr, int *inheritsched) 43 | { 44 | if (ptw32_is_attr (attr) != 0 || inheritsched == NULL) 45 | { 46 | return EINVAL; 47 | } 48 | 49 | *inheritsched = (*attr)->inheritsched; 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_attr_getschedparam.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_attr_getschedparam.c 3 | * 4 | * Description: 5 | * POSIX thread functions that deal with thread scheduling. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | #include "sched.h" 40 | 41 | int 42 | pthread_attr_getschedparam (const pthread_attr_t * attr, 43 | struct sched_param *param) 44 | { 45 | if (ptw32_is_attr (attr) != 0 || param == NULL) 46 | { 47 | return EINVAL; 48 | } 49 | 50 | memcpy (param, &(*attr)->param, sizeof (*param)); 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_attr_getschedpolicy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_attr_getschedpolicy.c 3 | * 4 | * Description: 5 | * POSIX thread functions that deal with thread scheduling. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | #include "sched.h" 40 | 41 | int 42 | pthread_attr_getschedpolicy (const pthread_attr_t * attr, int *policy) 43 | { 44 | if (ptw32_is_attr (attr) != 0 || policy == NULL) 45 | { 46 | return EINVAL; 47 | } 48 | 49 | /* 50 | * Validate the policy arg. 51 | * Check that a policy constant wasn't passed rather than &policy. 52 | */ 53 | if (policy <= (int *) SCHED_MAX) 54 | { 55 | return EINVAL; 56 | } 57 | 58 | *policy = SCHED_OTHER; 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_attr_getscope.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_attr_getscope.c 3 | * 4 | * Description: 5 | * This translation unit implements operations on thread attribute objects. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | /* ignore warning "unreferenced formal parameter" */ 41 | #if defined(_MSC_VER) 42 | #pragma warning( disable : 4100 ) 43 | #endif 44 | 45 | int 46 | pthread_attr_getscope (const pthread_attr_t * attr, int *contentionscope) 47 | { 48 | #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) 49 | *contentionscope = (*attr)->contentionscope; 50 | return 0; 51 | #else 52 | return ENOSYS; 53 | #endif 54 | } 55 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_attr_setinheritsched.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_attr_setinheritsched.c 3 | * 4 | * Description: 5 | * POSIX thread functions that deal with thread scheduling. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | #include "sched.h" 40 | 41 | int 42 | pthread_attr_setinheritsched (pthread_attr_t * attr, int inheritsched) 43 | { 44 | if (ptw32_is_attr (attr) != 0) 45 | { 46 | return EINVAL; 47 | } 48 | 49 | if (PTHREAD_INHERIT_SCHED != inheritsched 50 | && PTHREAD_EXPLICIT_SCHED != inheritsched) 51 | { 52 | return EINVAL; 53 | } 54 | 55 | (*attr)->inheritsched = inheritsched; 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_attr_setschedparam.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_attr_setschedparam.c 3 | * 4 | * Description: 5 | * POSIX thread functions that deal with thread scheduling. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | #include "sched.h" 40 | 41 | int 42 | pthread_attr_setschedparam (pthread_attr_t * attr, 43 | const struct sched_param *param) 44 | { 45 | int priority; 46 | 47 | if (ptw32_is_attr (attr) != 0 || param == NULL) 48 | { 49 | return EINVAL; 50 | } 51 | 52 | priority = param->sched_priority; 53 | 54 | /* Validate priority level. */ 55 | if (priority < sched_get_priority_min (SCHED_OTHER) || 56 | priority > sched_get_priority_max (SCHED_OTHER)) 57 | { 58 | return EINVAL; 59 | } 60 | 61 | memcpy (&(*attr)->param, param, sizeof (*param)); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_attr_setschedpolicy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_attr_setschedpolicy.c 3 | * 4 | * Description: 5 | * POSIX thread functions that deal with thread scheduling. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | #include "sched.h" 40 | 41 | int 42 | pthread_attr_setschedpolicy (pthread_attr_t * attr, int policy) 43 | { 44 | if (ptw32_is_attr (attr) != 0) 45 | { 46 | return EINVAL; 47 | } 48 | 49 | if (policy != SCHED_OTHER) 50 | { 51 | return ENOTSUP; 52 | } 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_attr_setscope.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_attr_setscope.c 3 | * 4 | * Description: 5 | * This translation unit implements operations on thread attribute objects. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | /* ignore warning "unreferenced formal parameter" */ 41 | #if defined(_MSC_VER) 42 | #pragma warning( disable : 4100 ) 43 | #endif 44 | 45 | int 46 | pthread_attr_setscope (pthread_attr_t * attr, int contentionscope) 47 | { 48 | #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) 49 | switch (contentionscope) 50 | { 51 | case PTHREAD_SCOPE_SYSTEM: 52 | (*attr)->contentionscope = contentionscope; 53 | return 0; 54 | case PTHREAD_SCOPE_PROCESS: 55 | return ENOTSUP; 56 | default: 57 | return EINVAL; 58 | } 59 | #else 60 | return ENOSYS; 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_barrier_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_barrier_init.c 3 | * 4 | * Description: 5 | * This translation unit implements barrier primitives. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | int 42 | pthread_barrier_init (pthread_barrier_t * barrier, 43 | const pthread_barrierattr_t * attr, unsigned int count) 44 | { 45 | pthread_barrier_t b; 46 | 47 | if (barrier == NULL || count == 0) 48 | { 49 | return EINVAL; 50 | } 51 | 52 | if (NULL != (b = (pthread_barrier_t) calloc (1, sizeof (*b)))) 53 | { 54 | b->pshared = (attr != NULL && *attr != NULL 55 | ? (*attr)->pshared : PTHREAD_PROCESS_PRIVATE); 56 | 57 | b->nCurrentBarrierHeight = b->nInitialBarrierHeight = count; 58 | b->lock = 0; 59 | 60 | if (0 == sem_init (&(b->semBarrierBreeched), b->pshared, 0)) 61 | { 62 | *barrier = b; 63 | return 0; 64 | } 65 | (void) free (b); 66 | } 67 | 68 | return ENOMEM; 69 | } 70 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_getconcurrency.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_getconcurrency.c 3 | * 4 | * Description: 5 | * This translation unit implements miscellaneous thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | int 42 | pthread_getconcurrency (void) 43 | { 44 | return ptw32_concurrency; 45 | } 46 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_getunique_np.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_getunique_np.c 3 | * 4 | * Description: 5 | * This translation unit implements non-portable thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | /* 41 | * 42 | */ 43 | unsigned __int64 44 | pthread_getunique_np (pthread_t thread) 45 | { 46 | return ((ptw32_thread_t*)thread.p)->seqNumber; 47 | } 48 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_getw32threadhandle_np.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_getw32threadhandle_np.c 3 | * 4 | * Description: 5 | * This translation unit implements non-portable thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | /* 41 | * pthread_getw32threadhandle_np() 42 | * 43 | * Returns the win32 thread handle that the POSIX 44 | * thread "thread" is running as. 45 | * 46 | * Applications can use the win32 handle to set 47 | * win32 specific attributes of the thread. 48 | */ 49 | HANDLE 50 | pthread_getw32threadhandle_np (pthread_t thread) 51 | { 52 | return ((ptw32_thread_t *)thread.p)->threadH; 53 | } 54 | 55 | /* 56 | * pthread_getw32threadid_np() 57 | * 58 | * Returns the win32 thread id that the POSIX 59 | * thread "thread" is running as. 60 | */ 61 | DWORD 62 | pthread_getw32threadid_np (pthread_t thread) 63 | { 64 | return ((ptw32_thread_t *)thread.p)->thread; 65 | } 66 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_mutexattr_getkind_np.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_mutexattr_getkind_np.c 3 | * 4 | * Description: 5 | * This translation unit implements non-portable thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | int 41 | pthread_mutexattr_getkind_np (pthread_mutexattr_t * attr, int *kind) 42 | { 43 | return pthread_mutexattr_gettype (attr, kind); 44 | } 45 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_mutexattr_gettype.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_mutexattr_gettype.c 3 | * 4 | * Description: 5 | * This translation unit implements mutual exclusion (mutex) primitives. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | int 42 | pthread_mutexattr_gettype (const pthread_mutexattr_t * attr, int *kind) 43 | { 44 | int result = 0; 45 | 46 | if (attr != NULL && *attr != NULL && kind != NULL) 47 | { 48 | *kind = (*attr)->kind; 49 | } 50 | else 51 | { 52 | result = EINVAL; 53 | } 54 | 55 | return (result); 56 | } 57 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_mutexattr_setkind_np.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_mutexattr_setkind_np.c 3 | * 4 | * Description: 5 | * This translation unit implements non-portable thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | int 41 | pthread_mutexattr_setkind_np (pthread_mutexattr_t * attr, int kind) 42 | { 43 | return pthread_mutexattr_settype (attr, kind); 44 | } 45 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_num_processors_np.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_num_processors_np.c 3 | * 4 | * Description: 5 | * This translation unit implements non-portable thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | /* 41 | * pthread_num_processors_np() 42 | * 43 | * Get the number of CPUs available to the process. 44 | */ 45 | int 46 | pthread_num_processors_np (void) 47 | { 48 | int count; 49 | 50 | if (ptw32_getprocessors (&count) != 0) 51 | { 52 | count = 1; 53 | } 54 | 55 | return (count); 56 | } 57 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_setconcurrency.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_setconcurrency.c 3 | * 4 | * Description: 5 | * This translation unit implements miscellaneous thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | int 42 | pthread_setconcurrency (int level) 43 | { 44 | if (level < 0) 45 | { 46 | return EINVAL; 47 | } 48 | else 49 | { 50 | ptw32_concurrency = level; 51 | return 0; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /compat/win32/pthreads/pthread_spin_unlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * pthread_spin_unlock.c 3 | * 4 | * Description: 5 | * This translation unit implements spin lock primitives. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | int 42 | pthread_spin_unlock (pthread_spinlock_t * lock) 43 | { 44 | register pthread_spinlock_t s; 45 | 46 | if (NULL == lock || NULL == *lock) 47 | { 48 | return (EINVAL); 49 | } 50 | 51 | s = *lock; 52 | 53 | if (s == PTHREAD_SPINLOCK_INITIALIZER) 54 | { 55 | return EPERM; 56 | } 57 | 58 | switch ((long) 59 | PTW32_INTERLOCKED_COMPARE_EXCHANGE_LONG ((PTW32_INTERLOCKED_LONGPTR) &s->interlock, 60 | (PTW32_INTERLOCKED_LONG) PTW32_SPIN_UNLOCKED, 61 | (PTW32_INTERLOCKED_LONG) PTW32_SPIN_LOCKED)) 62 | { 63 | case PTW32_SPIN_LOCKED: 64 | case PTW32_SPIN_UNLOCKED: 65 | return 0; 66 | case PTW32_SPIN_USE_MUTEX: 67 | return pthread_mutex_unlock (&(s->u.mutex)); 68 | } 69 | 70 | return EINVAL; 71 | } 72 | -------------------------------------------------------------------------------- /compat/win32/pthreads/ptw32_calloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ptw32_calloc.c 3 | * 4 | * Description: 5 | * This translation unit implements miscellaneous thread functions. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | #if defined(NEED_CALLOC) 42 | void * 43 | ptw32_calloc (size_t n, size_t s) 44 | { 45 | unsigned int m = n * s; 46 | void *p; 47 | 48 | p = malloc (m); 49 | if (p == NULL) 50 | return NULL; 51 | 52 | memset (p, 0, m); 53 | 54 | return p; 55 | } 56 | #endif 57 | -------------------------------------------------------------------------------- /compat/win32/pthreads/ptw32_is_attr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ptw32_is_attr.c 3 | * 4 | * Description: 5 | * This translation unit implements operations on thread attribute objects. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | int 41 | ptw32_is_attr (const pthread_attr_t * attr) 42 | { 43 | /* Return 0 if the attr object is valid, non-zero otherwise. */ 44 | 45 | return (attr == NULL || 46 | *attr == NULL || (*attr)->valid != PTW32_ATTR_VALID); 47 | } 48 | -------------------------------------------------------------------------------- /compat/win32/pthreads/ptw32_rwlock_cancelwrwait.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ptw32_rwlock_cancelwrwait.c 3 | * 4 | * Description: 5 | * This translation unit implements read/write lock primitives. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | void 41 | ptw32_rwlock_cancelwrwait (void *arg) 42 | { 43 | pthread_rwlock_t rwl = (pthread_rwlock_t) arg; 44 | 45 | rwl->nSharedAccessCount = -rwl->nCompletedSharedAccessCount; 46 | rwl->nCompletedSharedAccessCount = 0; 47 | 48 | (void) pthread_mutex_unlock (&(rwl->mtxSharedAccessCompleted)); 49 | (void) pthread_mutex_unlock (&(rwl->mtxExclusiveAccess)); 50 | } 51 | -------------------------------------------------------------------------------- /compat/win32/pthreads/rwlock.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rwlock.c 3 | * 4 | * Description: 5 | * This translation unit implements read/write lock primitives. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "ptw32_rwlock_check_need_init.c" 38 | #include "ptw32_rwlock_cancelwrwait.c" 39 | #include "pthread_rwlock_init.c" 40 | #include "pthread_rwlock_destroy.c" 41 | #include "pthread_rwlockattr_init.c" 42 | #include "pthread_rwlockattr_destroy.c" 43 | #include "pthread_rwlockattr_getpshared.c" 44 | #include "pthread_rwlockattr_setpshared.c" 45 | #include "pthread_rwlock_rdlock.c" 46 | #include "pthread_rwlock_timedrdlock.c" 47 | #include "pthread_rwlock_wrlock.c" 48 | #include "pthread_rwlock_timedwrlock.c" 49 | #include "pthread_rwlock_unlock.c" 50 | #include "pthread_rwlock_tryrdlock.c" 51 | #include "pthread_rwlock_trywrlock.c" 52 | -------------------------------------------------------------------------------- /compat/win32/pthreads/sched.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sched.c 3 | * 4 | * Description: 5 | * POSIX thread functions that deal with thread scheduling. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | #include "sched.h" 40 | 41 | #include "pthread_attr_setschedpolicy.c" 42 | #include "pthread_attr_getschedpolicy.c" 43 | #include "pthread_attr_setschedparam.c" 44 | #include "pthread_attr_getschedparam.c" 45 | #include "pthread_attr_setinheritsched.c" 46 | #include "pthread_attr_getinheritsched.c" 47 | #include "pthread_setschedparam.c" 48 | #include "pthread_getschedparam.c" 49 | #include "sched_get_priority_max.c" 50 | #include "sched_get_priority_min.c" 51 | #include "sched_setscheduler.c" 52 | #include "sched_getscheduler.c" 53 | #include "sched_yield.c" 54 | -------------------------------------------------------------------------------- /compat/win32/pthreads/sched_getscheduler.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sched_getscheduler.c 3 | * 4 | * Description: 5 | * POSIX thread functions that deal with thread scheduling. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | #include "sched.h" 40 | 41 | int 42 | sched_getscheduler (pid_t pid) 43 | { 44 | /* 45 | * Win32 only has one policy which we call SCHED_OTHER. 46 | * However, we try to provide other valid side-effects 47 | * such as EPERM and ESRCH errors. 48 | */ 49 | if (0 != pid) 50 | { 51 | int selfPid = (int) GetCurrentProcessId (); 52 | 53 | if (pid != selfPid) 54 | { 55 | HANDLE h = 56 | OpenProcess (PROCESS_QUERY_INFORMATION, PTW32_FALSE, (DWORD) pid); 57 | 58 | if (NULL == h) 59 | { 60 | errno = 61 | (GetLastError () == 62 | (0xFF & ERROR_ACCESS_DENIED)) ? EPERM : ESRCH; 63 | return -1; 64 | } 65 | else 66 | CloseHandle(h); 67 | } 68 | } 69 | 70 | return SCHED_OTHER; 71 | } 72 | -------------------------------------------------------------------------------- /compat/win32/pthreads/sem_close.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------- 3 | * 4 | * Module: sem_close.c 5 | * 6 | * Purpose: 7 | * Semaphores aren't actually part of the PThreads standard. 8 | * They are defined by the POSIX Standard: 9 | * 10 | * POSIX 1003.1b-1993 (POSIX.1b) 11 | * 12 | * ------------------------------------------------------------- 13 | * 14 | * -------------------------------------------------------------------------- 15 | * 16 | * Pthreads-win32 - POSIX Threads Library for Win32 17 | * Copyright(C) 1998 John E. Bossom 18 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 19 | * 20 | * Contact Email: rpj@callisto.canberra.edu.au 21 | * 22 | * The current list of contributors is contained 23 | * in the file CONTRIBUTORS included with the source 24 | * code distribution. The list can also be seen at the 25 | * following World Wide Web location: 26 | * http://sources.redhat.com/pthreads-win32/contributors.html 27 | * 28 | * This library is free software; you can redistribute it and/or 29 | * modify it under the terms of the GNU Lesser General Public 30 | * License as published by the Free Software Foundation; either 31 | * version 2 of the License, or (at your option) any later version. 32 | * 33 | * This library is distributed in the hope that it will be useful, 34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 36 | * Lesser General Public License for more details. 37 | * 38 | * You should have received a copy of the GNU Lesser General Public 39 | * License along with this library in the file COPYING.LIB; 40 | * if not, write to the Free Software Foundation, Inc., 41 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 42 | */ 43 | 44 | #include "pthread.h" 45 | #include "semaphore.h" 46 | #include "implement.h" 47 | 48 | /* ignore warning "unreferenced formal parameter" */ 49 | #if defined(_MSC_VER) 50 | #pragma warning( disable : 4100 ) 51 | #endif 52 | 53 | int 54 | sem_close (sem_t * sem) 55 | { 56 | errno = ENOSYS; 57 | return -1; 58 | } /* sem_close */ 59 | -------------------------------------------------------------------------------- /compat/win32/pthreads/sem_open.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------- 3 | * 4 | * Module: sem_open.c 5 | * 6 | * Purpose: 7 | * Semaphores aren't actually part of the PThreads standard. 8 | * They are defined by the POSIX Standard: 9 | * 10 | * POSIX 1003.1b-1993 (POSIX.1b) 11 | * 12 | * ------------------------------------------------------------- 13 | * 14 | * -------------------------------------------------------------------------- 15 | * 16 | * Pthreads-win32 - POSIX Threads Library for Win32 17 | * Copyright(C) 1998 John E. Bossom 18 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 19 | * 20 | * Contact Email: rpj@callisto.canberra.edu.au 21 | * 22 | * The current list of contributors is contained 23 | * in the file CONTRIBUTORS included with the source 24 | * code distribution. The list can also be seen at the 25 | * following World Wide Web location: 26 | * http://sources.redhat.com/pthreads-win32/contributors.html 27 | * 28 | * This library is free software; you can redistribute it and/or 29 | * modify it under the terms of the GNU Lesser General Public 30 | * License as published by the Free Software Foundation; either 31 | * version 2 of the License, or (at your option) any later version. 32 | * 33 | * This library is distributed in the hope that it will be useful, 34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 36 | * Lesser General Public License for more details. 37 | * 38 | * You should have received a copy of the GNU Lesser General Public 39 | * License along with this library in the file COPYING.LIB; 40 | * if not, write to the Free Software Foundation, Inc., 41 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 42 | */ 43 | 44 | #include "pthread.h" 45 | #include "semaphore.h" 46 | #include "implement.h" 47 | 48 | /* ignore warning "unreferenced formal parameter" */ 49 | #if defined(_MSC_VER) 50 | #pragma warning( disable : 4100 ) 51 | #endif 52 | 53 | int 54 | sem_open (const char *name, int oflag, mode_t mode, unsigned int value) 55 | { 56 | errno = ENOSYS; 57 | return -1; 58 | } /* sem_open */ 59 | -------------------------------------------------------------------------------- /compat/win32/pthreads/sem_unlink.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------- 3 | * 4 | * Module: sem_unlink.c 5 | * 6 | * Purpose: 7 | * Semaphores aren't actually part of the PThreads standard. 8 | * They are defined by the POSIX Standard: 9 | * 10 | * POSIX 1003.1b-1993 (POSIX.1b) 11 | * 12 | * ------------------------------------------------------------- 13 | * 14 | * -------------------------------------------------------------------------- 15 | * 16 | * Pthreads-win32 - POSIX Threads Library for Win32 17 | * Copyright(C) 1998 John E. Bossom 18 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 19 | * 20 | * Contact Email: rpj@callisto.canberra.edu.au 21 | * 22 | * The current list of contributors is contained 23 | * in the file CONTRIBUTORS included with the source 24 | * code distribution. The list can also be seen at the 25 | * following World Wide Web location: 26 | * http://sources.redhat.com/pthreads-win32/contributors.html 27 | * 28 | * This library is free software; you can redistribute it and/or 29 | * modify it under the terms of the GNU Lesser General Public 30 | * License as published by the Free Software Foundation; either 31 | * version 2 of the License, or (at your option) any later version. 32 | * 33 | * This library is distributed in the hope that it will be useful, 34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 36 | * Lesser General Public License for more details. 37 | * 38 | * You should have received a copy of the GNU Lesser General Public 39 | * License along with this library in the file COPYING.LIB; 40 | * if not, write to the Free Software Foundation, Inc., 41 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 42 | */ 43 | 44 | #include "pthread.h" 45 | #include "semaphore.h" 46 | #include "implement.h" 47 | 48 | /* ignore warning "unreferenced formal parameter" */ 49 | #if defined(_MSC_VER) 50 | #pragma warning( disable : 4100 ) 51 | #endif 52 | 53 | int 54 | sem_unlink (const char *name) 55 | { 56 | errno = ENOSYS; 57 | return -1; 58 | } /* sem_unlink */ 59 | -------------------------------------------------------------------------------- /compat/win32/pthreads/semaphore.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ------------------------------------------------------------- 3 | * 4 | * Module: semaphore.c 5 | * 6 | * Purpose: 7 | * Concatenated version of separate modules to allow 8 | * inlining optimisation, which it is assumed can only 9 | * be effective within a single module. 10 | * 11 | * Semaphores aren't actually part of the PThreads standard. 12 | * They are defined by the POSIX Standard: 13 | * 14 | * POSIX 1003.1b-1993 (POSIX.1b) 15 | * 16 | * ------------------------------------------------------------- 17 | * 18 | * -------------------------------------------------------------------------- 19 | * 20 | * Pthreads-win32 - POSIX Threads Library for Win32 21 | * Copyright(C) 1998 John E. Bossom 22 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 23 | * 24 | * Contact Email: rpj@callisto.canberra.edu.au 25 | * 26 | * The current list of contributors is contained 27 | * in the file CONTRIBUTORS included with the source 28 | * code distribution. The list can also be seen at the 29 | * following World Wide Web location: 30 | * http://sources.redhat.com/pthreads-win32/contributors.html 31 | * 32 | * This library is free software; you can redistribute it and/or 33 | * modify it under the terms of the GNU Lesser General Public 34 | * License as published by the Free Software Foundation; either 35 | * version 2 of the License, or (at your option) any later version. 36 | * 37 | * This library is distributed in the hope that it will be useful, 38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 40 | * Lesser General Public License for more details. 41 | * 42 | * You should have received a copy of the GNU Lesser General Public 43 | * License along with this library in the file COPYING.LIB; 44 | * if not, write to the Free Software Foundation, Inc., 45 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 46 | */ 47 | 48 | #if !defined(NEED_FTIME) 49 | # include 50 | #endif 51 | 52 | #include 53 | 54 | #include "pthread.h" 55 | #include "semaphore.h" 56 | #include "implement.h" 57 | 58 | 59 | #include "sem_init.c" 60 | #include "sem_destroy.c" 61 | #include "sem_trywait.c" 62 | #include "sem_wait.c" 63 | #include "sem_timedwait.c" 64 | #include "sem_post.c" 65 | #include "sem_post_multiple.c" 66 | #include "sem_getvalue.c" 67 | #include "sem_open.c" 68 | #include "sem_close.c" 69 | #include "sem_unlink.c" 70 | -------------------------------------------------------------------------------- /compat/win32/pthreads/spin.c: -------------------------------------------------------------------------------- 1 | /* 2 | * spin.c 3 | * 4 | * Description: 5 | * This translation unit implements spin lock primitives. 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | #include "ptw32_spinlock_check_need_init.c" 42 | #include "pthread_spin_init.c" 43 | #include "pthread_spin_destroy.c" 44 | #include "pthread_spin_lock.c" 45 | #include "pthread_spin_unlock.c" 46 | #include "pthread_spin_trylock.c" 47 | -------------------------------------------------------------------------------- /compat/win32/pthreads/sync.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sync.c 3 | * 4 | * Description: 5 | * This translation unit implements functions related to thread 6 | * synchronisation. 7 | * 8 | * -------------------------------------------------------------------------- 9 | * 10 | * Pthreads-win32 - POSIX Threads Library for Win32 11 | * Copyright(C) 1998 John E. Bossom 12 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 13 | * 14 | * Contact Email: rpj@callisto.canberra.edu.au 15 | * 16 | * The current list of contributors is contained 17 | * in the file CONTRIBUTORS included with the source 18 | * code distribution. The list can also be seen at the 19 | * following World Wide Web location: 20 | * http://sources.redhat.com/pthreads-win32/contributors.html 21 | * 22 | * This library is free software; you can redistribute it and/or 23 | * modify it under the terms of the GNU Lesser General Public 24 | * License as published by the Free Software Foundation; either 25 | * version 2 of the License, or (at your option) any later version. 26 | * 27 | * This library is distributed in the hope that it will be useful, 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 30 | * Lesser General Public License for more details. 31 | * 32 | * You should have received a copy of the GNU Lesser General Public 33 | * License along with this library in the file COPYING.LIB; 34 | * if not, write to the Free Software Foundation, Inc., 35 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 36 | */ 37 | 38 | #include "pthread.h" 39 | #include "implement.h" 40 | 41 | 42 | #include "pthread_detach.c" 43 | #include "pthread_join.c" 44 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/Debug.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "Debug"=.\Debug.dsp - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/Debug.plg: -------------------------------------------------------------------------------- 1 | 2 | 3 |
 4 | 

Build Log

5 |

6 | --------------------Configuration: Debug - Win32 Debug-------------------- 7 |

8 |

Command Lines

9 | Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP9.tmp" with contents 10 | [ 11 | /nologo /MDd /W3 /WX /Gm /ZI /Od /I ".." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /D "CLEANUP_C" /FR"Debug/" /Fp"Debug/Debug.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c 12 | "E:\PTHREADS\pthreads.2\tests\semaphore1.c" 13 | ] 14 | Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP9.tmp" 15 | Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSPA.tmp" with contents 16 | [ 17 | kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib pthreadVC2d.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/Debug.pdb" /debug /machine:I386 /out:"Debug/Debug.exe" /pdbtype:sept /libpath:".." 18 | .\Debug\semaphore1.obj 19 | ] 20 | Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSPA.tmp" 21 |

Output Window

22 | Compiling... 23 | semaphore1.c 24 | Linking... 25 | 26 | 27 | 28 |

Results

29 | Debug.exe - 0 error(s), 0 warning(s) 30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/Debug.txt: -------------------------------------------------------------------------------- 1 | This project is used to debug individual test case programs. 2 | 3 | To build and debug a test case: 4 | - add the .c file to this project; 5 | - remove any .c files from other test cases from this project. 6 | - build and debug as usual. -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/README: -------------------------------------------------------------------------------- 1 | Running test cases in this directory 2 | ------------------------------------ 3 | 4 | These make scripts expect to be able to copy the dll, library 5 | and header files from this directory's parent directory, 6 | which should be the pthreads-win32 source directory. 7 | 8 | MS VC nmake 9 | ------------- 10 | 11 | Run the target corresponding to the DLL version being tested: 12 | 13 | nmake clean VC 14 | 15 | or: 16 | 17 | nmake clean VS 18 | 19 | 20 | GNU GCC make 21 | ------------ 22 | 23 | Run "make clean" and then "make". See the "Known bugs" section 24 | in ..\README. 25 | 26 | 27 | Writing Test Cases 28 | ------------------ 29 | 30 | Tests written in this test suite should behave in the following manner: 31 | 32 | * If a test fails, leave main() with a result of 1. 33 | 34 | * If a test succeeds, leave main() with a result of 0. 35 | 36 | * No diagnostic output should appear when the test is succeeding. 37 | Diagnostic output may be emitted if something in the test 38 | fails, to help determine the cause of the test failure. 39 | 40 | Notes: 41 | ------ 42 | 43 | Many test cases use knowledge of implementation internals which are supposed 44 | to be opaque to portable applications. 45 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/README.BENCHTESTS: -------------------------------------------------------------------------------- 1 | 2 | ------------ 3 | Benchmarking 4 | ------------ 5 | There is a set a benchmarking programs in the 6 | "tests" directory. These should be runnable using the 7 | following command-lines corresponding to each of the possible 8 | library builds: 9 | 10 | MSVC: 11 | nmake clean VC-bench 12 | nmake clean VCE-bench 13 | nmake clean VSE-bench 14 | 15 | Mingw32: 16 | make clean GC-bench 17 | make clean GCE-bench 18 | 19 | UWIN: 20 | The benchtests are run as part of the testsuite. 21 | 22 | 23 | Mutex benchtests 24 | ---------------- 25 | 26 | benchtest1 - Lock plus unlock on an unlocked mutex. 27 | benchtest2 - Lock plus unlock on a locked mutex. 28 | benchtest3 - Trylock on a locked mutex. 29 | benchtest4 - Trylock plus unlock on an unlocked mutex. 30 | 31 | 32 | Each test times up to three alternate synchronisation 33 | implementations as a reference, and then times each of 34 | the four mutex types provided by the library. Each is 35 | described below: 36 | 37 | Simple Critical Section 38 | - uses a simple Win32 critical section. There is no 39 | additional overhead for this case as there is in the 40 | remaining cases. 41 | 42 | POSIX mutex implemented using a Critical Section 43 | - The old implementation which uses runtime adaptation 44 | depending on the Windows variant being run on. When 45 | the pthreads DLL was run on WinNT or higher then 46 | POSIX mutexes would use Win32 Critical Sections. 47 | 48 | POSIX mutex implemented using a Win32 Mutex 49 | - The old implementation which uses runtime adaptation 50 | depending on the Windows variant being run on. When 51 | the pthreads DLL was run on Win9x then POSIX mutexes 52 | would use Win32 Mutexes (because TryEnterCriticalSection 53 | is not implemented on Win9x). 54 | 55 | PTHREAD_MUTEX_DEFAULT 56 | PTHREAD_MUTEX_NORMAL 57 | PTHREAD_MUTEX_ERRORCHECK 58 | PTHREAD_MUTEX_RECURSIVE 59 | - The current implementation supports these mutex types. 60 | The underlying basis of POSIX mutexes is now the same 61 | irrespective of the Windows variant, and should therefore 62 | have consistent performance. 63 | 64 | 65 | Semaphore benchtests 66 | -------------------- 67 | 68 | benchtest5 - Timing for various uncontended cases. 69 | 70 | 71 | In all benchtests, the operation is repeated a large 72 | number of times and an average is calculated. Loop 73 | overhead is measured and subtracted from all test times. 74 | 75 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/SIZES.GC: -------------------------------------------------------------------------------- 1 | Sizes of pthreads-win32 structs 2 | ------------------------------- 3 | pthread_t 8 4 | ptw32_thread_t 160 5 | pthread_attr_t_ 28 6 | sem_t_ 12 7 | pthread_mutex_t_ 28 8 | pthread_mutexattr_t_ 12 9 | pthread_spinlock_t_ 8 10 | pthread_barrier_t_ 36 11 | pthread_barrierattr_t_ 4 12 | pthread_key_t_ 16 13 | pthread_cond_t_ 32 14 | pthread_condattr_t_ 4 15 | pthread_rwlock_t_ 28 16 | pthread_rwlockattr_t_ 4 17 | pthread_once_t_ 16 18 | ptw32_cleanup_t 12 19 | ptw32_mcs_node_t_ 16 20 | sched_param 4 21 | ------------------------------- 22 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/SIZES.GCE: -------------------------------------------------------------------------------- 1 | Sizes of pthreads-win32 structs 2 | ------------------------------- 3 | pthread_t 8 4 | ptw32_thread_t 96 5 | pthread_attr_t_ 28 6 | sem_t_ 12 7 | pthread_mutex_t_ 28 8 | pthread_mutexattr_t_ 12 9 | pthread_spinlock_t_ 8 10 | pthread_barrier_t_ 36 11 | pthread_barrierattr_t_ 4 12 | pthread_key_t_ 16 13 | pthread_cond_t_ 32 14 | pthread_condattr_t_ 4 15 | pthread_rwlock_t_ 28 16 | pthread_rwlockattr_t_ 4 17 | pthread_once_t_ 16 18 | ptw32_cleanup_t 12 19 | ptw32_mcs_node_t_ 16 20 | sched_param 4 21 | ------------------------------- 22 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/SIZES.VC: -------------------------------------------------------------------------------- 1 | Sizes of pthreads-win32 structs 2 | ------------------------------- 3 | pthread_t 16 4 | ptw32_thread_t 432 5 | pthread_attr_t_ 40 6 | sem_t_ 24 7 | pthread_mutex_t_ 48 8 | pthread_mutexattr_t_ 12 9 | pthread_spinlock_t_ 16 10 | pthread_barrier_t_ 64 11 | pthread_barrierattr_t_ 4 12 | pthread_key_t_ 32 13 | pthread_cond_t_ 56 14 | pthread_condattr_t_ 4 15 | pthread_rwlock_t_ 40 16 | pthread_rwlockattr_t_ 4 17 | pthread_once_t_ 24 18 | ptw32_cleanup_t 24 19 | ptw32_mcs_node_t_ 32 20 | sched_param 4 21 | ------------------------------- 22 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/SIZES.VCE: -------------------------------------------------------------------------------- 1 | Sizes of pthreads-win32 structs 2 | ------------------------------- 3 | pthread_t 8 4 | ptw32_thread_t 96 5 | pthread_attr_t_ 28 6 | sem_t_ 12 7 | pthread_mutex_t_ 28 8 | pthread_mutexattr_t_ 12 9 | pthread_spinlock_t_ 8 10 | pthread_barrier_t_ 36 11 | pthread_barrierattr_t_ 4 12 | pthread_key_t_ 16 13 | pthread_cond_t_ 32 14 | pthread_condattr_t_ 4 15 | pthread_rwlock_t_ 28 16 | pthread_rwlockattr_t_ 4 17 | pthread_once_t_ 16 18 | ptw32_cleanup_t 12 19 | ptw32_mcs_node_t_ 16 20 | sched_param 4 21 | ------------------------------- 22 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/SIZES.VSE: -------------------------------------------------------------------------------- 1 | Sizes of pthreads-win32 structs 2 | ------------------------------- 3 | pthread_t 8 4 | ptw32_thread_t 96 5 | pthread_attr_t_ 28 6 | sem_t_ 12 7 | pthread_mutex_t_ 28 8 | pthread_mutexattr_t_ 12 9 | pthread_spinlock_t_ 8 10 | pthread_barrier_t_ 36 11 | pthread_barrierattr_t_ 4 12 | pthread_key_t_ 16 13 | pthread_cond_t_ 32 14 | pthread_condattr_t_ 4 15 | pthread_rwlock_t_ 28 16 | pthread_rwlockattr_t_ 4 17 | pthread_once_t_ 16 18 | ptw32_cleanup_t 12 19 | ptw32_mcs_node_t_ 16 20 | sched_param 4 21 | ------------------------------- 22 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/barrier1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * barrier1.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Create a barrier object and then destroy it. 37 | * 38 | */ 39 | 40 | #include "test.h" 41 | 42 | pthread_barrier_t barrier = NULL; 43 | 44 | int 45 | main() 46 | { 47 | assert(barrier == NULL); 48 | 49 | assert(pthread_barrier_init(&barrier, NULL, 1) == 0); 50 | 51 | assert(barrier != NULL); 52 | 53 | assert(pthread_barrier_destroy(&barrier) == 0); 54 | 55 | assert(barrier == NULL); 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/barrier2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * barrier2.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a single barrier object, wait on it, 37 | * and then destroy it. 38 | * 39 | */ 40 | 41 | #include "test.h" 42 | 43 | pthread_barrier_t barrier = NULL; 44 | 45 | int 46 | main() 47 | { 48 | assert(pthread_barrier_init(&barrier, NULL, 1) == 0); 49 | 50 | assert(pthread_barrier_wait(&barrier) == PTHREAD_BARRIER_SERIAL_THREAD); 51 | 52 | assert(pthread_barrier_destroy(&barrier) == 0); 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/create1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * create1.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Description: 37 | * Create a thread and check that it ran. 38 | * 39 | * Depends on API functions: None. 40 | */ 41 | 42 | #include "test.h" 43 | 44 | static int washere = 0; 45 | 46 | void * func(void * arg) 47 | { 48 | washere = 1; 49 | return 0; 50 | } 51 | 52 | int 53 | main() 54 | { 55 | pthread_t t; 56 | 57 | assert(pthread_create(&t, NULL, func, NULL) == 0); 58 | 59 | /* A dirty hack, but we cannot rely on pthread_join in this 60 | primitive test. */ 61 | Sleep(2000); 62 | 63 | assert(washere == 1); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/delay1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * delay1.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Depends on API functions: 37 | * pthread_delay_np 38 | */ 39 | 40 | #include "test.h" 41 | 42 | int 43 | main(int argc, char * argv[]) 44 | { 45 | struct timespec interval = {1L, 500000000L}; 46 | 47 | assert(pthread_delay_np(&interval) == 0); 48 | 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/equal1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test for pthread_equal. 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Depends on functions: pthread_create(). 37 | */ 38 | 39 | #include "test.h" 40 | 41 | void * func(void * arg) 42 | { 43 | Sleep(2000); 44 | return 0; 45 | } 46 | 47 | int 48 | main() 49 | { 50 | pthread_t t1, t2; 51 | 52 | assert(pthread_create(&t1, NULL, func, (void *) 1) == 0); 53 | 54 | assert(pthread_create(&t2, NULL, func, (void *) 2) == 0); 55 | 56 | assert(pthread_equal(t1, t2) == 0); 57 | 58 | assert(pthread_equal(t1,t1) != 0); 59 | 60 | /* This is a hack. We don't want to rely on pthread_join 61 | yet if we can help it. */ 62 | Sleep(4000); 63 | 64 | /* Success. */ 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/exit1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test for pthread_exit(). 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Depends on API functions: None. 37 | */ 38 | 39 | #include "test.h" 40 | 41 | int 42 | main(int argc, char * argv[]) 43 | { 44 | /* A simple test first. */ 45 | pthread_exit((void *) 0); 46 | 47 | /* Not reached */ 48 | assert(0); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/exit2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test for pthread_exit(). 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Depends on API functions: 37 | * pthread_create() 38 | * pthread_exit() 39 | */ 40 | 41 | #include "test.h" 42 | 43 | void * 44 | func(void * arg) 45 | { 46 | pthread_exit(arg); 47 | 48 | /* Never reached. */ 49 | assert(0); 50 | 51 | return NULL; 52 | } 53 | 54 | int 55 | main(int argc, char * argv[]) 56 | { 57 | pthread_t t; 58 | 59 | assert(pthread_create(&t, NULL, func, (void *) NULL) == 0); 60 | 61 | Sleep(100); 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/exit3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test for pthread_exit(). 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Depends on API functions: pthread_create(). 37 | */ 38 | 39 | #include "test.h" 40 | 41 | void * 42 | func(void * arg) 43 | { 44 | pthread_exit(arg); 45 | 46 | /* Never reached. */ 47 | assert(0); 48 | 49 | return NULL; 50 | } 51 | 52 | int 53 | main(int argc, char * argv[]) 54 | { 55 | pthread_t id[4]; 56 | int i; 57 | 58 | /* Create a few threads and then exit. */ 59 | for (i = 0; i < 4; i++) 60 | { 61 | assert(pthread_create(&id[i], NULL, func, (void *)(size_t)i) == 0); 62 | } 63 | 64 | Sleep(400); 65 | 66 | /* Success. */ 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/join0.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test for pthread_join(). 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Depends on API functions: pthread_create(), pthread_exit(). 37 | */ 38 | 39 | #include "test.h" 40 | 41 | void * 42 | func(void * arg) 43 | { 44 | Sleep(2000); 45 | 46 | pthread_exit(arg); 47 | 48 | /* Never reached. */ 49 | exit(1); 50 | } 51 | 52 | int 53 | main(int argc, char * argv[]) 54 | { 55 | pthread_t id; 56 | void* result = (void*)0; 57 | 58 | /* Create a single thread and wait for it to exit. */ 59 | assert(pthread_create(&id, NULL, func, (void *) 123) == 0); 60 | 61 | assert(pthread_join(id, &result) == 0); 62 | 63 | assert((int)(size_t)result == 123); 64 | 65 | /* Success. */ 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/join2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test for pthread_join() returning return value from threads. 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Depends on API functions: pthread_create(). 37 | */ 38 | 39 | #include "test.h" 40 | 41 | void * 42 | func(void * arg) 43 | { 44 | Sleep(1000); 45 | return arg; 46 | } 47 | 48 | int 49 | main(int argc, char * argv[]) 50 | { 51 | pthread_t id[4]; 52 | int i; 53 | void* result = (void*)-1; 54 | 55 | /* Create a few threads and then exit. */ 56 | for (i = 0; i < 4; i++) 57 | { 58 | assert(pthread_create(&id[i], NULL, func, (void *)(size_t)i) == 0); 59 | } 60 | 61 | for (i = 0; i < 4; i++) 62 | { 63 | assert(pthread_join(id[i], &result) == 0); 64 | assert((int)(size_t)result == i); 65 | } 66 | 67 | /* Success. */ 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/join3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Test for pthread_join() returning return value from threads. 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Depends on API functions: pthread_create(). 37 | */ 38 | 39 | #include "test.h" 40 | 41 | void * 42 | func(void * arg) 43 | { 44 | sched_yield(); 45 | return arg; 46 | } 47 | 48 | int 49 | main(int argc, char * argv[]) 50 | { 51 | pthread_t id[4]; 52 | int i; 53 | void* result = (void*)-1; 54 | 55 | /* Create a few threads and then exit. */ 56 | for (i = 0; i < 4; i++) 57 | { 58 | assert(pthread_create(&id[i], NULL, func, (void *)(size_t)i) == 0); 59 | } 60 | 61 | /* 62 | * Let threads exit before we join them. 63 | * We should still retrieve the exit code for the threads. 64 | */ 65 | Sleep(1000); 66 | 67 | for (i = 0; i < 4; i++) 68 | { 69 | assert(pthread_join(id[i], &result) == 0); 70 | assert((int)(size_t)result == i); 71 | } 72 | 73 | /* Success. */ 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/kill1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * File: kill1.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Test Synopsis: 37 | * - pthread_kill() does not support non zero signals.. 38 | * 39 | * Test Method (Validation or Falsification): 40 | * - 41 | * 42 | * Requirements Tested: 43 | * - 44 | * 45 | * Features Tested: 46 | * - 47 | * 48 | * Cases Tested: 49 | * - 50 | * 51 | * Description: 52 | * - 53 | * 54 | * Environment: 55 | * - 56 | * 57 | * Input: 58 | * - None. 59 | * 60 | * Output: 61 | * - File name, Line number, and failed expression on failure. 62 | * - No output on success. 63 | * 64 | * Assumptions: 65 | * - 66 | * 67 | * Pass Criteria: 68 | * - Process returns zero exit status. 69 | * 70 | * Fail Criteria: 71 | * - Process returns non-zero exit status. 72 | */ 73 | 74 | #include "test.h" 75 | 76 | 77 | int 78 | main() 79 | { 80 | assert(pthread_kill(pthread_self(), 1) == EINVAL); 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/mutex1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutex1.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Create a simple mutex object, lock it, and then unlock it again. 37 | * This is the simplest test of the pthread mutex family that we can do. 38 | * 39 | * Depends on API functions: 40 | * pthread_mutex_init() 41 | * pthread_mutex_lock() 42 | * pthread_mutex_unlock() 43 | * pthread_mutex_destroy() 44 | */ 45 | 46 | #include "test.h" 47 | 48 | pthread_mutex_t mutex = NULL; 49 | 50 | int 51 | main() 52 | { 53 | assert(mutex == NULL); 54 | 55 | assert(pthread_mutex_init(&mutex, NULL) == 0); 56 | 57 | assert(mutex != NULL); 58 | 59 | assert(pthread_mutex_lock(&mutex) == 0); 60 | 61 | assert(pthread_mutex_unlock(&mutex) == 0); 62 | 63 | assert(pthread_mutex_destroy(&mutex) == 0); 64 | 65 | assert(mutex == NULL); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/mutex2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutex2.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a static mutex object, lock it, 37 | * and then unlock it again. 38 | * 39 | * Depends on API functions: 40 | * pthread_mutex_lock() 41 | * pthread_mutex_unlock() 42 | */ 43 | 44 | #include "test.h" 45 | 46 | pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 47 | 48 | int 49 | main() 50 | { 51 | assert(mutex == PTHREAD_MUTEX_INITIALIZER); 52 | 53 | assert(pthread_mutex_lock(&mutex) == 0); 54 | 55 | assert(mutex != PTHREAD_MUTEX_INITIALIZER); 56 | 57 | assert(mutex != NULL); 58 | 59 | assert(pthread_mutex_unlock(&mutex) == 0); 60 | 61 | assert(pthread_mutex_destroy(&mutex) == 0); 62 | 63 | assert(mutex == NULL); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/mutex2e.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutex2e.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a static mutex object, lock it, 37 | * and then unlock it again. 38 | * 39 | * Depends on API functions: 40 | * pthread_mutex_lock() 41 | * pthread_mutex_unlock() 42 | */ 43 | 44 | #include "test.h" 45 | 46 | pthread_mutex_t mutex = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER; 47 | 48 | int 49 | main() 50 | { 51 | assert(mutex == PTHREAD_ERRORCHECK_MUTEX_INITIALIZER); 52 | 53 | assert(pthread_mutex_lock(&mutex) == 0); 54 | 55 | assert(mutex != PTHREAD_ERRORCHECK_MUTEX_INITIALIZER); 56 | 57 | assert(mutex != NULL); 58 | 59 | assert(pthread_mutex_unlock(&mutex) == 0); 60 | 61 | assert(pthread_mutex_destroy(&mutex) == 0); 62 | 63 | assert(mutex == NULL); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/mutex2r.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutex2r.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a static mutex object, lock it, 37 | * and then unlock it again. 38 | * 39 | * Depends on API functions: 40 | * pthread_mutex_lock() 41 | * pthread_mutex_unlock() 42 | */ 43 | 44 | #include "test.h" 45 | 46 | pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; 47 | 48 | int 49 | main() 50 | { 51 | assert(mutex == PTHREAD_RECURSIVE_MUTEX_INITIALIZER); 52 | 53 | assert(pthread_mutex_lock(&mutex) == 0); 54 | 55 | assert(mutex != PTHREAD_RECURSIVE_MUTEX_INITIALIZER); 56 | 57 | assert(mutex != NULL); 58 | 59 | assert(pthread_mutex_unlock(&mutex) == 0); 60 | 61 | assert(pthread_mutex_destroy(&mutex) == 0); 62 | 63 | assert(mutex == NULL); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/mutex3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutex3.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a static mutex object, lock it, trylock it, 37 | * and then unlock it again. 38 | * 39 | * Depends on API functions: 40 | * pthread_mutex_lock() 41 | * pthread_mutex_trylock() 42 | * pthread_mutex_unlock() 43 | */ 44 | 45 | #include "test.h" 46 | 47 | pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER; 48 | 49 | static int washere = 0; 50 | 51 | void * func(void * arg) 52 | { 53 | assert(pthread_mutex_trylock(&mutex1) == EBUSY); 54 | 55 | washere = 1; 56 | 57 | return 0; 58 | } 59 | 60 | int 61 | main() 62 | { 63 | pthread_t t; 64 | 65 | assert(pthread_mutex_lock(&mutex1) == 0); 66 | 67 | assert(pthread_create(&t, NULL, func, NULL) == 0); 68 | assert(pthread_join(t, NULL) == 0); 69 | 70 | assert(pthread_mutex_unlock(&mutex1) == 0); 71 | 72 | assert(washere == 1); 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/mutex3e.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutex3e.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a static mutex object, lock it, trylock it, 37 | * and then unlock it again. 38 | * 39 | * Depends on API functions: 40 | * pthread_mutex_lock() 41 | * pthread_mutex_trylock() 42 | * pthread_mutex_unlock() 43 | */ 44 | 45 | #include "test.h" 46 | 47 | pthread_mutex_t mutex1 = PTHREAD_ERRORCHECK_MUTEX_INITIALIZER; 48 | 49 | static int washere = 0; 50 | 51 | void * func(void * arg) 52 | { 53 | assert(pthread_mutex_trylock(&mutex1) == EBUSY); 54 | 55 | washere = 1; 56 | 57 | return 0; 58 | } 59 | 60 | int 61 | main() 62 | { 63 | pthread_t t; 64 | 65 | assert(pthread_mutex_lock(&mutex1) == 0); 66 | 67 | assert(pthread_create(&t, NULL, func, NULL) == 0); 68 | assert(pthread_join(t, NULL) == 0); 69 | 70 | assert(pthread_mutex_unlock(&mutex1) == 0); 71 | 72 | assert(washere == 1); 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/mutex3r.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutex3r.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a static mutex object, lock it, trylock it, 37 | * and then unlock it again. 38 | * 39 | * Depends on API functions: 40 | * pthread_mutex_lock() 41 | * pthread_mutex_trylock() 42 | * pthread_mutex_unlock() 43 | */ 44 | 45 | #include "test.h" 46 | 47 | pthread_mutex_t mutex1 = PTHREAD_RECURSIVE_MUTEX_INITIALIZER; 48 | 49 | static int washere = 0; 50 | 51 | void * func(void * arg) 52 | { 53 | assert(pthread_mutex_trylock(&mutex1) == EBUSY); 54 | 55 | washere = 1; 56 | 57 | return 0; 58 | } 59 | 60 | int 61 | main() 62 | { 63 | pthread_t t; 64 | 65 | assert(pthread_mutex_lock(&mutex1) == 0); 66 | 67 | assert(pthread_create(&t, NULL, func, NULL) == 0); 68 | assert(pthread_join(t, NULL) == 0); 69 | 70 | assert(pthread_mutex_unlock(&mutex1) == 0); 71 | 72 | assert(washere == 1); 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/mutex8.c: -------------------------------------------------------------------------------- 1 | /* 2 | * mutex8.c 3 | * 4 | * 5 | * Pthreads-win32 - POSIX Threads Library for Win32 6 | * Copyright (C) 1998 Ben Elliston and Ross Johnson 7 | * Copyright (C) 1999,2000,2001 Ross Johnson 8 | * 9 | * Contact Email: rpj@ise.canberra.edu.au 10 | * 11 | * This library is free software; you can redistribute it and/or 12 | * modify it under the terms of the GNU Lesser General Public 13 | * License as published by the Free Software Foundation; either 14 | * version 2.1 of the License, or (at your option) any later version. 15 | * 16 | * This library is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | * Lesser General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU Lesser General Public 22 | * License along with this library; if not, write to the Free Software 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | * 25 | * -------------------------------------------------------------------------- 26 | * 27 | * Test the default (type not set) mutex type exercising timedlock. 28 | * Thread locks mutex, another thread timedlocks the mutex. 29 | * Timed thread should timeout. 30 | * 31 | * Depends on API functions: 32 | * pthread_mutex_lock() 33 | * pthread_mutex_timedlock() 34 | * pthread_mutex_unlock() 35 | */ 36 | 37 | #include "test.h" 38 | #include 39 | 40 | static int lockCount = 0; 41 | 42 | static pthread_mutex_t mutex; 43 | 44 | void * locker(void * arg) 45 | { 46 | struct timespec abstime = { 0, 0 }; 47 | PTW32_STRUCT_TIMEB currSysTime; 48 | const DWORD NANOSEC_PER_MILLISEC = 1000000; 49 | 50 | PTW32_FTIME(&currSysTime); 51 | 52 | abstime.tv_sec = (long)currSysTime.time; 53 | abstime.tv_nsec = NANOSEC_PER_MILLISEC * currSysTime.millitm; 54 | 55 | abstime.tv_sec += 1; 56 | 57 | assert(pthread_mutex_timedlock(&mutex, &abstime) == ETIMEDOUT); 58 | 59 | lockCount++; 60 | 61 | return 0; 62 | } 63 | 64 | int 65 | main() 66 | { 67 | pthread_t t; 68 | 69 | assert(pthread_mutex_init(&mutex, NULL) == 0); 70 | 71 | assert(pthread_mutex_lock(&mutex) == 0); 72 | 73 | assert(pthread_create(&t, NULL, locker, NULL) == 0); 74 | 75 | Sleep(2000); 76 | 77 | assert(lockCount == 1); 78 | 79 | assert(pthread_mutex_unlock(&mutex) == 0); 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/once1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * once1.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Create a static pthread_once and test that it calls myfunc once. 37 | * 38 | * Depends on API functions: 39 | * pthread_once() 40 | * pthread_create() 41 | */ 42 | 43 | #include "test.h" 44 | 45 | pthread_once_t once = PTHREAD_ONCE_INIT; 46 | 47 | static int washere = 0; 48 | 49 | void 50 | myfunc(void) 51 | { 52 | washere++; 53 | } 54 | 55 | void * 56 | mythread(void * arg) 57 | { 58 | assert(pthread_once(&once, myfunc) == 0); 59 | 60 | return 0; 61 | } 62 | 63 | int 64 | main() 65 | { 66 | pthread_t t1, t2; 67 | 68 | assert(pthread_create(&t1, NULL, mythread, NULL) == 0); 69 | 70 | assert(pthread_create(&t2, NULL, mythread, NULL) == 0); 71 | 72 | Sleep(2000); 73 | 74 | assert(washere == 1); 75 | 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/rwlock1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rwlock1.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Create a simple rwlock object and then destroy it. 37 | * 38 | * Depends on API functions: 39 | * pthread_rwlock_init() 40 | * pthread_rwlock_destroy() 41 | */ 42 | 43 | #include "test.h" 44 | 45 | pthread_rwlock_t rwlock = NULL; 46 | 47 | int 48 | main() 49 | { 50 | assert(rwlock == NULL); 51 | 52 | assert(pthread_rwlock_init(&rwlock, NULL) == 0); 53 | 54 | assert(rwlock != NULL); 55 | 56 | assert(pthread_rwlock_destroy(&rwlock) == 0); 57 | 58 | assert(rwlock == NULL); 59 | 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/rwlock2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rwlock2.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a static rwlock object, lock it, 37 | * and then unlock it again. 38 | * 39 | * Depends on API functions: 40 | * pthread_rwlock_rdlock() 41 | * pthread_rwlock_unlock() 42 | */ 43 | 44 | #include "test.h" 45 | 46 | pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER; 47 | 48 | int 49 | main() 50 | { 51 | assert(rwlock == PTHREAD_RWLOCK_INITIALIZER); 52 | 53 | assert(pthread_rwlock_rdlock(&rwlock) == 0); 54 | 55 | assert(rwlock != PTHREAD_RWLOCK_INITIALIZER); 56 | 57 | assert(rwlock != NULL); 58 | 59 | assert(pthread_rwlock_unlock(&rwlock) == 0); 60 | 61 | assert(pthread_rwlock_destroy(&rwlock) == 0); 62 | 63 | assert(rwlock == NULL); 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/rwlock3.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rwlock3.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a static rwlock object, wrlock it, trywrlock it, 37 | * and then unlock it again. 38 | * 39 | * Depends on API functions: 40 | * pthread_create() 41 | * pthread_join() 42 | * pthread_rwlock_wrlock() 43 | * pthread_rwlock_trywrlock() 44 | * pthread_rwlock_unlock() 45 | */ 46 | 47 | #include "test.h" 48 | 49 | pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER; 50 | 51 | static int washere = 0; 52 | 53 | void * func(void * arg) 54 | { 55 | assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY); 56 | 57 | washere = 1; 58 | 59 | return 0; 60 | } 61 | 62 | int 63 | main() 64 | { 65 | pthread_t t; 66 | 67 | assert(pthread_rwlock_wrlock(&rwlock1) == 0); 68 | 69 | assert(pthread_create(&t, NULL, func, NULL) == 0); 70 | 71 | assert(pthread_join(t, NULL) == 0); 72 | 73 | assert(pthread_rwlock_unlock(&rwlock1) == 0); 74 | 75 | assert(washere == 1); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/rwlock4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rwlock4.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a static rwlock object, rdlock it, trywrlock it, 37 | * and then unlock it again. 38 | * 39 | * Depends on API functions: 40 | * pthread_create() 41 | * pthread_join() 42 | * pthread_rwlock_rdlock() 43 | * pthread_rwlock_trywrlock() 44 | * pthread_rwlock_unlock() 45 | */ 46 | 47 | #include "test.h" 48 | 49 | pthread_rwlock_t rwlock1 = PTHREAD_RWLOCK_INITIALIZER; 50 | 51 | static int washere = 0; 52 | 53 | void * func(void * arg) 54 | { 55 | assert(pthread_rwlock_trywrlock(&rwlock1) == EBUSY); 56 | 57 | washere = 1; 58 | 59 | return 0; 60 | } 61 | 62 | int 63 | main() 64 | { 65 | pthread_t t; 66 | 67 | assert(pthread_rwlock_rdlock(&rwlock1) == 0); 68 | 69 | assert(pthread_create(&t, NULL, func, NULL) == 0); 70 | 71 | assert(pthread_join(t, NULL) == 0); 72 | 73 | assert(pthread_rwlock_unlock(&rwlock1) == 0); 74 | 75 | assert(washere == 1); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/self1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * self1.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Test for pthread_self(). 37 | * 38 | * Depends on API functions: 39 | * pthread_self() 40 | * 41 | * Implicitly depends on: 42 | * pthread_getspecific() 43 | * pthread_setspecific() 44 | */ 45 | 46 | #include "test.h" 47 | 48 | int 49 | main(int argc, char * argv[]) 50 | { 51 | /* 52 | * This should always succeed unless the system has no 53 | * resources (memory) left. 54 | */ 55 | pthread_t self; 56 | 57 | #if defined(PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__)) 58 | pthread_win32_process_attach_np(); 59 | #endif 60 | 61 | self = pthread_self(); 62 | 63 | assert(self.p != NULL); 64 | 65 | #if defined(PTW32_STATIC_LIB) && !(defined(_MSC_VER) || defined(__MINGW32__)) 66 | pthread_win32_process_detach_np(); 67 | #endif 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/self2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * self2.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Test for pthread_self(). 37 | * 38 | * Depends on API functions: 39 | * pthread_create() 40 | * pthread_self() 41 | * 42 | * Implicitly depends on: 43 | * pthread_getspecific() 44 | * pthread_setspecific() 45 | */ 46 | 47 | #include "test.h" 48 | #include 49 | 50 | static pthread_t me; 51 | 52 | void * 53 | entry(void * arg) 54 | { 55 | me = pthread_self(); 56 | 57 | return arg; 58 | } 59 | 60 | int 61 | main() 62 | { 63 | pthread_t t; 64 | 65 | assert(pthread_create(&t, NULL, entry, NULL) == 0); 66 | 67 | Sleep(100); 68 | 69 | assert(pthread_equal(t, me) != 0); 70 | 71 | /* Success. */ 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/sizes.c: -------------------------------------------------------------------------------- 1 | #define _WIN32_WINNT 0x400 2 | 3 | #include "test.h" 4 | #include "../implement.h" 5 | 6 | int 7 | main() 8 | { 9 | printf("Sizes of pthreads-win32 structs\n"); 10 | printf("-------------------------------\n"); 11 | printf("%30s %4d\n", "pthread_t", (int)sizeof(pthread_t)); 12 | printf("%30s %4d\n", "ptw32_thread_t", (int)sizeof(ptw32_thread_t)); 13 | printf("%30s %4d\n", "pthread_attr_t_", (int)sizeof(struct pthread_attr_t_)); 14 | printf("%30s %4d\n", "sem_t_", (int)sizeof(struct sem_t_)); 15 | printf("%30s %4d\n", "pthread_mutex_t_", (int)sizeof(struct pthread_mutex_t_)); 16 | printf("%30s %4d\n", "pthread_mutexattr_t_", (int)sizeof(struct pthread_mutexattr_t_)); 17 | printf("%30s %4d\n", "pthread_spinlock_t_", (int)sizeof(struct pthread_spinlock_t_)); 18 | printf("%30s %4d\n", "pthread_barrier_t_", (int)sizeof(struct pthread_barrier_t_)); 19 | printf("%30s %4d\n", "pthread_barrierattr_t_", (int)sizeof(struct pthread_barrierattr_t_)); 20 | printf("%30s %4d\n", "pthread_key_t_", (int)sizeof(struct pthread_key_t_)); 21 | printf("%30s %4d\n", "pthread_cond_t_", (int)sizeof(struct pthread_cond_t_)); 22 | printf("%30s %4d\n", "pthread_condattr_t_", (int)sizeof(struct pthread_condattr_t_)); 23 | printf("%30s %4d\n", "pthread_rwlock_t_", (int)sizeof(struct pthread_rwlock_t_)); 24 | printf("%30s %4d\n", "pthread_rwlockattr_t_", (int)sizeof(struct pthread_rwlockattr_t_)); 25 | printf("%30s %4d\n", "pthread_once_t_", (int)sizeof(struct pthread_once_t_)); 26 | printf("%30s %4d\n", "ptw32_cleanup_t", (int)sizeof(struct ptw32_cleanup_t)); 27 | printf("%30s %4d\n", "ptw32_mcs_node_t_", (int)sizeof(struct ptw32_mcs_node_t_)); 28 | printf("%30s %4d\n", "sched_param", (int)sizeof(struct sched_param)); 29 | printf("-------------------------------\n"); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/spin1.c: -------------------------------------------------------------------------------- 1 | /* 2 | * spin1.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Create a simple spinlock object, lock it, and then unlock it again. 37 | * This is the simplest test of the pthread mutex family that we can do. 38 | * 39 | */ 40 | 41 | #include "test.h" 42 | 43 | pthread_spinlock_t lock; 44 | 45 | int 46 | main() 47 | { 48 | assert(pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE) == 0); 49 | 50 | assert(pthread_spin_lock(&lock) == 0); 51 | 52 | assert(pthread_spin_unlock(&lock) == 0); 53 | 54 | assert(pthread_spin_destroy(&lock) == 0); 55 | 56 | assert(pthread_spin_lock(&lock) == EINVAL); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tests/spin2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * spin2.c 3 | * 4 | * 5 | * -------------------------------------------------------------------------- 6 | * 7 | * Pthreads-win32 - POSIX Threads Library for Win32 8 | * Copyright(C) 1998 John E. Bossom 9 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 10 | * 11 | * Contact Email: rpj@callisto.canberra.edu.au 12 | * 13 | * The current list of contributors is contained 14 | * in the file CONTRIBUTORS included with the source 15 | * code distribution. The list can also be seen at the 16 | * following World Wide Web location: 17 | * http://sources.redhat.com/pthreads-win32/contributors.html 18 | * 19 | * This library is free software; you can redistribute it and/or 20 | * modify it under the terms of the GNU Lesser General Public 21 | * License as published by the Free Software Foundation; either 22 | * version 2 of the License, or (at your option) any later version. 23 | * 24 | * This library is distributed in the hope that it will be useful, 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 | * Lesser General Public License for more details. 28 | * 29 | * You should have received a copy of the GNU Lesser General Public 30 | * License along with this library in the file COPYING.LIB; 31 | * if not, write to the Free Software Foundation, Inc., 32 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 33 | * 34 | * -------------------------------------------------------------------------- 35 | * 36 | * Declare a spinlock object, lock it, trylock it, 37 | * and then unlock it again. 38 | * 39 | */ 40 | 41 | #include "test.h" 42 | 43 | pthread_spinlock_t lock = NULL; 44 | 45 | static int washere = 0; 46 | 47 | void * func(void * arg) 48 | { 49 | assert(pthread_spin_trylock(&lock) == EBUSY); 50 | 51 | washere = 1; 52 | 53 | return 0; 54 | } 55 | 56 | int 57 | main() 58 | { 59 | pthread_t t; 60 | 61 | assert(pthread_spin_init(&lock, PTHREAD_PROCESS_PRIVATE) == 0); 62 | 63 | assert(pthread_spin_lock(&lock) == 0); 64 | 65 | assert(pthread_create(&t, NULL, func, NULL) == 0); 66 | assert(pthread_join(t, NULL) == 0); 67 | 68 | assert(pthread_spin_unlock(&lock) == 0); 69 | 70 | assert(pthread_spin_destroy(&lock) == 0); 71 | 72 | assert(washere == 1); 73 | 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /compat/win32/pthreads/tsd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tsd.c 3 | * 4 | * Description: 5 | * POSIX thread functions which implement thread-specific data (TSD). 6 | * 7 | * -------------------------------------------------------------------------- 8 | * 9 | * Pthreads-win32 - POSIX Threads Library for Win32 10 | * Copyright(C) 1998 John E. Bossom 11 | * Copyright(C) 1999,2005 Pthreads-win32 contributors 12 | * 13 | * Contact Email: rpj@callisto.canberra.edu.au 14 | * 15 | * The current list of contributors is contained 16 | * in the file CONTRIBUTORS included with the source 17 | * code distribution. The list can also be seen at the 18 | * following World Wide Web location: 19 | * http://sources.redhat.com/pthreads-win32/contributors.html 20 | * 21 | * This library is free software; you can redistribute it and/or 22 | * modify it under the terms of the GNU Lesser General Public 23 | * License as published by the Free Software Foundation; either 24 | * version 2 of the License, or (at your option) any later version. 25 | * 26 | * This library is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 29 | * Lesser General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU Lesser General Public 32 | * License along with this library in the file COPYING.LIB; 33 | * if not, write to the Free Software Foundation, Inc., 34 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 35 | */ 36 | 37 | #include "pthread.h" 38 | #include "implement.h" 39 | 40 | 41 | #include "pthread_key_create.c" 42 | #include "pthread_key_delete.c" 43 | #include "pthread_setspecific.c" 44 | #include "pthread_getspecific.c" 45 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/LICENSE: -------------------------------------------------------------------------------- 1 | QuickJS Javascript Engine 2 | 3 | Copyright (c) 2017-2021 Fabrice Bellard 4 | Copyright (c) 2017-2021 Charlie Gordon 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/VERSION: -------------------------------------------------------------------------------- 1 | 2021-03-27 2 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/examples/fib.c: -------------------------------------------------------------------------------- 1 | /* 2 | * QuickJS: Example of C module 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | #include "../quickjs.h" 25 | 26 | #define countof(x) (sizeof(x) / sizeof((x)[0])) 27 | 28 | static int fib(int n) 29 | { 30 | if (n <= 0) 31 | return 0; 32 | else if (n == 1) 33 | return 1; 34 | else 35 | return fib(n - 1) + fib(n - 2); 36 | } 37 | 38 | static JSValue js_fib(JSContext *ctx, JSValueConst this_val, 39 | int argc, JSValueConst *argv) 40 | { 41 | int n, res; 42 | if (JS_ToInt32(ctx, &n, argv[0])) 43 | return JS_EXCEPTION; 44 | res = fib(n); 45 | return JS_NewInt32(ctx, res); 46 | } 47 | 48 | static const JSCFunctionListEntry js_fib_funcs[] = { 49 | JS_CFUNC_DEF("fib", 1, js_fib ), 50 | }; 51 | 52 | static int js_fib_init(JSContext *ctx, JSModuleDef *m) 53 | { 54 | return JS_SetModuleExportList(ctx, m, js_fib_funcs, 55 | countof(js_fib_funcs)); 56 | } 57 | 58 | #ifdef JS_SHARED_LIBRARY 59 | #define JS_INIT_MODULE js_init_module 60 | #else 61 | #define JS_INIT_MODULE js_init_module_fib 62 | #endif 63 | 64 | JSModuleDef *JS_INIT_MODULE(JSContext *ctx, const char *module_name) 65 | { 66 | JSModuleDef *m; 67 | m = JS_NewCModule(ctx, module_name, js_fib_init); 68 | if (!m) 69 | return NULL; 70 | JS_AddModuleExportList(ctx, m, js_fib_funcs, countof(js_fib_funcs)); 71 | return m; 72 | } 73 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/examples/fib_module.js: -------------------------------------------------------------------------------- 1 | /* fib module */ 2 | export function fib(n) 3 | { 4 | if (n <= 0) 5 | return 0; 6 | else if (n == 1) 7 | return 1; 8 | else 9 | return fib(n - 1) + fib(n - 2); 10 | } 11 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/examples/hello.js: -------------------------------------------------------------------------------- 1 | console.log("Hello World"); 2 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/examples/hello_module.js: -------------------------------------------------------------------------------- 1 | /* example of JS module */ 2 | 3 | import { fib } from "./fib_module.js"; 4 | 5 | console.log("Hello World"); 6 | console.log("fib(10)=", fib(10)); 7 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/examples/pi_bigdecimal.js: -------------------------------------------------------------------------------- 1 | /* 2 | * PI computation in Javascript using the QuickJS bigdecimal type 3 | * (decimal floating point) 4 | */ 5 | "use strict"; 6 | 7 | /* compute PI with a precision of 'prec' digits */ 8 | function calc_pi(prec) { 9 | const CHUD_A = 13591409m; 10 | const CHUD_B = 545140134m; 11 | const CHUD_C = 640320m; 12 | const CHUD_C3 = 10939058860032000m; /* C^3/24 */ 13 | const CHUD_DIGITS_PER_TERM = 14.18164746272548; /* log10(C/12)*3 */ 14 | 15 | /* return [P, Q, G] */ 16 | function chud_bs(a, b, need_G) { 17 | var c, P, Q, G, P1, Q1, G1, P2, Q2, G2, b1; 18 | if (a == (b - 1n)) { 19 | b1 = BigDecimal(b); 20 | G = (2m * b1 - 1m) * (6m * b1 - 1m) * (6m * b1 - 5m); 21 | P = G * (CHUD_B * b1 + CHUD_A); 22 | if (b & 1n) 23 | P = -P; 24 | G = G; 25 | Q = b1 * b1 * b1 * CHUD_C3; 26 | } else { 27 | c = (a + b) >> 1n; 28 | [P1, Q1, G1] = chud_bs(a, c, true); 29 | [P2, Q2, G2] = chud_bs(c, b, need_G); 30 | P = P1 * Q2 + P2 * G1; 31 | Q = Q1 * Q2; 32 | if (need_G) 33 | G = G1 * G2; 34 | else 35 | G = 0m; 36 | } 37 | return [P, Q, G]; 38 | } 39 | 40 | var n, P, Q, G; 41 | /* number of serie terms */ 42 | n = BigInt(Math.ceil(prec / CHUD_DIGITS_PER_TERM)) + 10n; 43 | [P, Q, G] = chud_bs(0n, n, false); 44 | Q = BigDecimal.div(Q, (P + Q * CHUD_A), 45 | { roundingMode: "half-even", 46 | maximumSignificantDigits: prec }); 47 | G = (CHUD_C / 12m) * BigDecimal.sqrt(CHUD_C, 48 | { roundingMode: "half-even", 49 | maximumSignificantDigits: prec }); 50 | return Q * G; 51 | } 52 | 53 | (function() { 54 | var r, n_digits, n_bits; 55 | if (typeof scriptArgs != "undefined") { 56 | if (scriptArgs.length < 2) { 57 | print("usage: pi n_digits"); 58 | return; 59 | } 60 | n_digits = scriptArgs[1] | 0; 61 | } else { 62 | n_digits = 1000; 63 | } 64 | /* we add more digits to reduce the probability of bad rounding for 65 | the last digits */ 66 | r = calc_pi(n_digits + 20); 67 | print(r.toFixed(n_digits, "down")); 68 | })(); 69 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/examples/pi_bigfloat.js: -------------------------------------------------------------------------------- 1 | /* 2 | * PI computation in Javascript using the QuickJS bigfloat type 3 | * (binary floating point) 4 | */ 5 | "use strict"; 6 | 7 | /* compute PI with a precision of 'prec' bits */ 8 | function calc_pi() { 9 | const CHUD_A = 13591409n; 10 | const CHUD_B = 545140134n; 11 | const CHUD_C = 640320n; 12 | const CHUD_C3 = 10939058860032000n; /* C^3/24 */ 13 | const CHUD_BITS_PER_TERM = 47.11041313821584202247; /* log2(C/12)*3 */ 14 | 15 | /* return [P, Q, G] */ 16 | function chud_bs(a, b, need_G) { 17 | var c, P, Q, G, P1, Q1, G1, P2, Q2, G2; 18 | if (a == (b - 1n)) { 19 | G = (2n * b - 1n) * (6n * b - 1n) * (6n * b - 5n); 20 | P = BigFloat(G * (CHUD_B * b + CHUD_A)); 21 | if (b & 1n) 22 | P = -P; 23 | G = BigFloat(G); 24 | Q = BigFloat(b * b * b * CHUD_C3); 25 | } else { 26 | c = (a + b) >> 1n; 27 | [P1, Q1, G1] = chud_bs(a, c, true); 28 | [P2, Q2, G2] = chud_bs(c, b, need_G); 29 | P = P1 * Q2 + P2 * G1; 30 | Q = Q1 * Q2; 31 | if (need_G) 32 | G = G1 * G2; 33 | else 34 | G = 0l; 35 | } 36 | return [P, Q, G]; 37 | } 38 | 39 | var n, P, Q, G; 40 | /* number of serie terms */ 41 | n = BigInt(Math.ceil(BigFloatEnv.prec / CHUD_BITS_PER_TERM)) + 10n; 42 | [P, Q, G] = chud_bs(0n, n, false); 43 | Q = Q / (P + Q * BigFloat(CHUD_A)); 44 | G = BigFloat((CHUD_C / 12n)) * BigFloat.sqrt(BigFloat(CHUD_C)); 45 | return Q * G; 46 | } 47 | 48 | (function() { 49 | var r, n_digits, n_bits; 50 | if (typeof scriptArgs != "undefined") { 51 | if (scriptArgs.length < 2) { 52 | print("usage: pi n_digits"); 53 | return; 54 | } 55 | n_digits = scriptArgs[1]; 56 | } else { 57 | n_digits = 1000; 58 | } 59 | n_bits = Math.ceil(n_digits * Math.log2(10)); 60 | /* we add more bits to reduce the probability of bad rounding for 61 | the last digits */ 62 | BigFloatEnv.setPrec( () => { 63 | r = calc_pi(); 64 | print(r.toFixed(n_digits, BigFloatEnv.RNDZ)); 65 | }, n_bits + 32); 66 | })(); 67 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/examples/test_fib.js: -------------------------------------------------------------------------------- 1 | /* example of JS module importing a C module */ 2 | 3 | import { fib } from "./fib.so"; 4 | 5 | console.log("Hello World"); 6 | console.log("fib(10)=", fib(10)); 7 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/examples/test_point.js: -------------------------------------------------------------------------------- 1 | /* example of JS module importing a C module */ 2 | import { Point } from "./point.so"; 3 | 4 | function assert(b, str) 5 | { 6 | if (b) { 7 | return; 8 | } else { 9 | throw Error("assertion failed: " + str); 10 | } 11 | } 12 | 13 | class ColorPoint extends Point { 14 | constructor(x, y, color) { 15 | super(x, y); 16 | this.color = color; 17 | } 18 | get_color() { 19 | return this.color; 20 | } 21 | }; 22 | 23 | function main() 24 | { 25 | var pt, pt2; 26 | 27 | pt = new Point(2, 3); 28 | assert(pt.x === 2); 29 | assert(pt.y === 3); 30 | pt.x = 4; 31 | assert(pt.x === 4); 32 | assert(pt.norm() == 5); 33 | 34 | pt2 = new ColorPoint(2, 3, 0xffffff); 35 | assert(pt2.x === 2); 36 | assert(pt2.color === 0xffffff); 37 | assert(pt2.get_color() === 0xffffff); 38 | } 39 | 40 | main(); 41 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/libregexp-opcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Regular Expression Engine 3 | * 4 | * Copyright (c) 2017-2018 Fabrice Bellard 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | 25 | #ifdef DEF 26 | 27 | DEF(invalid, 1) /* never used */ 28 | DEF(char, 3) 29 | DEF(char32, 5) 30 | DEF(dot, 1) 31 | DEF(any, 1) /* same as dot but match any character including line terminator */ 32 | DEF(line_start, 1) 33 | DEF(line_end, 1) 34 | DEF(goto, 5) 35 | DEF(split_goto_first, 5) 36 | DEF(split_next_first, 5) 37 | DEF(match, 1) 38 | DEF(save_start, 2) /* save start position */ 39 | DEF(save_end, 2) /* save end position, must come after saved_start */ 40 | DEF(save_reset, 3) /* reset save positions */ 41 | DEF(loop, 5) /* decrement the top the stack and goto if != 0 */ 42 | DEF(push_i32, 5) /* push integer on the stack */ 43 | DEF(drop, 1) 44 | DEF(word_boundary, 1) 45 | DEF(not_word_boundary, 1) 46 | DEF(back_reference, 2) 47 | DEF(backward_back_reference, 2) /* must come after back_reference */ 48 | DEF(range, 3) /* variable length */ 49 | DEF(range32, 3) /* variable length */ 50 | DEF(lookahead, 5) 51 | DEF(negative_lookahead, 5) 52 | DEF(push_char_pos, 1) /* push the character position on the stack */ 53 | DEF(bne_char_pos, 5) /* pop one stack element and jump if equal to the character 54 | position */ 55 | DEF(prev, 1) /* go to the previous char */ 56 | DEF(simple_greedy_quant, 17) 57 | 58 | #endif /* DEF */ 59 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/readme.txt: -------------------------------------------------------------------------------- 1 | The main documentation is in doc/quickjs.pdf or doc/quickjs.html. 2 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/test262o_errors.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openkraken/node-qjsc/4a4c50574d164a99a787905db4bbea0770c453ef/deps/quickjs_2021_03_27/test262o_errors.txt -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/tests/test262.patch: -------------------------------------------------------------------------------- 1 | diff --git a/harness/atomicsHelper.js b/harness/atomicsHelper.js 2 | index 9c1217351e..3c24755558 100644 3 | --- a/harness/atomicsHelper.js 4 | +++ b/harness/atomicsHelper.js 5 | @@ -227,10 +227,14 @@ $262.agent.waitUntil = function(typedArray, index, expected) { 6 | * } 7 | */ 8 | $262.agent.timeouts = { 9 | - yield: 100, 10 | - small: 200, 11 | - long: 1000, 12 | - huge: 10000, 13 | +// yield: 100, 14 | +// small: 200, 15 | +// long: 1000, 16 | +// huge: 10000, 17 | + yield: 20, 18 | + small: 20, 19 | + long: 100, 20 | + huge: 1000, 21 | }; 22 | 23 | /** 24 | diff --git a/harness/regExpUtils.js b/harness/regExpUtils.js 25 | index be7039fda0..7b38abf8df 100644 26 | --- a/harness/regExpUtils.js 27 | +++ b/harness/regExpUtils.js 28 | @@ -6,24 +6,27 @@ description: | 29 | defines: [buildString, testPropertyEscapes, matchValidator] 30 | ---*/ 31 | 32 | +if ($262 && typeof $262.codePointRange === "function") { 33 | + /* use C function to build the codePointRange (much faster with 34 | + slow JS engines) */ 35 | + codePointRange = $262.codePointRange; 36 | +} else { 37 | + codePointRange = function codePointRange(start, end) { 38 | + const codePoints = []; 39 | + let length = 0; 40 | + for (codePoint = start; codePoint < end; codePoint++) { 41 | + codePoints[length++] = codePoint; 42 | + } 43 | + return String.fromCodePoint.apply(null, codePoints); 44 | + } 45 | +} 46 | + 47 | function buildString({ loneCodePoints, ranges }) { 48 | - const CHUNK_SIZE = 10000; 49 | - let result = Reflect.apply(String.fromCodePoint, null, loneCodePoints); 50 | - for (let i = 0; i < ranges.length; i++) { 51 | - const range = ranges[i]; 52 | - const start = range[0]; 53 | - const end = range[1]; 54 | - const codePoints = []; 55 | - for (let length = 0, codePoint = start; codePoint <= end; codePoint++) { 56 | - codePoints[length++] = codePoint; 57 | - if (length === CHUNK_SIZE) { 58 | - result += Reflect.apply(String.fromCodePoint, null, codePoints); 59 | - codePoints.length = length = 0; 60 | - } 61 | + let result = String.fromCodePoint.apply(null, loneCodePoints); 62 | + for (const [start, end] of ranges) { 63 | + result += codePointRange(start, end + 1); 64 | } 65 | - result += Reflect.apply(String.fromCodePoint, null, codePoints); 66 | - } 67 | - return result; 68 | + return result; 69 | } 70 | 71 | function testPropertyEscapes(regex, string, expression) { 72 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/tests/test_worker.js: -------------------------------------------------------------------------------- 1 | /* os.Worker API test */ 2 | import * as std from "std"; 3 | import * as os from "os"; 4 | 5 | function assert(actual, expected, message) { 6 | if (arguments.length == 1) 7 | expected = true; 8 | 9 | if (actual === expected) 10 | return; 11 | 12 | if (actual !== null && expected !== null 13 | && typeof actual == 'object' && typeof expected == 'object' 14 | && actual.toString() === expected.toString()) 15 | return; 16 | 17 | throw Error("assertion failed: got |" + actual + "|" + 18 | ", expected |" + expected + "|" + 19 | (message ? " (" + message + ")" : "")); 20 | } 21 | 22 | var worker; 23 | 24 | function test_worker() 25 | { 26 | var counter; 27 | 28 | worker = new os.Worker("./test_worker_module.js"); 29 | 30 | counter = 0; 31 | worker.onmessage = function (e) { 32 | var ev = e.data; 33 | // print("recv", JSON.stringify(ev)); 34 | switch(ev.type) { 35 | case "num": 36 | assert(ev.num, counter); 37 | counter++; 38 | if (counter == 10) { 39 | /* test SharedArrayBuffer modification */ 40 | let sab = new SharedArrayBuffer(10); 41 | let buf = new Uint8Array(sab); 42 | worker.postMessage({ type: "sab", buf: buf }); 43 | } 44 | break; 45 | case "sab_done": 46 | { 47 | let buf = ev.buf; 48 | /* check that the SharedArrayBuffer was modified */ 49 | assert(buf[2], 10); 50 | worker.postMessage({ type: "abort" }); 51 | } 52 | break; 53 | case "done": 54 | /* terminate */ 55 | worker.onmessage = null; 56 | break; 57 | } 58 | }; 59 | } 60 | 61 | 62 | test_worker(); 63 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/tests/test_worker_module.js: -------------------------------------------------------------------------------- 1 | /* Worker code for test_worker.js */ 2 | import * as std from "std"; 3 | import * as os from "os"; 4 | 5 | var parent = os.Worker.parent; 6 | 7 | function handle_msg(e) { 8 | var ev = e.data; 9 | // print("child_recv", JSON.stringify(ev)); 10 | switch(ev.type) { 11 | case "abort": 12 | parent.postMessage({ type: "done" }); 13 | break; 14 | case "sab": 15 | /* modify the SharedArrayBuffer */ 16 | ev.buf[2] = 10; 17 | parent.postMessage({ type: "sab_done", buf: ev.buf }); 18 | break; 19 | } 20 | } 21 | 22 | function worker_main() { 23 | var i; 24 | 25 | parent.onmessage = handle_msg; 26 | for(i = 0; i < 10; i++) { 27 | parent.postMessage({ type: "num", num: i }); 28 | } 29 | } 30 | 31 | worker_main(); 32 | -------------------------------------------------------------------------------- /deps/quickjs_2021_03_27/unicode_download.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | url="ftp://ftp.unicode.org/Public/13.0.0/ucd" 5 | emoji_url="${url}/emoji/emoji-data.txt" 6 | 7 | files="CaseFolding.txt DerivedNormalizationProps.txt PropList.txt \ 8 | SpecialCasing.txt CompositionExclusions.txt ScriptExtensions.txt \ 9 | UnicodeData.txt DerivedCoreProperties.txt NormalizationTest.txt Scripts.txt \ 10 | PropertyValueAliases.txt" 11 | 12 | mkdir -p unicode 13 | 14 | #for f in $files; do 15 | # g="${url}/${f}" 16 | # wget $g -O unicode/$f 17 | #done 18 | 19 | wget $emoji_url -O unicode/emoji-data.txt 20 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const supportedVersions = ['20210327']; 2 | 3 | class Qjsc { 4 | constructor(options = {}) { 5 | let version = options.version || '20210327'; 6 | if (supportedVersions.indexOf(version) === -1) { 7 | throw new Error('Unsupported QuickJS version: ' + version); 8 | } 9 | // TODO: Multiple quickjs version switch are removed because of prebuilt library. 10 | this._bindings = require('node-gyp-build')(__dirname); 11 | } 12 | help() { 13 | console.log('Supported QuckJS versions: ' + supportedVersions.join(', ')); 14 | } 15 | 16 | getSupportedVersions() { 17 | return supportedVersions; 18 | } 19 | 20 | compile(code, options = {}) { 21 | let sourceURL = options.sourceURL || 'internal://'; 22 | return this._bindings.dumpByteCode(code, sourceURL); 23 | } 24 | 25 | get version() { 26 | return this._bindings.version; 27 | } 28 | 29 | _evalByteCode(buffer) { 30 | return this._bindings.evalByteCode(buffer); 31 | } 32 | } 33 | 34 | module.exports = Qjsc; 35 | -------------------------------------------------------------------------------- /install.js: -------------------------------------------------------------------------------- 1 | // To compact with `npm install --no-bin-links`. We avoid to use `node-gyp-build` because it will failed caused by child_process. 2 | 3 | const tryLoadPreBuilt = require('node-gyp-build'); 4 | const proc = require('child_process') 5 | const os = require('os') 6 | const path = require('path') 7 | 8 | try { 9 | if (!buildFromSource()) { 10 | tryLoadPreBuilt(__dirname); 11 | } else { 12 | preinstall(); 13 | } 14 | } catch (e) { 15 | preinstall(); 16 | } 17 | 18 | function build () { 19 | var args = [os.platform() === 'win32' ? 'node-gyp.cmd' : 'node-gyp', 'rebuild'] 20 | 21 | try { 22 | args = [ 23 | process.execPath, 24 | path.join(require.resolve('node-gyp/package.json'), '..', require('node-gyp/package.json').bin['node-gyp']), 25 | 'rebuild' 26 | ] 27 | } catch (_) {} 28 | 29 | proc.spawn(args[0], args.slice(1), { stdio: 'inherit' }).on('exit', function (code) { 30 | if (code || !process.argv[3]) process.exit(code) 31 | exec(process.argv[3]).on('exit', function (code) { 32 | process.exit(code) 33 | }) 34 | }) 35 | } 36 | 37 | function preinstall () { 38 | if (!process.argv[2]) return build() 39 | exec(process.argv[2]).on('exit', function (code) { 40 | if (code) process.exit(code) 41 | build() 42 | }) 43 | } 44 | 45 | function exec (cmd) { 46 | if (process.platform !== 'win32') { 47 | var shell = os.platform() === 'android' ? 'sh' : '/bin/sh' 48 | return proc.spawn(shell, ['-c', '--', cmd], { 49 | stdio: 'inherit' 50 | }) 51 | } 52 | 53 | return proc.spawn(process.env.comspec || 'cmd.exe', ['/s', '/c', '"' + cmd + '"'], { 54 | windowsVerbatimArguments: true, 55 | stdio: 'inherit' 56 | }) 57 | } 58 | 59 | function buildFromSource () { 60 | return hasFlag('--build-from-source') || process.env.npm_config_build_from_source === 'true' 61 | } 62 | 63 | function verbose () { 64 | return hasFlag('--verbose') || process.env.npm_config_loglevel === 'verbose' 65 | } 66 | 67 | // TODO (next major): remove in favor of env.npm_config_* which works since npm 68 | // 0.1.8 while npm_config_argv will stop working in npm 7. See npm/rfcs#90 69 | function hasFlag (flag) { 70 | if (!process.env.npm_config_argv) return false 71 | 72 | try { 73 | return JSON.parse(process.env.npm_config_argv).original.indexOf(flag) !== -1 74 | } catch (_) { 75 | return false 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "qjsc", 3 | "version": "0.3.0", 4 | "description": "Node.js addon for the Quickjs compiler", 5 | "main": "index.js", 6 | "bin": { 7 | "qjsc": "./bin/qjsc.js" 8 | }, 9 | "scripts": { 10 | "install": "node install.js", 11 | "test": "jasmine test.js", 12 | "build": "node-gyp rebuild --verbose", 13 | "build:pre": "prebuildify --napi" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/openkraken/node-qjsc.git" 18 | }, 19 | "author": "The Kraken Team", 20 | "license": "Apache License 2.0", 21 | "bugs": { 22 | "url": "https://github.com/openkraken/node-qjsc/issues" 23 | }, 24 | "homepage": "https://github.com/openkraken/node-qjsc#readme", 25 | "dependencies": { 26 | "bindings": "^1.5.0", 27 | "commander": "^8.2.0", 28 | "nan": "^2.15.0", 29 | "node-addon-api": "^4.1.0", 30 | "node-gyp": "^9.0.0", 31 | "node-gyp-build": "^4.3.0" 32 | }, 33 | "engines": { 34 | "node": ">=12" 35 | }, 36 | "devDependencies": { 37 | "jasmine": "^3.9.0", 38 | "prebuildify": "^5.0.0" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /prebuilds/darwin-arm64/node.napi.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openkraken/node-qjsc/4a4c50574d164a99a787905db4bbea0770c453ef/prebuilds/darwin-arm64/node.napi.node -------------------------------------------------------------------------------- /prebuilds/darwin-x64/node.napi.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openkraken/node-qjsc/4a4c50574d164a99a787905db4bbea0770c453ef/prebuilds/darwin-x64/node.napi.node -------------------------------------------------------------------------------- /prebuilds/linux-x64/node.napi.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openkraken/node-qjsc/4a4c50574d164a99a787905db4bbea0770c453ef/prebuilds/linux-x64/node.napi.node -------------------------------------------------------------------------------- /prebuilds/win32-x64/node.napi.node: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openkraken/node-qjsc/4a4c50574d164a99a787905db4bbea0770c453ef/prebuilds/win32-x64/node.napi.node -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | const Qjsc = require('./index'); 2 | 3 | const qjsc = new Qjsc(); 4 | 5 | describe('qjsc', () => { 6 | it('throw error when empty arguments', () => { 7 | expect(() => qjsc.compile()).toThrowError('1st arguments should be string.'); 8 | }); 9 | 10 | it('throw error when js syntax not correct', () => { 11 | const code = ` 12 | function f() { 13 | 14 | console.log(111; 15 | 16 | `; 17 | expect(() => qjsc.compile(code)).toThrowError(); 18 | }); 19 | 20 | it('return bytecode binary', () => { 21 | const code = ` 22 | function f() { return 1 + '1234'; } 23 | f(); 24 | `; 25 | let buffer = qjsc.compile(code); 26 | expect(qjsc._evalByteCode(buffer)).toBe('11234'); 27 | }); 28 | 29 | it('support 20210327', () => { 30 | expect(qjsc.version).toBe('20210327'); 31 | }); 32 | 33 | it('get all supported version', () => { 34 | expect(qjsc.getSupportedVersions()).toEqual(['20210327']); 35 | }); 36 | }); 37 | --------------------------------------------------------------------------------