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 2026 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
26#ifdef FIFTYONE_DEGREES_IPI_SYMBOLS
27#include "ipiSymbols.h"
28#endif
29
135
136/* Define NDEBUG if needed, to ensure asserts are disabled in release builds */
137#if !defined(DEBUG) && !defined(_DEBUG) && !defined(NDEBUG)
138#define NDEBUG
139#endif
140
141#include <stdlib.h>
142#include <stdint.h>
143#include <assert.h>
144#include "threading.h"
145#include "common.h"
146
148typedef struct fiftyone_degrees_resource_manager_t
150
151typedef struct fiftyone_degrees_resource_handle_t
154
161typedef struct fiftyone_degrees_resource_handle_t {
162#ifndef FIFTYONE_DEGREES_NO_THREADING
163 volatile
164#endif
167 const void* resource;
170 void(*freeResource)(void*);
173
177typedef struct fiftyone_degrees_resource_manager_t {
178#ifndef FIFTYONE_DEGREES_NO_THREADING
182#else
185#endif
187
203 void *resource,
204 fiftyoneDegreesResourceHandle **resourceHandle,
205 void(*freeResource)(void*));
206
215
226
235
245
260 void *newResource,
261 fiftyoneDegreesResourceHandle **newResourceHandle);
262
266
267#endif
void fiftyoneDegreesResourceReplace(fiftyoneDegreesResourceManager *manager, void *newResource, fiftyoneDegreesResourceHandle **newResourceHandle)
Replaces the resource with the new resource.
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.
int32_t fiftyoneDegreesResourceHandleGetUse(fiftyoneDegreesResourceHandle *handle)
Return the current usage counter.
fiftyoneDegreesResourceHandle * fiftyoneDegreesResourceHandleIncUse(fiftyoneDegreesResourceManager *manager)
Increments the usage counter for the resource and returns a handle that can be used to reference it.
void fiftyoneDegreesResourceManagerFree(fiftyoneDegreesResourceManager *manager)
Frees any data associated with the manager and releases the manager.
void fiftyoneDegreesResourceHandleDecUse(fiftyoneDegreesResourceHandle *handle)
Decrements the usage counter.
Double width (64 or 128 depending on the architecture) compare and exchange.
Definition threading.h:430
Handle for a shared resource.
Definition resource.h:161
volatile fiftyoneDegreesInterlockDoubleWidth counter
Counter for this handle.
Definition resource.h:165
void(* freeResource)(void *)
Pointer to the method used to free the resource.
Definition resource.h:170
const void * resource
Pointer to the resource being managed.
Definition resource.h:167
const fiftyoneDegreesResourceManager * manager
Pointer to the manager the handle relates to.
Definition resource.h:168
Manager structure used to provide access to a shared and changing resource.
Definition resource.h:177
volatile fiftyoneDegreesResourceHandle * active
Current handle for resource used by the manager.
Definition resource.h:179