Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement [ap_]atomics for [u]int/[u]long/size_t and use them for (some) proxy_worker_shared fields #396

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

ylavic
Copy link
Member

@ylavic ylavic commented Nov 28, 2023

Follow up to https://lists.apache.org/thread/np1xzvq6yq5onmtqqovyx0doncowvp3f

This is a proposal/POC to implement [ap_]atomics on system dependent signed/unsigned types, using the uint32/uint66/ptr atomics from the APR as primitives.

This currently implements:

  • ap_atomic_{int,long,size}_get()
  • ap_atomic_{int,long,size}_set()
  • ap_atomic_{int,long,size}_xchg()
  • ap_atomic_{int,long,size}_cas()
  • ap_atomic_{int,long,size}_add()
  • ap_atomic_{int,long,size}_add_sat()
  • ap_atomic_{int,long,size}_sub()
  • ap_atomic_{int,long,size}_sub_sat()

The add/sub functions wrap on under/overflow (safely for signed types), while the add_sat/sub_sat ones saturate instead (e.g. at INT_MIN/INT_MAX for ints, at 0/ULONG_MAX for unsigned longs, ...).

This allows to replace/remove the ap_proxy_{get,set,dec,inc}_busy_count() specialized functions by using the new ap_atomic_size_*() helpers directly on worker->s->busy, and likewise to use the the new ap_atomic_int_*() directly on worker->s->lbstatus to switch to atomic ops there too.

TODO: dox, MMNs..

@ylavic ylavic force-pushed the ap_atomics branch 3 times, most recently from ef70720 to 05d54b8 Compare November 29, 2023 23:04
jfclere added a commit to jfclere/httpd-asf that referenced this pull request Mar 6, 2024
jfclere added a commit to jfclere/httpd-asf that referenced this pull request Mar 6, 2024
jfclere added a commit to jfclere/httpd-asf that referenced this pull request Mar 6, 2024
Change ERROR into DAVERROR, because Windows has ERROR in assert.h...
@jfclere
Copy link
Contributor

jfclere commented Mar 6, 2024

Oops I caused the conflicts.
Note I have created #421 that works around a problem when building with windows.
I think that is due to the changes in httpd.h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants