diff options
author | Simon Rettberg | 2019-08-27 16:13:07 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-08-27 16:13:07 +0200 |
commit | 69f5bf408b9587a6e2008fba2224c2d506f1a895 (patch) | |
tree | 8fc9eda7e3a0b105007b7a85a4cc35ecc1d4431d /src/server/reftypes.h | |
parent | [SERVER] Fix warnings, simplify locking (diff) | |
download | dnbd3-69f5bf408b9587a6e2008fba2224c2d506f1a895.tar.gz dnbd3-69f5bf408b9587a6e2008fba2224c2d506f1a895.tar.xz dnbd3-69f5bf408b9587a6e2008fba2224c2d506f1a895.zip |
[SERVER] Use reference counting for uplink
First step towards less locking for proxy mode
Diffstat (limited to 'src/server/reftypes.h')
-rw-r--r-- | src/server/reftypes.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/server/reftypes.h b/src/server/reftypes.h new file mode 100644 index 0000000..45c0c20 --- /dev/null +++ b/src/server/reftypes.h @@ -0,0 +1,25 @@ +#ifndef _REFTYPES_H_ +#define _REFTYPES_H_ + +#include <stdatomic.h> + +_Static_assert( sizeof( void * ) == sizeof( _Atomic( void * ) ), "Atomic pointer bad" ); + +typedef _Atomic( void * ) weakref; + +#define aligned_ref(ptr) \ + ((union _aligned_ref_ *)((ptr) - (uintptr_t)(ptr) % sizeof(union _aligned_ref_))) + +union _aligned_ref_ { + struct _ref_ *ref; + void *_padding[( 32 - 1 ) / sizeof( void * ) + 1]; +}; + +typedef struct _ref_ { + _Atomic long count; + void ( *free )( struct _ref_ * ); + char _padding[sizeof( union _aligned_ref_ )]; + char _aligned_ref[sizeof( union _aligned_ref_ )]; +} ref; + +#endif |