Commit Graph

17 Commits

Author SHA1 Message Date
Yonggang Luo d61ac94658 c11: Remove _MTX_INITIALIZER_NP for windows
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Acked-by: David Heidelberg <david.heidelberg@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18493>
2022-11-09 04:38:28 +00:00
Yonggang Luo 399dc71a30 c11: Getting the macro guard of HAVE_PTHREAD in c11/threads.h to be consistence with util/u_uthread.h
The macro guard of #if defined(_WIN32) && !defined(__CYGWIN__) is comes from yohhoy's implementation
and that's not consistence with util/u_uthread.h, this caused it's hard to understand.
Now we change the behavior that's always rely on how meson detecting HAVE_PTHREAD.

So we always disable detecting of threads on Win32 as it's always included in the kernel32 library to
avoid detecting pthreads in mingw.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18425>
2022-10-20 03:04:56 +00:00
Yonggang Luo b6e4aa6f31 meson/mesa/wide: define WIN32_LEAN_AND_MEAN with pre_args
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18425>
2022-10-20 03:04:56 +00:00
Yonggang Luo 2f140c564f c11: Remove the code for Windows XP
We already require Windows Vista or later before this commit;
So the code for Windows XP can be removed.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18425>
2022-10-20 03:04:56 +00:00
Yonggang Luo eec1e728c5 c11: Update the values of enum mtx_plain, mtx_recursive, mtx_timed to make sure mtx_recursive != mtx_plain | mtx_recursive
According to c11 standards, there is 4 variant of mtx_init parameter,
mtx_plain
mtx_timed
mtx_plain|mtx_recursive
mtx_timed|mtx_recursive

Directly use mtx_recursive is not a thing, so we need make sure mtx_plain and mtx_plain|mtx_recursive are not equal,
So now we choose the values from Android c11 threads.h for enum mtx_plain, mtx_recursive, mtx_timed, to make sure
c11/threads.h be more c11 conformance, and can raise error when the type parameter of mtx_init are not one of
mtx_plain
mtx_timed
mtx_plain|mtx_recursive
mtx_timed|mtx_recursive

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18445>
2022-09-14 02:46:51 +00:00
Yonggang Luo f97ba1f95d c11: #include <threads.h> when the os/platform provide it
Closes #6964

CC: mesa-stable

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18043>
2022-08-18 01:02:07 +00:00
Yonggang Luo 4579b702f6 c11: Remove mtx_try from mtx enums as it's not a part of c11 standard
And we support for four types of mtx init enum values that define by C11 standard:
0 mtx_plain - a simple, non-recursive mutex is created.
2 mtx_timed - a non-recursive mutex, that supports timeout, is created.
1 mtx_plain | mtx_recursive - a recursive mutex is created.
3 mtx_timed | mtx_recursive - a recursive mutex, that supports timeout, is created.

musl library also use these enum combination

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18036>
2022-08-15 14:40:52 +00:00
Yonggang Luo e7b4af434b c11: Implement and use of thrd_current properly on win32
Now thrd_t are a struct that contains both thread handle and thread id.
For threads that not created by thrd_create, thrd_current are returning pseudo thread handle;
but we can still compare threads differences by using thread id.

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17071>
2022-08-10 20:14:15 +00:00
Yonggang Luo 125a952b66 c11: call impl_tss_dtor_invoke with tls callback for win32
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17071>
2022-08-10 20:14:15 +00:00
Yonggang Luo e819f71379 c11: It's should detect PTHREAD_DESTRUCTOR_ITERATIONS when define TSS_DTOR_ITERATIONS
INIT_ONCE_STATIC_INIT looks like miscopied from Win32's init once macro
Correct implementation for reference
https://gitlab.inria.fr/gustedt/p99/-/blob/master/p99/p99_threads_posix.h#L64

C11 standard:
https://en.cppreference.com/w/c/thread/TSS_DTOR_ITERATIONS

As TSS_DTOR_ITERATIONS didn't used in mesa codebase, so it's won't affect anything in mesa

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17071>
2022-08-10 20:14:15 +00:00
Yonggang Luo 6a933b7f53 c11: Fixes the declaration of timespec_get in time.h for macOS
../src/util/tests/timespec_test.cpp:327:4: error: use of undeclared identifier 'timespec_get'; did you mean 'timespec_eq'?
   timespec_get(&a, TIME_UTC);
   ^~~~~~~~~~~~
   timespec_eq
../src/util/timespec.h:299:1: note: 'timespec_eq' declared here
timespec_eq(const struct timespec *a, const struct timespec *b)

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Acked-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16995>
2022-08-09 17:23:17 +00:00
Emil Velikov 899aa7925b c11: reinstate the original license and authorship
The original code that was copied in was Boost licensed, so keep that
in. Since Yonggang Luo has code quite some work, keep their copyright
alongside the original one.

Fixes: b2ddec4e98 ("c11: Implement c11/time.h with c11/impl/time.c")
Fixes: e6392fcf3d ("c11: Move the implementation of threads.h into c source code")
Acked-by: Yonggang Luo <luoyonggang@gmail.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17232>
2022-06-27 11:46:22 +00:00
Yonggang Luo 6e33ef2bb9 c11: Implement thread_local in c11/threads.h
Use thread_local when possible

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15087>
2022-06-15 17:37:17 +00:00
Yonggang Luo 09cd5c9bdb c11: Fixes memory leak of pack in thrd_create on win32
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15087>
2022-06-15 17:37:17 +00:00
Yonggang Luo e6392fcf3d c11: Move the implementation of threads.h into c source code
By doing this, now the global variable impl_tss_dtor_tbl are only defined one time.
So the memory usage would reduced

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15087>
2022-06-15 17:37:17 +00:00
Yonggang Luo 65d5ee4012 c11: Implement timespec_get on win32 properly when not available
Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15497>
2022-06-09 17:23:34 +00:00
Yonggang Luo b2ddec4e98 c11: Implement c11/time.h with c11/impl/time.c
Create c11/time.h instead of put timespec_get in `c11/threads.h`

Creating impl folder is used to avoid `#include <time.h>` point the c11/time.h file

Detecting if `struct timespec` present with meson
Define TIME_UTC in `c11/time.h` instead `c11/threads.h`
Define `struct timespec` in `c11/time.h` when not present.
Implement timespec_get in c11/impl/time.c instead threads.h

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15497>
2022-06-09 17:23:34 +00:00