Branch data Line data Source code
1 : : /* SPDX-FileCopyrightText: Copyright 2026 Cozens Software Solutions Limited
2 : : * SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 OR LicenseRef-PolyForm-Internal-Use-1.0.0 OR LicenseRef-COSOSO-Commercial
3 : : */
4 : :
5 : : #include "SolidSyslogVxWorks64File.h"
6 : :
7 : : #include <stdbool.h>
8 : : #include <stddef.h>
9 : : #include <stdint.h>
10 : :
11 : : #include "SolidSyslogError.h"
12 : : #include "SolidSyslogErrorCategory.h"
13 : : #include "SolidSyslogNullFile.h"
14 : : #include "SolidSyslogPoolAllocator.h"
15 : : #include "SolidSyslogVxWorks64FileErrors.h"
16 : : #include "SolidSyslogVxWorks64FilePrivate.h"
17 : : #include "SolidSyslogPrival.h"
18 : : #include "SolidSyslogTunables.h"
19 : :
20 : : struct SolidSyslogFile;
21 : :
22 : : static inline size_t VxWorks64File_IndexFromHandle(const struct SolidSyslogFile* base);
23 : : static inline void VxWorks64File_CleanupAtIndex(size_t index, void* context);
24 : :
25 : : static bool VxWorks64File_InUse[SOLIDSYSLOG_FILE_POOL_SIZE];
26 : : static struct SolidSyslogVxWorks64File VxWorks64File_Pool[SOLIDSYSLOG_FILE_POOL_SIZE];
27 : : static struct SolidSyslogPoolAllocator VxWorks64File_Allocator = {VxWorks64File_InUse, SOLIDSYSLOG_FILE_POOL_SIZE};
28 : :
29 : 90 : struct SolidSyslogFile* SolidSyslogVxWorks64File_Create(void)
30 : : {
31 : 90 : size_t index = SolidSyslogPoolAllocator_AcquireFirstFree(&VxWorks64File_Allocator);
32 : 90 : struct SolidSyslogFile* handle = SolidSyslogNullFile_Get();
33 [ + + ]: 90 : if (SolidSyslogPoolAllocator_IndexIsValid(&VxWorks64File_Allocator, index) == true)
34 : : {
35 : 86 : SolidSyslogVxWorks64File_Initialise(&VxWorks64File_Pool[index].Base);
36 : 86 : handle = &VxWorks64File_Pool[index].Base;
37 : : }
38 : : else
39 : : {
40 : 4 : VxWorks64File_Report(
41 : : SOLIDSYSLOG_POOL_EXHAUSTED_SEVERITY,
42 : : SOLIDSYSLOG_CAT_POOL_EXHAUSTED,
43 : : SOLIDSYSLOG_FILE_ERROR_POOL_EXHAUSTED
44 : : );
45 : : }
46 : 90 : return handle;
47 : : }
48 : :
49 : 95 : void SolidSyslogVxWorks64File_Destroy(struct SolidSyslogFile* base)
50 : : {
51 : 95 : size_t index = VxWorks64File_IndexFromHandle(base);
52 : 95 : bool released =
53 [ + + + + ]: 182 : SolidSyslogPoolAllocator_IndexIsValid(&VxWorks64File_Allocator, index) &&
54 : 87 : SolidSyslogPoolAllocator_FreeIfInUse(&VxWorks64File_Allocator, index, VxWorks64File_CleanupAtIndex, NULL);
55 [ + + ]: 95 : if (!released)
56 : : {
57 : 9 : VxWorks64File_Report(
58 : : SOLIDSYSLOG_UNKNOWN_DESTROY_SEVERITY,
59 : : SOLIDSYSLOG_CAT_UNKNOWN_DESTROY,
60 : : SOLIDSYSLOG_FILE_ERROR_UNKNOWN_DESTROY
61 : : );
62 : : }
63 : 95 : }
64 : :
65 : 95 : static inline size_t VxWorks64File_IndexFromHandle(const struct SolidSyslogFile* base)
66 : : {
67 : 95 : size_t result = SOLIDSYSLOG_FILE_POOL_SIZE;
68 [ + + ]: 103 : for (size_t poolIndex = 0U; poolIndex < SOLIDSYSLOG_FILE_POOL_SIZE; poolIndex++)
69 : : {
70 [ + + ]: 95 : if (base == &VxWorks64File_Pool[poolIndex].Base)
71 : : {
72 : 87 : result = poolIndex;
73 : 87 : break;
74 : : }
75 : : }
76 : 95 : return result;
77 : : }
78 : :
79 : 86 : static inline void VxWorks64File_CleanupAtIndex(size_t index, void* context)
80 : : {
81 : : (void) context;
82 : 86 : SolidSyslogVxWorks64File_Cleanup(&VxWorks64File_Pool[index].Base);
83 : 86 : }
|