Commit Graph

347 Commits

Author SHA1 Message Date
rdb c99fe581d3 Merge branch 'release/1.10.x' 2023-09-16 09:57:09 +02:00
rdb 0bc290eb2c event: Replace _PyGen_FetchStopIterationValue in Python 3.13+
See python/cpython#106320 and python/cpython#107032

Closes #1526
2023-08-05 16:37:01 +02:00
rdb f80cd08993 Remove support for EOL Python versions 3.6 and 3.7 2023-08-04 14:20:59 +02:00
rdb c34f2bbc64 Switch to UPPER_CASE convention for enum classes as per PEP-8
Old names are still kept around for compatibility reasons, but deprecated - fortunately there are not that many cases of enum classes yet
2023-08-02 11:16:54 +02:00
rdb eefb51f510 dtoolutil: Add small_vector implementation and use it
This vector implementation does is optimized for the case of having only a small number of elements, which are stored directly on the vector object rather than being allocated from the heap.  If the capacity exceeds this small number, then a heap allocation is done.

This should improve performance in a couple of cases where vectors typically store 1 element and rarely more than that.
2023-02-22 16:48:11 +01:00
rdb 5e26aae1ff cleanup: Fix assorted issues uncovered by clang-tidy 2023-02-12 18:17:03 +01:00
Disyer af4a1bc7a9 python: Use public PyErr_Occurred API instead of private macro
The _PyErr_OCCURRED macro was removed in Python 3.10, so we shouldn't keep any compat code left around for it
2023-02-12 02:36:57 +02:00
Frang 275fe32079
create PY_EXTENSION and friends (#1415) 2023-01-04 20:54:53 +01:00
rdb 0747f46055 event: Improve interface for adding tasks from C++
The order of arguments is now the same as in Python (with the callable first), sort and priority arguments have been added, and new tasks can be added directly to a chain
2022-12-26 19:10:01 +01:00
Cary Sandvig 3247903d7b add more HAVE_PYTHON
Also add some more #endif comments.
2022-12-23 13:38:46 -05:00
rdb 867f60dcca pstats: Rename "Show code" collector to "Tasks"
Also remove outdated definitions from pStatProperties.cxx
2022-11-29 20:50:18 +01:00
rdb ae7084504b event: Fix crash when creating task from closure with extra data 2022-10-31 23:09:13 +01:00
rdb bf65624298 dtoolbase: Make MemoryHook constant-initialized
init_memory_hook() is no longer required, eliminating static initialization order issues

This required moving the DeletedBufferChain map elsewhere, which now also has a const-initialized array for relatively small allocations.

Also, deletedChain.T has been renamed to deletedChain.I

Fixes #539
2022-10-24 13:26:03 +02:00
rdb 20334cce05 Merge branch 'release/1.10.x' 2022-06-29 19:09:59 +02:00
rdb 9ab460c900 event: Fix memory leak in debug check of `task.set_owner(...)`
Fixes #1328
2022-06-29 15:13:57 +02:00
rdb a0be50c769 general: Fix assorted compiler warnings 2022-03-01 16:09:07 +01:00
rdb cb8563acac event: Update AsyncFuture to use new atomics implementation
With explicit barriers, and the non-timeout version of wait() is now significantly more efficient by using the new futexes if available
2022-02-23 23:20:49 +01:00
rdb b4d51c24e9 event: Remove FunctionAsyncTask
To create a task from a lambda, it is more efficient to use the new AsyncTaskManager::add() short-hand which creates an AsyncTask subclass in-place.
2022-02-22 18:02:34 +01:00
rdb 7baeaf3809 event: New C++ AsyncTaskManager::add() no longer uses std::function
std::function has unnecessary overhead, better to just create an AsyncTask subclass in-place storing the closure

This obsoletes FunctionAsyncTask, it will be removed in a future commit
2022-02-22 17:02:42 +01:00
rdb 8034cb5a92 dtoolbase: Introduce patomic<> as replacement for AtomicAdjust
This typedefs to std::atomic<> when building with true threading, and uses a dummy implementation without.

This lets us use the full range of atomic operations offered by C++11, including explicit specification of memory fences.  Using barriers lets the compiler generate more optimal code since currently we are using the quite strict sequential-consistent memory ordering for all operations.  ReferenceCount has been changed to use the correct barriers (I hope).  This may especially make a difference on weak ordering systems such as ARM.

Over time we should gradually replace the use of AtomicAdjust with the new patomic file.
2022-01-30 01:53:36 +01:00
rdb e4013226e1 general: Remove vestigial typedef.h file 2021-12-12 18:37:49 +01:00
rdb 5de31c6293 Merge branch 'release/1.10.x' 2021-12-04 21:57:35 +01:00
rdb e2c26adcf0 event: Mention that ButtonEvent API is not stable for Python use 2021-12-04 20:38:13 +01:00
rdb 9e7ca63662 Add missing @since to docstrings of some new methods 2021-11-29 16:02:22 +01:00
rdb 653cc3e091 event: Support C++11 lambdas as event handlers
It's unfortunate that we now have three maps on EventHandler for three different types of functions.  I'd love to unify them all under std::function, but the fact that it doesn't support comparison means the behavior would be different.

Perhaps in the future we can create a new interface or deprecate the existing behaviors and unify everything under std::function.
2021-11-29 14:48:06 +01:00
rdb 4af5bc9e6d event: Support lambdas as tasks via new FunctionAsyncTask
This is intended to replace GenericAsyncTask.
2021-11-29 14:47:44 +01:00
rdb 78fb565f2b Merge branch 'release/1.10.x' 2021-11-28 16:14:18 +01:00
rdb 980399d142 event: Expose ButtonEvent to Python 2021-11-28 14:36:20 +01:00
rdb ea61e53ab2 event: Fix ButtonEvent docstring 2021-11-28 13:56:55 +01:00
rdb c9508f3215 task: Prevent error indicator being sporadically cleared 2021-05-31 17:44:57 +02:00
rdb 571946739e task: Fix cancelling gather() of tasks 2021-05-11 12:21:37 +02:00
rdb 91a6ff1d81 task: Prevent "unexpected task state" when cancelling task sometimes 2021-05-11 12:21:30 +02:00
rdb 5ef1b44455 event: cancel future being awaited when cancelling coroutine task
Fixes #1136
2021-04-18 17:05:00 +02:00
rdb cdf5b16ddd task: Add AsyncFuture::shield() ability, part of #1136
This is modelled after `asyncio.shield()` and can be used to protect an inner future from cancellation when the outer future is cancelled.
2021-04-09 18:28:07 +02:00
rdb 050d86dadb event: AsyncFuture::set_result() behavior changes:
* Passing a Python subclass of a C++ class now works, the extra Python stuff isn't just discarded
* EventParameter objects are no longer automagically unwrapped - there's no more reason to pass an EventParameter to this method anyway, and it might be unexpected if it is treated specially.
2021-03-01 20:50:25 +01:00
rdb 402c303dba event: Make AsyncFuture::set_result() slightly more robust 2021-03-01 19:33:39 +01:00
rdb 8cbe36b352 Merge branch 'release/1.10.x' 2021-03-01 19:33:27 +01:00
rdb 064e0383be event: Allow AsyncFuture to store arbitrary PyObject result 2021-03-01 19:16:22 +01:00
rdb 2b3f2bb98c event: gather() should schedule coroutines with task manager
This matches the behaviour of asyncio.  It schedules with the current task's manager and chain.  If no current manager is found, it prints a warning.  (The user can just add the coroutine to a task manager themselves and pass the resulting task into gather() if needed.)

See discussion here:
https://discourse.panda3d.org/t/task-gather-does-not-seem-to-work/27313
2021-03-01 11:22:13 +01:00
rdb e348d216e5 event: Fix memory leak getting future result in some cases 2021-03-01 11:09:10 +01:00
rdb 6a51709332 event: Don't suppress coroutine exceptions in optimized builds 2021-02-26 11:44:50 +01:00
rdb a64dcd7c5d event: (BREAKING CHANGE) bare yield in task now means "cont"
This is more useful and consistent; you can after all just use "return" to end the task, whereas you can now just use "yield" to continue the next frame rather than "yield Task.cont".

This is a follow-up to f6b39345f7, which already enabled this behavior when an __await__ (that is awaited from a task) yielded None.
2021-02-07 15:14:04 +01:00
rdb e8b4b6476c Merge branch 'release/1.10.x' 2021-02-07 15:01:36 +01:00
rdb 8c8a73a1a7 event: Fix compilation with Python 2.7 2021-02-07 14:49:10 +01:00
rdb f6b39345f7 event: don't exit task if future __await__ yields None
This matches the behavior of asyncio's Task implementation, where this is the equivalent of `yield Task.cont`.

I've kept regular generator tasks unaffected for now, since this might break existing usage.
2021-02-07 12:38:16 +01:00
rdb c73c94c862 Merge branch 'release/1.10.x' 2021-02-06 01:23:34 +01:00
rdb 068ceaaf58 event: Clear exception flag after trying asyncio exception import 2021-02-06 01:21:52 +01:00
rdb 492cce8a49 event: Compile out threaded code when compiling without HAVE_THREADS 2021-02-03 13:29:28 +01:00
rdb a1b2d5b8dc Make use of new function call methods in Python 3.9 2020-12-12 17:28:21 +01:00
Daniel 4f63ef635d panda: Remove PyEval_InitThreads calls when compiling against Python 3.9+
Cherry-pick from #1053
2020-12-12 00:16:58 +01:00