\r\n

51Degrees Device Detection C/C++  4.4

A device detection library that is used natively or by 51Degrees products

resource.h

1 /* *********************************************************************
2  * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3  * Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
4  * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5  *
6  * This Original Work is licensed under the European Union Public Licence
7  * (EUPL) v.1.2 and is subject to its terms as set out below.
8  *
9  * If a copy of the EUPL was not distributed with this file, You can obtain
10  * one at https://opensource.org/licenses/EUPL-1.2.
11  *
12  * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13  * amended by the European Commission) shall be deemed incompatible for
14  * the purposes of the Work and the provisions of the compatibility
15  * clause in Article 5 of the EUPL shall not apply.
16  *
17  * If using the Work as, or as part of, a network application, by
18  * including the attribution notice(s) required under Article 5 of the EUPL
19  * in the end user terms of the application under an appropriate heading,
20  * such notice(s) shall fulfill the requirements of that article.
21  * ********************************************************************* */
22 
23 #ifndef FIFTYONE_DEGREES_MANAGER_INCLUDED
24 #define FIFTYONE_DEGREES_MANAGER_INCLUDED
25 
132 /* Define NDEBUG if needed, to ensure asserts are disabled in release builds */
133 #if !defined(DEBUG) && !defined(_DEBUG) && !defined(NDEBUG)
134 #define NDEBUG
135 #endif
136 
137 #include <stdlib.h>
138 #include <stdint.h>
139 #include <assert.h>
140 #include "threading.h"
141 #include "common.h"
142 
144 typedef struct fiftyone_degrees_resource_manager_t
146 
147 typedef struct fiftyone_degrees_resource_handle_t
157 typedef struct fiftyone_degrees_resource_handle_t {
158 #ifndef FIFTYONE_DEGREES_NO_THREADING
159  volatile
160 #endif
163  const void* resource;
166  void(*freeResource)(void*);
169 
173 typedef struct fiftyone_degrees_resource_manager_t {
174 #ifndef FIFTYONE_DEGREES_NO_THREADING
178 #else
181 #endif
183 
199  void *resource,
200  fiftyoneDegreesResourceHandle **resourceHandle,
201  void(*freeResource)(void*));
202 
211 
222 
231 
239 EXTERNAL int32_t fiftyoneDegreesResourceHandleGetUse(
241 
252 EXTERNAL void fiftyoneDegreesResourceReplace(
254  void *newResource,
255  fiftyoneDegreesResourceHandle **newResourceHandle);
256 
261 #endif
const fiftyoneDegreesResourceManager * manager
Pointer to the manager the handle relates to.
Definition: resource.h:164
const void * resource
Pointer to the resource being managed.
Definition: resource.h:163
void fiftyoneDegreesResourceReplace(fiftyoneDegreesResourceManager *manager, void *newResource, fiftyoneDegreesResourceHandle **newResourceHandle)
Replaces the resource with the new resource.
void fiftyoneDegreesResourceHandleDecUse(fiftyoneDegreesResourceHandle *handle)
Decrements the usage counter.
volatile fiftyoneDegreesInterlockDoubleWidth counter
Counter for this handle.
Definition: resource.h:161
void fiftyoneDegreesResourceManagerFree(fiftyoneDegreesResourceManager *manager)
Frees any data associated with the manager and releases the manager.
Handle for a shared resource.
Definition: resource.h:157
Manager structure used to provide access to a shared and changing resource.
Definition: resource.h:173
fiftyoneDegreesResourceHandle * fiftyoneDegreesResourceHandleIncUse(fiftyoneDegreesResourceManager *manager)
Increments the usage counter for the resource and returns a handle that can be used to reference it.
void fiftyoneDegreesResourceManagerInit(fiftyoneDegreesResourceManager *manager, void *resource, fiftyoneDegreesResourceHandle **resourceHandle, void(*freeResource)(void *))
Initialise a preallocated resource manager structure with a resource for it to manage access to.
Double width (64 or 128 depending on the architecture) compare and exchange.
Definition: threading.h:422
volatile fiftyoneDegreesResourceHandle * active
Current handle for resource used by the manager.
Definition: resource.h:175
int32_t fiftyoneDegreesResourceHandleGetUse(fiftyoneDegreesResourceHandle *handle)
Return the current usage counter.