51Degrees Device Detection C/C++  4.4

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


1 /* *********************************************************************
2  * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3  * Copyright 2022 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  * ********************************************************************* */
119 #include <stdio.h>
120 #include <errno.h>
121 #include <stdint.h>
122 #ifdef _MSC_VER
123 #pragma warning (push)
124 #pragma warning (disable: 5105)
125 #include <windows.h>
126 #pragma warning (default: 5105)
127 #pragma warning (pop)
128 #endif
129 #include <assert.h>
130 #include <limits.h>
131 #include "data.h"
132 #include "exceptions.h"
133 #include "memory.h"
135 #include "threading.h"
136 #endif
137 #include "common.h"
140 typedef struct fiftyone_degrees_pool_item_t fiftyoneDegreesPoolItem;
141 typedef struct fiftyone_degrees_pool_t fiftyoneDegreesPool;
152 typedef void*(*fiftyoneDegreesPoolResourceCreate)(
153  fiftyoneDegreesPool *pool,
154  void *state,
155  fiftyoneDegreesException *exception);
164 typedef size_t(*fiftyoneDegreesPoolResourceSize)(void *state);
172  fiftyoneDegreesPool *pool,
173  void *resource);
178 typedef struct fiftyone_degrees_pool_item_t {
179  void *resource;
180  uint16_t next;
187 typedef union fiftyone_degrees_pool_head_t {
188  volatile long exchange;
189  struct {
190  uint16_t index;
191  uint16_t aba;
192  } values;
198 typedef struct fiftyone_degrees_pool_t {
202  uint16_t count;
224  fiftyoneDegreesPool *pool,
225  uint16_t concurrency,
226  void *state,
227  fiftyoneDegreesPoolResourceCreate resourceCreate,
228  fiftyoneDegreesPoolResourceFree resourceFree,
229  fiftyoneDegreesException *exception);
241  fiftyoneDegreesPool *pool,
242  fiftyoneDegreesException *exception);
256 EXTERNAL void fiftyoneDegreesPoolFree(fiftyoneDegreesPool* pool);
262 EXTERNAL void fiftyoneDegreesPoolReset(fiftyoneDegreesPool *pool);
268 #endif
void fiftyoneDegreesPoolReset(fiftyoneDegreesPool *pool)
Resets the pool without releasing any resources.
fiftyoneDegreesPoolResourceFree resourceFree
Frees a resource.
Definition: pool.h:203
Pool item node in the stack of items.
Definition: pool.h:178
void(* fiftyoneDegreesPoolResourceFree)(fiftyoneDegreesPool *pool, void *resource)
Frees a resource previously created with fiftyoneDegreesPoolResourceCreate.
Definition: pool.h:171
uint16_t index
Index of the item in the linked list.
Definition: pool.h:190
void fiftyoneDegreesPoolFree(fiftyoneDegreesPool *pool)
Releases the items used by the pool freeing the resources used by each item by calling the resourceFr...
uint16_t count
Number of resource items that stack can hold.
Definition: pool.h:202
volatile long exchange
Number used in the compare exchange operation.
Definition: pool.h:188
Pool of resources stored as items in a stack.
Definition: pool.h:198
uint16_t aba
ABA value used to ensure proper operation.
Definition: pool.h:191
fiftyoneDegreesPoolItem * stack
Pointer to the memory used by the stack.
Definition: pool.h:199
fiftyoneDegreesPoolItem * fiftyoneDegreesPoolItemGet(fiftyoneDegreesPool *pool, fiftyoneDegreesException *exception)
Gets the next free item from the pool for exclusive use by the caller.
size_t(* fiftyoneDegreesPoolResourceSize)(void *state)
Used to determine the additional size beyond the pointer used for each resource added to the pool.
Definition: pool.h:164
The head of the stack used for pop and push operations.
Definition: pool.h:187
fiftyoneDegreesPoolHead head
Head of the stack.
Definition: pool.h:201
void fiftyoneDegreesPoolItemRelease(fiftyoneDegreesPoolItem *item)
Releases the item back to the pool it belongs ready to be reused by another operation.
void * resource
Pointer to the resource in the pool.
Definition: pool.h:179
fiftyoneDegreesPool * fiftyoneDegreesPoolInit(fiftyoneDegreesPool *pool, uint16_t concurrency, void *state, fiftyoneDegreesPoolResourceCreate resourceCreate, fiftyoneDegreesPoolResourceFree resourceFree, fiftyoneDegreesException *exception)
Initialises a pool data structure to support the number of concurrent requests that can be made to th...
void *(* fiftyoneDegreesPoolResourceCreate)(fiftyoneDegreesPool *pool, void *state, fiftyoneDegreesException *exception)
Used to create a new resource for use in the pool.
Definition: pool.h:152
Structure used to represent a 51Degrees exception and passed into methods that might generate excepti...
Definition: exceptions.h:111
uint16_t next
The next item in the stack.
Definition: pool.h:180
fiftyoneDegreesPool * pool
Reader the handle belongs to.
Definition: pool.h:181