CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
ssdshared.h
1#pragma once
2
3#include <cx/thread/rwlock.h>
4#include <cx/meta/block.h>
6
7#if DEBUG_LEVEL > 1
8#define SSD_LOCK_DEBUG 1
9#endif
10
11typedef struct SSDTree SSDTree;
12typedef struct SSDNode SSDNode;
13typedef SSDNode *(*SSDNodeFactory)(SSDTree *info);
14
17
22
32
34
35typedef struct SSDLockDebug {
36 int64 time;
37 const char *file;
38 int32 line;
39} SSDLockDebug;
40saDeclare(SSDLockDebug);
41
42typedef struct SSDLockState
43{
44 union {
45 bool _is_SSDLockState;
46 bool init; // lock state structure initialized
47 };
48 bool rdlock; // read lock held by current thread
49 bool wrlock; // write lock held by current thread
50#ifdef SSD_LOCK_DEBUG
51 SSDLockDebug dbg;
52#endif
53} SSDLockState;
54
55enum SSD_LOCK_STATE_ENUM {
56 _ssdCurrentLockState = 0
57};
58
59// Initializes a lock structure
60#ifdef SSD_LOCK_DEBUG
61SSDLockState *__ssdLockStateInit(_Out_ SSDLockState *lstate, _In_z_ const char *fn, int lnum);
62#define _ssdLockStateInit(lstate) __ssdLockStateInit(lstate, __FILE__, __LINE__)
63#else
64SSDLockState *_ssdLockStateInit(_Out_ SSDLockState *lstate);
65#endif
66
80
97#ifdef SSD_LOCK_DEBUG
98#define ssdLockRead(root) _ssdLockRead(SSDNode(root), (SSDLockState*)&_ssdCurrentLockState->_is_SSDLockState, __FILE__, __LINE__)
99#define _ssdManualLockRead(root, lstate) _ssdLockRead(SSDNode(root), lstate, __FILE__, __LINE__)
100bool _ssdLockRead(_Inout_ SSDNode *root, _Inout_ SSDLockState *lstate, _In_z_ const char *fn, int lnum);
101#else
102#define ssdLockRead(root) _ssdLockRead(SSDNode(root), _ssdCurrentLockState)
103#define _ssdManualLockRead(root, lstate) _ssdLockRead(SSDNode(root), lstate)
104bool _ssdLockRead(_Inout_ SSDNode *root, _Inout_ SSDLockState *lstate);
105#endif
106
127#ifdef SSD_LOCK_DEBUG
128#define ssdLockWrite(root) _ssdLockWrite(SSDNode(root), (SSDLockState*)&_ssdCurrentLockState->_is_SSDLockState, __FILE__, __LINE__)
129#define _ssdManualLockWrite(root, lstate) _ssdLockWrite(SSDNode(root), lstate, __FILE__, __LINE__)
130bool _ssdLockWrite(_Inout_ SSDNode *root, _Inout_ SSDLockState *lstate, _In_z_ const char *fn, int lnum);
131#else
132#define ssdLockWrite(root) _ssdLockWrite(SSDNode(root), _ssdCurrentLockState)
133#define _ssdManualLockWrite(root, lstate) _ssdLockWrite(SSDNode(root), lstate)
134bool _ssdLockWrite(_Inout_ SSDNode *root, _Inout_ SSDLockState *lstate);
135#endif
136
147#define ssdUnlock(root) _ssdUnlock(SSDNode(root), (SSDLockState*)&_ssdCurrentLockState->_is_SSDLockState)
148bool _ssdUnlock(_Inout_ SSDNode *root, _Inout_ SSDLockState *lstate);
149
159#define ssdLockEnd(root) _ssdLockEnd(SSDNode(root), (SSDLockState*)&_ssdCurrentLockState->_is_SSDLockState)
160bool _ssdLockEnd(_Inout_ SSDNode *root, _Inout_ SSDLockState *lstate);
161
186#define ssdLockedTransaction(root) _blkStart \
187 _inhibitReturn \
188 _blkFull(SSDLockState _ssdTransientLockState = { 0 }, (root), \
189 _ssdLockEnd(SSDNode(root), &_ssdTransientLockState)) \
190 _blkBefore(SSDLockState *_ssdCurrentLockStateShadow = (SSDLockState*)_ssdCurrentLockState) \
191 _blkBefore(SSDLockState *_ssdCurrentLockState = _ssdCurrentLockStateShadow ? \
192 _ssdCurrentLockStateShadow : _ssdLockStateInit(&_ssdTransientLockState)) \
193 _blkEnd
194
Block wrapping macros for automatic resource management.
#define saDeclare(name)
Definition sarray.h:91
enum SSD_CREATE_TYPE_ENUM SSDCreateType
Node creation types for specifying which kind of node to create.
SSD_CREATE_TYPE_ENUM
Node creation types for specifying which kind of node to create.
Definition ssdshared.h:24
SSD_FLAGS_ENUM
Flags for configuring SSD tree behavior.
Definition ssdshared.h:19
@ SSD_Create_Single
Create a single-value node.
Definition ssdshared.h:28
@ SSD_Create_Array
Create an array (indexed) node.
Definition ssdshared.h:27
@ SSD_Create_Hashtable
Create a hashtable (key-value) node.
Definition ssdshared.h:26
@ SSD_Create_None
Do not create a node.
Definition ssdshared.h:25
@ SSD_Create_Count
Total number of creation types (internal use)
Definition ssdshared.h:30
@ SSD_CaseInsensitive
Keys in hashtables are case-insensitive.
Definition ssdshared.h:20
Reader-writer lock synchronization primitive.
Dynamic arrays with type-safe generic programming.