Nekotekina
0a5742587a
atomic.cpp: upgrade raw_notify()
...
Now it searches all semaphores if data arg is nullptr.
Also it tries to wake up all threads if thread_id is 0.
2020-11-06 17:15:40 +03:00
Nekotekina
ad4df2d946
atomic.cpp: refactor native signaling functions
...
Add native_alert() and try_native_alert()
2020-11-06 17:15:40 +03:00
Nekotekina
bfe9580551
atomic.cpp: fix cond_handle data structures
...
Fix a critical bug with possible id out of range.
2020-11-06 16:56:59 +03:00
Nekotekina
557f0c5a8a
atomic.cpp: remove load() from notify functions
...
Only compare masks for overlap for second overload (with mask provided).
Explicit "new value" can be provided in new 3-arg overloads.
Also rename atomic_storage_futex -> atomic_wait_engine.
2020-11-06 04:44:31 +03:00
Nekotekina
9fb8d449fe
atomic.cpp: more improvements
...
Add ref counters for internal semaphores for concurrent notifying.
Lack of them could result in loss of notification.
2020-11-06 00:14:53 +03:00
Nekotekina
1bb7c74c93
atomic.cpp: various cleanups and fixes
...
Add pointer comparison to notifiers (to prevent spurious wakeups).
Fix a bug with a possible double notification in raw_notify().
Fix a bug with incorrect allocatin bit slots for cond_handle.
Add a semaphore counter to track max allowed number of threads.
Use #define for some constants to STRINGIZE them in errors.
Add some error messages when certain limits are reached.
Fix a bug with a wrong check simply throwing std::abort.
Use "special" notify_all patch with batch processing for every arch.
Fix Win7 bug who no one probably noticed.
2020-11-06 00:10:16 +03:00
Nekotekina
5248240e10
atomic.cpp: improvements.
...
Reduced static memory amount for waitable atomics.
Allow notifier to skip notifications if wait/notify masks don't overlap.
Improve raw_notify to wake up the thread by its id, add thread_id arg.
Add optional mask argument to notify_one() and notify_all().
2020-11-05 05:51:43 +03:00
Nekotekina
c50233cc92
atomics.cpp: add support for waiting on 128-bit atomics
...
Complementarily.
Also refactored to make waiting mask non-template arg.
2020-10-28 03:47:41 +03:00
Nekotekina
6806e3d5c7
atomic.cpp: implement notify callback
...
Notification can be very heavy, especially if we need to wake many threads.
Callback is set for cpu_thread in order to set wait flag accordingly.
2020-10-27 17:56:19 +03:00
Nekotekina
d344701fd5
atomic.cpp: add sparse atomics
...
Set alignment as second template argument (typically cache line).
2020-10-26 01:15:31 +03:00
Nekotekina
af6fcb19a8
atomic.cpp: add std primitive fallback for other platforms
...
Other platforms = not Windows or Linux.
2020-10-25 16:45:22 +03:00
Nekotekina
7db77a5580
atomic.cpp: use new thread alerting API (Win8+)
...
Win7 will remain using old API (keyed events).
2020-10-24 19:06:02 +03:00
Nekotekina
c479d431a4
atomic.cpp: experimental optimization (Win7+)
...
Try non-blocking wake up function first.
2020-10-24 14:16:32 +03:00
Nekotekina
8628fc441d
atomic.cpp: rewrite internals (again)
...
Use individual semaphore for each thread.
Unfortunately, limit max thread waiting for single address (60).
If limit is reached, use busy waiting.
2020-10-24 14:16:32 +03:00
Nekotekina
d48d67767a
atomic.cpp: integrate callback check in ptr_cmp function
2020-10-24 14:16:32 +03:00
Nekotekina
59d9e7ce98
Revert "Atomics: use WaitOnAddress if available (Win8+)"
...
This reverts commit f0fd7e2e19 .
2020-10-21 09:59:08 +03:00
Nekotekina
306593a0c5
Revert "atomic.cpp: fixup for WaitOnAddress path"
...
This reverts commit 3b8bce1bed .
2020-10-21 09:54:22 +03:00
Nekotekina
3b8bce1bed
atomic.cpp: fixup for WaitOnAddress path
...
Also fix wait quantum.
2020-10-21 08:18:27 +03:00
Nekotekina
f0fd7e2e19
Atomics: use WaitOnAddress if available (Win8+)
2020-10-21 00:22:08 +03:00
Eladash
17c8b34088
atomic.cpp: Optimize sema_get to not always use atomic instruction ( #8907 )
2020-09-16 22:15:14 +03:00
Eladash
fe9c61fe73
atomic.hpp: Fix atomic_storage_futex::raw_notify
2020-09-12 22:11:40 +03:00
Nekotekina
032e7c0491
Replace utils::cntlz{32,64} with std::countl_zero
2020-04-14 16:05:58 +03:00
Nekotekina
d0c199d455
Replace utils::cnttz{32,64} with std::countr_{zero,one}
...
Make #include <bit> mandatory.
2020-04-14 16:05:58 +03:00
Nekotekina Aux1
250736ece5
Fix warnings in emucore
2020-03-04 21:23:34 +03:00
Nekotekina
ec1ea466fd
atomic.hpp: fix typo
2019-10-23 16:01:14 +03:00
Nekotekina
b844cd81e8
atomic.hpp: remove <string> dependency
2019-10-20 23:06:17 +03:00
Nekotekina
2dde133e1f
atomic.hpp: fix internal resource deallocation
...
Also remove debug printf.
2019-10-20 23:06:17 +03:00
Nekotekina
4d46e66833
atomic.hpp: improve internal data layout
...
Put semaphore control variable together in hashtable.
Avoid unnecessary allocation of extents.
2019-10-20 20:08:09 +03:00
Nekotekina
56b310ebac
atomic.hpp: reimplement USE_FUTEX path for Linux
2019-10-20 20:05:36 +03:00
Nekotekina
e0f60c5dce
atomic.hpp: rewrite collision handling
...
Remove "fallback" code path.
Remove USE_FUTEX code path temporarily.
2019-10-20 18:29:20 +03:00
Nekotekina
db7042b986
Restore using keyed events in waitable atomics on Windows
2019-10-18 23:08:00 +03:00
Nekotekina
9710473a2e
atomic.hpp: use native semaphores on Windows
...
Windows: drop keyed events
Linux: keep using native futex
Implement unused POSIX semaphore path
Implement fallback semaphore with pure std (OSX, BSD, etc)
2019-09-24 05:01:00 +03:00
Nekotekina
95c939f014
atomic.hpp: fix pointer mask
2019-09-24 05:01:00 +03:00
Nekotekina
74471e8ea3
atomic.hpp: fixup for atomic waiting
2019-09-24 05:01:00 +03:00
Nekotekina
e982871ab5
atomic.hpp: increase hashtable capacity
...
Double size and ignore 2 lowest bits (effectively x8)
2019-09-13 15:53:34 +03:00
Nekotekina
2fc8844315
atomic.hpp: add atomic wait mask support
2019-09-13 15:53:34 +03:00
Nekotekina
4504ac2d12
atomic.hpp: implement collision fallback properly
...
Should prevent devastating effect of collisions
2019-09-10 19:25:39 +03:00
Nekotekina
67f31c17d1
atomic.hpp: fix signal saturation logic
...
Make sure to notify_all at max signal count.
2019-09-10 19:25:39 +03:00
Nekotekina
a808c2aaf6
atomic.hpp: optimize internal logic
...
Move waiter count to highest bits to prevent false futex wakeups.
Test pointer bits properly in notify_all to avoid false wakeups.
2019-09-10 19:25:39 +03:00
Nekotekina
aa99faa85d
atomic.hpp: add timeout support
2019-09-10 19:25:39 +03:00
Nekotekina
1668d6ee1b
atomic.hpp: implement wait callback interface
...
Will be used to wake up threads uniformly.
2019-09-10 17:43:04 +03:00
Nekotekina
5bd17a44c9
Add fallback implementation for waitable atomics
...
May improve perf on OSX/BSD
2019-08-02 18:37:23 +03:00
Nekotekina
c6993d3f1c
Change bits of waitable atomics
...
Reduce max waiter count to 2^14.
Refactor code to use waiter_mask and signal_mask constants.
2019-07-29 21:55:59 +03:00
Nekotekina
e1db6cef6f
Remove ignored bits in waitable atomics
...
It was not implemented correctly.
2019-07-29 21:55:59 +03:00
Nekotekina
f63e89f9b4
Implement waitable atomics
...
Moved Atomic.h to util/atomic.hpp
List source files in CMakeLists.txt
2019-07-29 03:04:55 +03:00