Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libcdi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
libcdi
Commits
fa384961
Commit
fa384961
authored
9 years ago
by
Thomas Jahns
Committed by
Sergey Kosukhin
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Make table of namespace switches dynamic.
parent
e6d18b05
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!34
Version 2.2.0
,
!13
Consolidation with CDI-PIO (develop)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/namespace.c
+53
-10
53 additions, 10 deletions
src/namespace.c
src/namespace.h
+4
-2
4 additions, 2 deletions
src/namespace.h
with
57 additions
and
12 deletions
src/namespace.c
+
53
−
10
View file @
fa384961
...
...
@@ -69,11 +69,14 @@ enum namespaceStatus
NAMESPACE_STATUS_UNUSED
,
};
static
union
namespaceSwitchValue
initialSwitches
[
NUM_NAMESPACE_SWITCH
]
=
defaultSwitches
;
static
struct
Namespace
{
enum
namespaceStatus
resStage
;
union
namespaceSwitchValue
switches
[
NUM_NAMESPACE_SWITCH
];
}
initialNamespace
=
{
.
resStage
=
NAMESPACE_STATUS_INUSE
,
.
switches
=
defaultSwitches
};
unsigned
numSwitches
;
union
namespaceSwitchValue
*
switches
;
}
initialNamespace
=
{
.
resStage
=
NAMESPACE_STATUS_INUSE
,
.
numSwitches
=
NUM_NAMESPACE_SWITCH
,
.
switches
=
initialSwitches
};
static
struct
Namespace
*
namespaces
=
&
initialNamespace
;
...
...
@@ -191,11 +194,16 @@ namespaceNew()
xassert
(
newNamespaceID
>=
0
&&
newNamespaceID
<
NUM_NAMESPACES
);
++
nNamespaces
;
namespaces
[
newNamespaceID
].
resStage
=
NAMESPACE_STATUS_INUSE
;
namespaces
[
newNamespaceID
].
numSwitches
=
NUM_NAMESPACE_SWITCH
;
enum
{
initialNSSWSize
=
sizeof
(
union
namespaceSwitchValue
)
*
NUM_NAMESPACE_SWITCH
};
namespaces
[
newNamespaceID
].
switches
=
(
union
namespaceSwitchValue
*
)
Malloc
(
initialNSSWSize
);
#if defined(SX) || defined(__cplusplus)
memcpy
(
namespaces
[
newNamespaceID
].
switches
,
defaultSwitches_
,
sizeof
(
namespaces
[
newNamespaceID
].
switches
)
);
memcpy
(
namespaces
[
newNamespaceID
].
switches
,
defaultSwitches_
,
initialNSSWSize
);
#else
memcpy
(
namespaces
[
newNamespaceID
].
switches
,
(
union
namespaceSwitchValue
[
NUM_NAMESPACE_SWITCH
])
defaultSwitches
,
sizeof
(
namespaces
[
newNamespaceID
].
switches
));
memcpy
(
namespaces
[
newNamespaceID
].
switches
,
(
union
namespaceSwitchValue
[
NUM_NAMESPACE_SWITCH
])
defaultSwitches
,
initialNSSWSize
);
#endif
reshListCreate
(
newNamespaceID
);
NAMESPACE_UNLOCK
();
...
...
@@ -209,6 +217,7 @@ namespaceDelete(int namespaceID)
NAMESPACE_LOCK
();
xassert
(
namespaceID
>=
0
&&
(
unsigned
)
namespaceID
<
namespacesSize
&&
nNamespaces
);
reshListDestruct
(
namespaceID
);
if
(
namespaces
[
namespaceID
].
switches
!=
initialSwitches
)
Free
(
namespaces
[
namespaceID
].
switches
);
namespaces
[
namespaceID
].
resStage
=
NAMESPACE_STATUS_UNUSED
;
--
nNamespaces
;
NAMESPACE_UNLOCK
();
...
...
@@ -268,19 +277,53 @@ namespaceAdaptKey2(int originResH)
}
void
namespaceSwitchSet
(
enum
namespaceSwitch
sw
,
union
namespaceSwitchValue
value
)
namespaceSwitchSet
(
int
sw
,
union
namespaceSwitchValue
value
)
{
xassert
(
sw
>
NSSWITCH_NO_SUCH_SWITCH
&&
sw
<
NUM_NAMESPACE_SWITCH
);
xassert
(
sw
>
NSSWITCH_NO_SUCH_SWITCH
);
int
nsp
=
namespaceGetActive
();
NAMESPACE_LOCK
();
if
(
namespaces
[
nsp
].
numSwitches
<=
(
unsigned
)
sw
)
{
if
(
namespaces
[
nsp
].
switches
!=
initialSwitches
)
namespaces
[
nsp
].
switches
=
(
union
namespaceSwitchValue
*
)
Realloc
(
namespaces
[
nsp
].
switches
,
((
unsigned
)
sw
+
1
)
*
sizeof
value
);
else
{
void
*
temp
=
Malloc
(((
unsigned
)
sw
+
1
)
*
sizeof
value
);
memcpy
(
temp
,
(
void
*
)
namespaces
[
nsp
].
switches
,
namespaces
[
nsp
].
numSwitches
*
sizeof
value
);
namespaces
[
nsp
].
switches
=
(
union
namespaceSwitchValue
*
)
temp
;
}
namespaces
[
nsp
].
numSwitches
=
(
unsigned
)
sw
+
1
;
}
namespaces
[
nsp
].
switches
[
sw
]
=
value
;
NAMESPACE_UNLOCK
();
}
union
namespaceSwitchValue
namespaceSwitchGet
(
enum
namespaceSwitch
sw
)
namespaceSwitchGet
(
int
sw
)
{
xassert
(
sw
>
NSSWITCH_NO_SUCH_SWITCH
&&
sw
<
NUM_NAMESPACE_SWITCH
);
int
nsp
=
namespaceGetActive
();
return
namespaces
[
nsp
].
switches
[
sw
];
xassert
(
sw
>
NSSWITCH_NO_SUCH_SWITCH
&&
(
unsigned
)
sw
<
namespaces
[
nsp
].
numSwitches
);
NAMESPACE_LOCK
();
union
namespaceSwitchValue
sw_val
=
namespaces
[
nsp
].
switches
[
sw
];
NAMESPACE_UNLOCK
();
return
sw_val
;
}
int
cdiNamespaceSwitchNewKey
(
void
)
{
static
unsigned
reservedKeys
=
0
;
#if defined(HAVE_LIBPTHREAD)
static
pthread_mutex_t
keyMutex
=
PTHREAD_MUTEX_INITIALIZER
;
pthread_mutex_lock
(
&
keyMutex
);
#endif
if
(
reservedKeys
>=
INT_MAX
-
NUM_NAMESPACE_SWITCH
-
1
)
Error
(
"pool of available namespace switch keys exhausted!"
);
int
newKey
=
(
int
)
(
reservedKeys
++
)
+
NUM_NAMESPACE_SWITCH
;
#if defined(HAVE_LIBPTHREAD)
pthread_mutex_unlock
(
&
keyMutex
);
#endif
return
newKey
;
}
void
...
...
This diff is collapsed.
Click to expand it.
src/namespace.h
+
4
−
2
View file @
fa384961
...
...
@@ -61,8 +61,10 @@ int namespaceIdxEncode2(int, int);
namespaceTuple_t
namespaceResHDecode
(
int
);
int
namespaceAdaptKey
(
int
originResH
,
int
originNamespace
);
int
namespaceAdaptKey2
(
int
);
void
namespaceSwitchSet
(
enum
namespaceSwitch
sw
,
union
namespaceSwitchValue
value
);
union
namespaceSwitchValue
namespaceSwitchGet
(
enum
namespaceSwitch
sw
);
void
namespaceSwitchSet
(
int
sw
,
union
namespaceSwitchValue
value
);
union
namespaceSwitchValue
namespaceSwitchGet
(
int
sw
);
/* reserve new dynamic key */
int
cdiNamespaceSwitchNewKey
(
void
);
#endif
/*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment