summaryrefslogtreecommitdiff
path: root/otherlibs/systhreads/st_win32.h
Commit message (Collapse)AuthorAgeFilesLines
* Fix the tick thread on WindowsDavid Allsopp2022-03-221-0/+5
| | | | | The Windows implementation of select doesn't support all three fdsets being empty. Call Sleep directly instead.
* Share pthreads code more explicitly in systhreadsDavid Allsopp2022-03-221-2/+15
| | | | Keep Win32 and Posix-specific functions in st_posix.h and st_win32.h
* Implement systhreads via winpthreads for nowDavid Allsopp2021-12-231-0/+23
|
* first dec importEnguerrand Decorne2020-07-301-434/+0
|
* Thread.yield fairness with multiple busy yielding threads (#2112)ahh2019-02-081-7/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Thread.yield invoked a trivial blocking section, which basically woke up a competitor and then raced with them to get the ocaml lock back, invoking nanosleep() to help guarantee that the yielder would lose the race. However, until the yielder woke up again and attempted to take the ocaml lock, it wouldn't be marked as a waiter. As a result, if two threads A and B yielded to each other in a tight loop, A's first yield would work well, but then B would execute 10000+ iterations of the loop before A could mark itself as a waiter and be yielded to. This works even worse if A and B are pinned to the same CPU, in which case A can't be marked as a waiter until the kernel preempts B, which can take tens or hundreds of milliseconds! So we reimplement yield; instead of dropping the lock and taking it again (with a wait in the middle), atomically wake a competitor and mark the yielding thread as a waiter. (We essentially inline a failed masterlock_acquire into masterlock_release, specialized for the case where we know another waiter exists and we want them to run instead.) Now, threads yielding to each other very consistently succeed--in that same tight loop, we see a change of control on every iteration (with some very rare exceptions, most likely from other uncommon blocking region invocations.) This also means we don't have to worry about the vagaries of kernel scheduling and whether or not a yielding or a yielded-to thread gets to run first; we consistently let a competing thread run whenever we yield, which is what the API claims to do.
* Whitespace and overlong line fixes.David Allsopp2018-06-141-1/+2
|
* Cleaning up the C code (#1812)Xavier Leroy2018-06-071-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Running Clang 6.0 and GCC 8 with full warnings on suggests a few simple improvements and clean-ups to the C code of OCaml. This commit implements them. * Remove old-style, unprototyped function declarations It's `int f(void)`, not `int f()`. [-Wstrict-prototypes] * Be more explicit about conversions involving `float` and `double` byterun/bigarray.c, byterun/ints.c: add explicit casts to clarify the intent renamed float field of conversion union from `d` to `f`. byterun/compact.c, byterun/gc_ctrl.c: some local variables were of type `float` while all FP computations here are done in double precision; turned these variables into `double`. [-Wdouble-promotion -Wfloat-conversion] *Add explicit initialization of struct field `compare_ext` [-Wmissing-field-initializers] * Declare more functions "noreturn" [-Wmissing-noreturn] * Make CAMLassert compliant with ISO C In `e1 ? e2 : e3`, expressions `e2` and `e3` must have the same type. `e2` of type `void` and `e3` of type `int`, as in the original code, is a GNU extension. * Remove or conditionalize unused macros Some macros were defined and never used. Some other macros were always defined but conditionally used. [-Wunused-macros] * Replace some uses of `int` by more appropriate types like `intnat` On a 64-bit platform, `int` is only 32 bits and may not represent correctly the length of a string or the size of an OCaml heap block. This commit replaces a number of uses of `int` by other types that are 64-bit wide on 64-bit architectures, such as `intnat` or `uintnat` or `size_t` or `mlsize_t`. Sometimes an `intnat` was used as an `int` and is intended as a Boolean (0 or 1); then it was replaced by an `int`. There are many remaining cases where we assign a 64-bit quantity to a 32-bit `int` variable. Either I believe these cases are safe (e.g. the 64-bit quantity is the difference between two pointers within an I/O buffer, something that always fits in 32 bits), or the code change was not obvious and too risky. [-Wshorten-64-to-32] * Put `inline` before return type `static inline void f(void)` is cleaner than `static void inline f(void)`. [-Wold-style-declaration] * Unused assignment to unused parameter Looks very useless. [-Wunused-but-set-parameter]
* Unicode support for the Windows runtime (#1200)Nicolás Ojeda Bär2017-09-181-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add support code * Explicitly reference ANSI Windows APIs * Adapt Sys.is_directory * Adapt ocamlrun * Add Changes entry * Add testsuite * Adapt Unix.open_process{_in,_out,_full,}, Unix.create_process{_env,} * Adapt headernt.c * Adapt Pervasives.open_{in,out}, Filename.temp_file, etc. * Adapt Sys.file_exists * Adapt Sys.remove * Adapt Sys.chdir * Adapt Sys.getcwd * Adapt Sys.getenv * Adapt Sys.command * Adapt Sys.readdir * Adapt CPLUGINS * Remove use of FormatMessageA, CreateFileA * Adapt Unix.mkdir * Adapt Unix.openfile * Adapt Unix.readlink * Adapt Unix.rename * Adapt Unix.{LargeFile,}.{l,}stat * Adapt Unix.system * Adapt Unix.{open,read}dir * Adapt Unix.link * Adapt Unix.symlink * Adapt Unix.getcwd * Adapt Unix.rmdir * Adapt Unix.utimes * Adapt Unix.unlink * Adapt Unix.chdir * Adapt Unix.chmod * Adapt Unix.{execv,execve,execvp,execvpe} * Compile with -DUNICODE -D_UNICODE under Windows * Add configure-time switch, Config.windows_unicode * Adapt Unix.putenv * Re-implement Unix.environment using GetEnvironmentStrings() * Use Unicode-aware flexdll * Adapt Unix.environment * AppVeyor: bootstrap flexdll * Adapt tests/embedded/cmmain.c * Adapt tests/lib-dynlink-csharp/entry.c * Remove exec tests * Fixup * Pass -municode to MinGW compiler * Try to fix tests/embedded * Adapt Sys.rename * Correct Changes entry * Makefile.several: use $(O) and $(NATIVECODE_ONLY) * Display => skipped correctly for tests/win-unicode * Add missing casts to execv* calls It's not clear why these aren't necessary for with char, but they are necessary with wchar_t on GCC (but not MSVC). * Missing header in systhreads (Win32 only) * Revert "Pass -municode to MinGW compiler" This reverts commit a4ce7fb319c429068a5b9d1ab14a2cc3969c355f. * Revert "Try to fix tests/embedded" This reverts commit 5197d8922295b7b339b970ec3189374aa15de4b8. * Revert "Remove exec tests" This reverts commit 306ccef2e79eca5b38ecfa285b912c7bcf3e9f52. * Don't pass $(LDFLAGS) when build ocamlc.opt It's already included via CC anyway, and it causes Unicode problems for Winodws (because the linker options need to be prefixed "-link" to go via flexlink). * Use wmain on Windows for ocamlrun * Build Unicode applications on Windows * Use wmain in headernt.c * Minor correction to win-unicode Makefile * Switch submodule to FlexDLL 0.36 * Build ocamlyacc as an ANSI application * Revert "Fixup" This reverts commit 500bd6b575ffd6c5b71c6953e55d740f0b090185. * Fix casts for execvp/execve * Remove tabs from test code * Fix Changes entry * shell32.lib is no longer necessary * Free allocated string * Changes: signal breaking change * Disable exec_tests * Protect with CAML_INTERNALS
* Fixed grammar in user-facing comments and READMEMax Mouratov2017-04-061-1/+1
|
* runtime: replacing direct calls to malloc/calloc/realloc/free with calls to ↵Max Mouratov2017-03-171-4/+4
| | | | | | | | caml_stat_* A few more wrappers were added (caml_stat_alloc_noexc, caml_stat_resize_noexc, caml_stat_calloc_noexc) that do not throw an exception in case of errors and offer a compatible substitute to the corresponding stdlib functions.
* Fix a couple of warnings in C code.Sébastien Hinderer2016-12-061-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes the list of warnings below. They have been obtained while compiling the MinGW port with gcc version 4.9.2. A few remarks are due: 1. Several warnings are about the _WIN32_WINNT macro. This commit gets rid of those warnings by #undef-ing the macro in those files that define it anyway. 2. In win32graph/draw.c, the function caml_gr_show_bitmap which causes a warning has been removed, because this (broken) code is actually not called by any other function. It turned out that all the functions defined in the win32graph/dib.c module are unused, too. This dib.c module has thus been removed completely. 3. The warnings about variables that might be used without having been previously initialised occur because the C compiler does not realise that unix_error never returns. So, fixing this warning does not require any modification of the source files where it occurs. It rather requires to declare that unix_error does not return on Windows, as is actually already done on Unix. List of fixed warnings : asmrun/clambda_checks.c: clambda_checks.c: In function ‘caml_check_field_access’: clambda_checks.c:62:7: warning: unknown conversion type character ‘l’ in format [-Wformat=] (ARCH_UINT64_TYPE) Long_val(pos), descr); ^ clambda_checks.c:62:7: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘long long unsigned int’ [-Wformat=] clambda_checks.c:62:7: warning: too many arguments for format [-Wformat-extra-args] clambda_checks.c:68:7: warning: unknown conversion type character ‘l’ in format [-Wformat=] (ARCH_UINT64_TYPE) Long_val(pos), (void*) v, descr); ^ clambda_checks.c:68:7: warning: format ‘%p’ expects argument of type ‘void *’, but argument 3 has type ‘long long unsigned int’ [-Wformat=] clambda_checks.c:68:7: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘void *’ [-Wformat=] clambda_checks.c:68:7: warning: too many arguments for format [-Wformat-extra-args] clambda_checks.c:82:7: warning: unknown conversion type character ‘l’ in format [-Wformat=] descr); ^ clambda_checks.c:82:7: warning: format ‘%p’ expects argument of type ‘void *’, but argument 3 has type ‘long long unsigned int’ [-Wformat=] clambda_checks.c:82:7: warning: unknown conversion type character ‘l’ in format [-Wformat=] clambda_checks.c:82:7: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘void *’ [-Wformat=] clambda_checks.c:82:7: warning: too many arguments for format [-Wformat-extra-args] otherlibs/win32unix/createprocess.c: createprocess.c: In function ‘win_create_process_native’: createprocess.c:66:5: warning: implicit declaration of function ‘caml_stat_free’ [-Wimplicit-function-declaration] caml_stat_free(exefile); ^ otherlibs/win32unix/select.c: In file included from select.c:21:0: winworker.h:19:0: warning: "_WIN32_WINNT" redefined #define _WIN32_WINNT 0x0400 ^ In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/crtdefs.h:10:0, from /usr/i686-w64-mingw32/sys-root/mingw/include/stdint.h:28, from /usr/lib/gcc/i686-w64-mingw32/4.9.2/include/stdint.h:9, from ../../byterun/caml/config.h:34, from ../../byterun/caml/mlvalues.h:22, from select.c:16: /usr/i686-w64-mingw32/sys-root/mingw/include/_mingw.h:225:0: note: this is the location of the previous definition #define _WIN32_WINNT 0x502 ^ select.c: In function ‘find_handle’: select.c:906:3: warning: enumeration value ‘SELECT_MODE_NONE’ not handled in switch [-Wswitch] switch( iterResult->EMode ) ^ select.c: In function ‘unix_select’: select.c:1267:19: warning: enumeration value ‘SELECT_MODE_NONE’ not handled in switch [-Wswitch] switch (iterResult->EMode) ^ otherlibs/win32unix/sockopt.c: sockopt.c: In function ‘unix_setsockopt_aux’: sockopt.c:200:7: warning: ‘optsize’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (setsockopt(Socket_val(socket), level, option, ^ otherlibs/win32unix/startup.cstartup.c: In file included from startup.c:20:0: winworker.h:19:0: warning: "_WIN32_WINNT" redefined #define _WIN32_WINNT 0x0400 ^ In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/crtdefs.h:10:0, from /usr/i686-w64-mingw32/sys-root/mingw/include/stdio.h:9, from startup.c:16: /usr/i686-w64-mingw32/sys-root/mingw/include/_mingw.h:225:0: note: this is the location of the previous definition #define _WIN32_WINNT 0x502 ^ otherlibs/win32unix/winworker.c In file included from winworker.c:20:0: winworker.h:19:0: warning: "_WIN32_WINNT" redefined #define _WIN32_WINNT 0x0400 ^ In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/crtdefs.h:10:0, from /usr/i686-w64-mingw32/sys-root/mingw/include/stdint.h:28, from /usr/lib/gcc/i686-w64-mingw32/4.9.2/include/stdint.h:9, from ../../byterun/caml/config.h:34, from ../../byterun/caml/mlvalues.h:22, from winworker.c:16: /usr/i686-w64-mingw32/sys-root/mingw/include/_mingw.h:225:0: note: this is the location of the previous definition #define _WIN32_WINNT 0x502 ^ otherlibs/unix/access.c: access.c:36:0: warning: "X_OK" redefined # define X_OK 4/* test for execute permission - not implemented in Win32 */ ^ In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/direct.h:10:0, from unixsupport.h:23, from access.c:20: /usr/i686-w64-mingw32/sys-root/mingw/include/io.h:174:0: note: this is the location of the previous definition #define X_OK 1 /* Check for execute permission. */ ^ otherlibs/unix/socketaddr.c: socketaddr.c: In function ‘alloc_sockaddr’: socketaddr.c:153:3: warning: ‘res’ may be used uninitialized in this function [-Wmaybe-uninitialized] return res; ^ otherlibs/win32graph/open.c: open.c: In function ‘caml_gr_open_graph’: open.c:270:18: warning: pointer targets in passing argument 6 of ‘CreateThread’ differ in signedness [-Wpointer-sign] &tid); ^ In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/winbase.h:29:0, from /usr/i686-w64-mingw32/sys-root/mingw/include/windows.h:70, from libgraph.h:17, from open.c:20: /usr/i686-w64-mingw32/sys-root/mingw/include/processthreadsapi.h:160:28: note: expected ‘LPDWORD’ but argument is of type ‘long int *’ WINBASEAPI HANDLE WINAPI CreateThread (LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter, DWORD dwCreationFlags, LPDWORD lpThreadId); ^ otherlibs/win32graph/draw.c: draw.c: In function ‘caml_gr_show_bitmap’: draw.c:309:9: warning: implicit declaration of function ‘AfficheBitmap’ [-Wimplicit-function-declaration] AfficheBitmap(filename,grwindow.gcBitmap,x,Wcvt(y)); ^ otherlibs/systhreads/st_stubs.c: In file included from st_stubs.c:50:0: st_win32.h:18:0: warning: "_WIN32_WINNT" redefined #define _WIN32_WINNT 0x0400 ^ In file included from /usr/i686-w64-mingw32/sys-root/mingw/include/crtdefs.h:10:0, from /usr/i686-w64-mingw32/sys-root/mingw/include/stdint.h:28, from /usr/lib/gcc/i686-w64-mingw32/4.9.2/include/stdint.h:9, from ../../byterun/caml/config.h:34, from ../../byterun/caml/misc.h:24, from ../../byterun/caml/alloc.h:23, from st_stubs.c:18: /usr/i686-w64-mingw32/sys-root/mingw/include/_mingw.h:225:0: note: this is the location of the previous definition #define _WIN32_WINNT 0x502 ^
* Do not use the compatibility macros in the C stub code. (#892)Sébastien Hinderer2016-11-171-5/+5
| | | | | | | | | | | | * Don't use the compatibility macros, neither in the C stub code nor in the testsuite. * Make sure compiler sources do not use deprecated C identifiers. This is achieved by ensuring that the CAML_NAME_SPACE macro is defined everytime a C source file is compiled, rather than being defined only in a few places. Defining this macro guarantees that the compatibility.h header (where these deprecated identifiers are defined) will not be included.
* Update headers for the new license.Damien Doligez2016-02-181-12/+14
| | | | Remains to be done: remove all headers in testsuite/tests.
* PR#6776: Failure to kill the "tick" thread, segfault when exiting the runtimeDamien Doligez2015-03-311-6/+8
| | | | git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15975 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
* Merge branch 4.01 from branching point to 4.01.0+rc1Damien Doligez2013-09-041-1/+2
| | | | | | | | Command line used: svn merge --accept postpone -r 13776:14055 $REPO/version/4.01 . git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14060 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
* WinError.h -> winerror.h. This improves cross-compilation for Windows.Wojciech Meyer2012-12-301-1/+1
| | | | | | Patch proposed by Adrien Nader. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13175 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
* remove all $Id keywordsDamien Doligez2012-10-151-2/+0
| | | | git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13013 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
* clean up TABs and whitespaceDamien Doligez2012-07-301-10/+10
| | | | git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12799 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
* PR#5504: Fix. Patch proposed by Stephane Glondu, thanks.Wojciech Meyer2012-02-191-1/+1
| | | | git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12170 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
* Fix #5383: Cannot build OCaml 3.12.1 Win32/MSVCJonathan Protzenko2012-01-301-0/+1
| | | | git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@12100 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
* renaming of Objective Caml to OCaml and cleanup of copyright headersDamien Doligez2011-07-271-1/+1
| | | | git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11156 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
* - Refactoring of otherlibs/systhreadsXavier Leroy2010-04-271-0/+419
- PR#4702: added C functions to register threads not created by Caml - PR#5013: wrong implementation of condition variables under Win32 - PR#4979: wrong error code handling under Win32 - Added standard include <caml/threads.h> - Added "stack_size" field in GC statistics. git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@10315 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02