51Degrees Device Detection C/C++  4.1

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 #ifndef FIFTYONE_DEGREES_NO_THREADING
141 #include "threading.h"
142 #endif
143 
144 #ifdef __cplusplus
145 #define EXTERNAL extern "C"
146 #else
147 #define EXTERNAL
148 #endif
149 
151 typedef struct fiftyone_degrees_resource_manager_t
153 
154 typedef struct fiftyone_degrees_resource_handle_t
163 typedef union fiftyone_degrees_resource_handle_counter_t {
164  int32_t inUse;
165  void *padding;
168 
174 typedef struct fiftyone_degrees_resource_handle_t {
178  const void* resource;
181  void(*freeResource)(void*);
184 
188 typedef struct fiftyone_degrees_resource_manager_t {
189 #ifndef FIFTYONE_DEGREES_NO_THREADING
193 #else
196 #endif
198 
218  void *resource,
219  fiftyoneDegreesResourceHandle **resourceHandle,
220  void(*freeResource)(void*));
221 
236 
247 
256 
267 EXTERNAL void fiftyoneDegreesResourceReplace(
269  void *newResource,
270  fiftyoneDegreesResourceHandle **newResourceHandle);
271 
276 #endif
const fiftyoneDegreesResourceManager * manager
Pointer to the manager the handle relates to.
Definition: resource.h:179
fiftyoneDegreesResourceHandleCounter counter
Tracks active use count of the resource.
Definition: resource.h:176
const void * resource
Pointer to the resource being managed.
Definition: resource.h:178
void fiftyoneDegreesResourceReplace(fiftyoneDegreesResourceManager *manager, void *newResource, fiftyoneDegreesResourceHandle **newResourceHandle)
Replaces the resource with the new resource.
int32_t inUse
Active use count of the resource.
Definition: resource.h:164
void fiftyoneDegreesResourceHandleDecUse(fiftyoneDegreesResourceHandle *handle)
Decrements the usage counter.
void fiftyoneDegreesResourceManagerFree(fiftyoneDegreesResourceManager *manager)
Frees any data associated with the manager and releases the resource making it eligible for freeing.
Tracks the number of active uses of the resource within the manager.
Definition: resource.h:174
Manager structure used to provide access to a shared and changing resource.
Definition: resource.h:188
Contains the number of active uses of the resource.
Definition: resource.h:163
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.
void * padding
Pads the union to the size of a pointer.
Definition: resource.h:165
fiftyoneDegreesResourceHandle volatile * active
Current handle for resource used by the manager.
Definition: resource.h:190