51Degrees Device Detection C/C++  4.2

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 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4  * Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
5  *
6  * This Original Work is licensed under the European Union Public Licence (EUPL)
7  * 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 
142 #ifdef __cplusplus
143 #define EXTERNAL extern "C"
144 #else
145 #define EXTERNAL
146 #endif
147 
149 typedef struct fiftyone_degrees_resource_manager_t
151 
152 typedef struct fiftyone_degrees_resource_handle_t
162 typedef struct fiftyone_degrees_resource_handle_t {
163 #ifndef FIFTYONE_DEGREES_NO_THREADING
164  volatile
165 #endif
168  const void* resource;
171  void(*freeResource)(void*);
174 
178 typedef struct fiftyone_degrees_resource_manager_t {
179 #ifndef FIFTYONE_DEGREES_NO_THREADING
183 #else
186 #endif
188 
204  void *resource,
205  fiftyoneDegreesResourceHandle **resourceHandle,
206  void(*freeResource)(void*));
207 
216 
227 
236 
244 EXTERNAL int32_t fiftyoneDegreesResourceHandleGetUse(
246 
257 EXTERNAL void fiftyoneDegreesResourceReplace(
259  void *newResource,
260  fiftyoneDegreesResourceHandle **newResourceHandle);
261 
266 #endif
const fiftyoneDegreesResourceManager * manager
Pointer to the manager the handle relates to.
Definition: resource.h:169
const void * resource
Pointer to the resource being managed.
Definition: resource.h:168
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:166
void fiftyoneDegreesResourceManagerFree(fiftyoneDegreesResourceManager *manager)
Frees any data associated with the manager and releases the manager.
Handle for a shared resource.
Definition: resource.h:162
Manager structure used to provide access to a shared and changing resource.
Definition: resource.h:178
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:437
volatile fiftyoneDegreesResourceHandle * active
Current handle for resource used by the manager.
Definition: resource.h:180
int32_t fiftyoneDegreesResourceHandleGetUse(fiftyoneDegreesResourceHandle *handle)
Return the current usage counter.