51Degrees Device Detection C/C++  4.3

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 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  * ********************************************************************* */
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
138 #ifdef __cplusplus
139 #define EXTERNAL extern "C"
140 #else
141 #define EXTERNAL
142 #endif
145 typedef struct fiftyone_degrees_pool_item_t fiftyoneDegreesPoolItem;
146 typedef struct fiftyone_degrees_pool_t fiftyoneDegreesPool;
157 typedef void*(*fiftyoneDegreesPoolResourceCreate)(
158  fiftyoneDegreesPool *pool,
159  void *state,
160  fiftyoneDegreesException *exception);
169 typedef size_t(*fiftyoneDegreesPoolResourceSize)(void *state);
177  fiftyoneDegreesPool *pool,
178  void *resource);
183 typedef struct fiftyone_degrees_pool_item_t {
184  void *resource;
185  uint16_t next;
192 typedef union fiftyone_degrees_pool_head_t {
193  volatile long exchange;
194  struct {
195  uint16_t index;
196  uint16_t aba;
197  } values;
203 typedef struct fiftyone_degrees_pool_t {
207  uint16_t count;
229  fiftyoneDegreesPool *pool,
230  uint16_t concurrency,
231  void *state,
232  fiftyoneDegreesPoolResourceCreate resourceCreate,
233  fiftyoneDegreesPoolResourceFree resourceFree,
234  fiftyoneDegreesException *exception);
246  fiftyoneDegreesPool *pool,
247  fiftyoneDegreesException *exception);
261 EXTERNAL void fiftyoneDegreesPoolFree(fiftyoneDegreesPool* pool);
267 EXTERNAL void fiftyoneDegreesPoolReset(fiftyoneDegreesPool *pool);
273 #endif
void fiftyoneDegreesPoolReset(fiftyoneDegreesPool *pool)
Resets the pool without releasing any resources.
fiftyoneDegreesPoolResourceFree resourceFree
Frees a resource.
Definition: pool.h:208
Pool item node in the stack of items.
Definition: pool.h:183
void(* fiftyoneDegreesPoolResourceFree)(fiftyoneDegreesPool *pool, void *resource)
Frees a resource previously created with fiftyoneDegreesPoolResourceCreate.
Definition: pool.h:176
uint16_t index
Index of the item in the linked list.
Definition: pool.h:195
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:207
volatile long exchange
Number used in the compare exchange operation.
Definition: pool.h:193
Pool of resources stored as items in a stack.
Definition: pool.h:203
uint16_t aba
ABA value used to ensure proper operation.
Definition: pool.h:196
fiftyoneDegreesPoolItem * stack
Pointer to the memory used by the stack.
Definition: pool.h:204
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:169
The head of the stack used for pop and push operations.
Definition: pool.h:192
fiftyoneDegreesPoolHead head
Head of the stack.
Definition: pool.h:206
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:184
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:157
Structure used to represent a 51Degrees exception and passed into methods that might generate excepti...
Definition: exceptions.h:116
uint16_t next
The next item in the stack.
Definition: pool.h:185
fiftyoneDegreesPool * pool
Reader the handle belongs to.
Definition: pool.h:186