Remove obsolete m-shared.h header

This commit is contained in:
Patrick Pelissier committed 2025-05-07 21:34:18 +02:00
1 parent 790ae33334
commit 2296f203fd
5 files changed
+2 -974

No files matched your search

-171
View File
@@ -196,7 +196,6 @@ Finally, headers for compatibility with non C11 compilers:
* [m-thread.h](#m-thread): header for providing a very thin layer across multiple implementation of mutex/threads (C11/PTHREAD/WIN32).
The following headers are obsolete and will be removed in the next major release:
* [m-shared.h](#m-shared): header for creating shared pointer of generic type,
* [m-concurrent.h](#m-concurrent): header for transforming a container into a concurrent container (thread safe),
* [m-i-shared.h](#m-i-shared): header for creating intrusive shared pointer of generic type (Thread Safe).
* [m-mempool.h](#m-mempool): header for creating specialized & fast memory allocator,
@@ -5086,176 +5085,6 @@ Create a new shared object initialized with its `INIT_SET` operator on the given
This method is created only if the `INIT_SET` operator is defined.
_________________
### M-SHARED
> [!NOTE]
> This header is obsolete: M-SHARED-PTR should be used instead.
This header is for creating shared pointer.
A [shared pointer](https://en.wikipedia.org/wiki/Smart_pointer)
is a smart pointer that retains shared ownership of an object.
Several shared pointers may own the same object, sharing ownership of an object.
#### `SHARED_PTR_DEF(name, type[, oplist])`
#### `SHARED_PTR_DEF_AS(name, name_t, type[, oplist])`
Define the shared pointer `name_t` and its associated methods as `static inline` functions.
A shared pointer is a mechanism to keep tracks of all registered users of an object
and performs an automatic destruction of the object only when all users release
their need on this object.
`name` shall be a C identifier that will be used to identify the shared pointer.
It will be used to create all the types (including the iterator)
and functions to handle the container.
This definition shall be done once per name and per compilation unit.
The tracking of ownership is atomic and the destruction of the object is thread safe.
The object oplist is expected to have at least the following operators (`CLEAR` to clear the object and `DEL` to free the allocated memory).
There are designed to work with buffers with policy `BUFFER_PUSH_INIT_POP_MOVE`
to send a shared pointer across multiple threads.
If the type is an incomplete type, you need to disable the `INIT` operator and not defined the `EMPLACE_TYPE` operator in the given oplist like this:
```C
(INIT(0), CLEAR(API_2(incomplete_clear))) )
```
`SHARED_PTR_DEF_AS` is the same as `SHARED_PTR_DEF` except the name of the type `name_t`
is provided.
Example:
```C
SHARED_PTR_DEF(shared_mpz, mpz_t, (CLEAR(mpz_clear)))
void f(void) {
shared_mpz_t p;
mpz_t z;
mpz_init(z);
shared_mpz_init2 (p, z);
buffer_uint_push(g_buff1, p);
buffer_uint_push(g_buff2, p);
shared_mpz_clear(p);
}
```
#### `SHARED_PTR_RELAXES_DEF(name, type[, oplist])`
#### `SHARED_PTR_RELAXES_DEF_AS(name, name_t, type[, oplist])`
Theses are the same as `SHARED_PTR_DEF` / `SHARED_PTR_DEF_AS`
except that they are not thread safe.
See `SHARED_PTR_DEF` for other details.
#### Created types
The following types are automatically defined by the previous definition macro if not provided by the user:
##### `name_t`
Type of the shared pointer.
#### Specialized methods
The following specialized methods are automatically created by the previous definition macro:
##### `void name_init(shared_t shared)`
Initialize the shared pointer `shared` to represent the NULL pointer
(no object is therefore referenced).
##### `void name_init2(shared_t shared, type *data)`
Initialize the shared pointer `shared` to reference the object `*data`
and takes ownership of this object.
User code shall not use `*data` (or any pointer to it) anymore
as the shared pointer gets the exclusive ownership of the object.
##### `void name_init_new(shared_t shared)`
Initialize the shared pointer `shared` to a new object of type `type`.
The default constructor of type is used to initialize the object.
This method is only created if the `INIT` method is provided.
##### `void name_init_set(shared_t shared, const shared_t src)`
Initialize the shared pointer `shared` to the same object than the one
pointed by `src` (sharing ownership).
This function is thread safe from `src` point of view.
##### `void name_init_with[suffix](shared_t shared, args...)`
Initialize the shared pointer `shared` to the new object initialized with args.
The provided arguments shall therefore match one of the constructor provided
by the `EMPLACE_TYPE` operator.
There is one generated method per suffix defined in the `EMPLACE_TYPE` operator,
and the `suffix` in the generated method name corresponds to the suffix defined
in the `EMPLACE_TYPE` operator (it can be empty).
This method is created only if the `EMPLACE_TYPE` operator is provided.
See [emplace chapter](#Emplace-construction) for more details.
It is equivalent to the C++ make_shared.
##### `bool name_NULL_p(const shared_t shared)`
Return true if shared doesn't reference any object (i.e. is the NULL pointer).
##### `void name_clear(shared_t shared)`
Clear the shared pointer (destructor):
the shared pointer loses its ownership of the object and
it destroys the shared object if no longer any other shared pointers own it.
This function is thread safe.
##### `void name_reset(shared_t shared)`
`shared` loses ownership of its shared object and destroys it
if no longer any other shared pointers own it.
Then it makes the shared pointer `shared` references no object (NULL)
(it doesn't reference its object any-longer and loses its ownership of it).
This function is thread safe.
##### `void name_set(shared_t shared, const shared_t src)`
`shared` loses ownership of its object and destroy it
if no longer any other shared pointers own it.
Then it sets the shared pointer `shared` to the same object
than the one pointed by `src` (sharing ownership).
This function is thread safe.
##### `void name_init_move(shared_t shared, shared_t src)`
Move the shared pointer from the initialized `src` to `shared`.
##### `void name_move(shared_t shared, shared_t src)`
`shared` loses ownership of its object and destroy it
if no longer any other shared pointers own it.
Then it moves the shared pointer from the initialized `src` to `shared`.
##### `void name_swap(shared_t shared1, shared_t shared2)`
Swap the references of the objects owned by the shared pointers `shared1` and `shared2`.
##### `bool name_equal_p(const shared_t shared1, const shared_t shared2)`
Return true if both shared pointers own the same object.
##### `const type *name_cref(const shared_t shared)`
Return a constant pointer to the shared object owned by the shared pointer.
The pointer shall be kept only until another use of shared pointer method.
Keeping the pointer otherwise is undefined behavior.
##### `type *name_ref(const shared_t shared)`
Return a pointer to the shared object pointed by the shared pointer.
The pointer shall be kept only until another use of shared pointer method.
Keeping the pointer otherwise is undefined behavior.
TODO: Document shared resource
_________________
### M-I-SHARED