Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Main
Synchronet
Commits
c26055da
Commit
c26055da
authored
4 years ago
by
Deucе
Browse files
Options
Downloads
Patches
Plain Diff
Use macros for all the atomic things.
parent
b4e6d685
No related branches found
No related tags found
1 merge request
!463
MRC mods by Codefenix (2024-10-20)
Pipeline
#1358
passed
4 years ago
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/sbbs3/main.cpp
+2
-2
2 additions, 2 deletions
src/sbbs3/main.cpp
src/xpdev/threadwrap.c
+1
-38
1 addition, 38 deletions
src/xpdev/threadwrap.c
src/xpdev/threadwrap.h
+26
-4
26 additions, 4 deletions
src/xpdev/threadwrap.h
with
29 additions
and
44 deletions
src/sbbs3/main.cpp
+
2
−
2
View file @
c26055da
...
...
@@ -57,8 +57,8 @@
lprintf
(
LOG_ERR
,
"%04d SSH Error %d destroying Cryptlib Session %d from line %d"
,
sock
,
result
,
session
,
line
);
else
{
int32_t
remain
=
protected_uint32_adjust
(
&
ssh_sessions
,
-
1
);
lprintf
(
LOG_DEBUG
,
"%04d SSH Cryptlib Session: %d destroyed from line %d (%
d
remain)"
u
int32_t
remain
=
protected_uint32_adjust
(
&
ssh_sessions
,
-
1
);
lprintf
(
LOG_DEBUG
,
"%04d SSH Cryptlib Session: %d destroyed from line %d (%
u
remain)"
,
sock
,
session
,
line
,
remain
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/threadwrap.c
+
1
−
38
View file @
c26055da
...
...
@@ -217,44 +217,7 @@ int DLLCALL pthread_mutex_destroy(pthread_mutex_t* mutex)
/* Protected (thread-safe) Integers (e.g. atomic/interlocked variables) */
/************************************************************************/
#ifdef __FreeBSD__
#define PROTECTED_TYPE_INIT(type) \
int DLLCALL protected_##type##_init(protected_##type##_t* prot, type##_t value) \
{ \
atomic_init(prot, value); \
return 0; \
}
PROTECTED_TYPE_INIT
(
int32
)
PROTECTED_TYPE_INIT
(
int64
)
PROTECTED_TYPE_INIT
(
uint32
)
PROTECTED_TYPE_INIT
(
uint64
)
#define PROTECTED_TYPE_SET(type) \
type##_t DLLCALL protected_##type##_set(protected_##type##_t* prot, type##_t value) \
{ \
atomic_store(prot, value); \
return value; \
}
PROTECTED_TYPE_SET
(
int32
)
PROTECTED_TYPE_SET
(
int64
)
PROTECTED_TYPE_SET
(
uint32
)
PROTECTED_TYPE_SET
(
uint64
)
#define PROTECTED_TYPE_ADJUST(type, adjtype) \
type##_t DLLCALL protected_##type##_adjust(protected_##type##_t* prot, adjtype##_t value) \
{ \
type##_t old = atomic_fetch_add(prot, value); \
return old + value; \
}
PROTECTED_TYPE_ADJUST
(
int32
,
int32
)
PROTECTED_TYPE_ADJUST
(
int64
,
int64
)
PROTECTED_TYPE_ADJUST
(
uint32
,
int32
)
PROTECTED_TYPE_ADJUST
(
uint64
,
int64
)
#else
#ifndef __FreeBSD__
int
DLLCALL
protected_int32_init
(
protected_int32_t
*
prot
,
int32_t
value
)
{
prot
->
value
=
value
;
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/threadwrap.h
+
26
−
4
View file @
c26055da
...
...
@@ -163,20 +163,41 @@ typedef std::atomic<int32_t> protected_int32_t;
typedef
std
::
atomic
<
uint32_t
>
protected_uint32_t
;
typedef
std
::
atomic
<
int64_t
>
protected_int64_t
;
typedef
std
::
atomic
<
uint64_t
>
protected_uint64_t
;
#define protected_int32_init(pval, val) (std::atomic_store<int32_t>(pval, val), 0)
#define protected_uint32_init(pval, val) (std::atomic_store<uint32_t>(pval, val), 0)
#define protected_int64_init(pval, val) (std::atomic_store<int64_t>(pval, val), 0)
#define protected_uint64_init(pval, val) (std::atomic_store<uint64_t>(pval, val), 0)
#define protected_int32_adjust(pval, adj) (std::atomic_fetch_add<int32_t>(pval, adj) + adj)
#define protected_uint32_adjust(pval, adj) (std::atomic_fetch_add<uint32_t>(pval, adj) + adj)
#define protected_int64_adjust(pval, adj) (std::atomic_fetch_add<int64_t>(pval, adj) + adj)
#define protected_uint64_adjust(pval, adj) (std::atomic_fetch_add<uint64_t>(pval, adj) + adj)
#define protected_int32_value(val) std::atomic_load<int32_t>(&val)
#define protected_uint32_value(val) std::atomic_load<uint32_t>(&val)
#define protected_int64_value(val) std::atomic_load<int64_t>(&val)
#define protected_uint64_value(val) std::atomic_load<uint64_t>(&val)
#else
typedef
_Atomic
(
int32_t
)
protected_int32_t
;
typedef
_Atomic
(
uint32_t
)
protected_uint32_t
;
typedef
_Atomic
(
int64_t
)
protected_int64_t
;
typedef
_Atomic
(
uint64_t
)
protected_uint64_t
;
#endif
DLLEXPORT
int
DLLCALL
protected_uint32_init
(
protected_uint32_t
*
,
uint32_t
value
);
DLLEXPORT
int
DLLCALL
protected_uint64_init
(
protected_uint64_t
*
,
uint64_t
value
);
#define protected_int32_init(pval, val) (atomic_init(pval, val), 0)
#define protected_uint32_init(pval, val) (atomic_init(pval, val), 0)
#define protected_int64_init(pval, val) (atomic_init(pval, val), 0)
#define protected_uint64_init(pval, val) (atomic_init(pval, val), 0)
#define protected_int32_adjust(pval, adj) (atomic_fetch_add(pval, adj) + adj)
#define protected_uint32_adjust(pval, adj) (atomic_fetch_add(pval, adj) + adj)
#define protected_int64_adjust(pval, adj) (atomic_fetch_add(pval, adj) + adj)
#define protected_uint64_adjust(pval, adj) (atomic_fetch_add(pval, adj) + adj)
#define protected_int32_value(val) atomic_load(&val)
#define protected_uint32_value(val) atomic_load(&val)
#define protected_int64_value(val) atomic_load(&val)
#define protected_uint64_value(val) atomic_load(&val)
#endif
#define protected_int32_destroy(i) 0
#define protected_uint32_destroy(i) 0
...
...
@@ -214,7 +235,6 @@ typedef struct {
#define protected_uint32_value(i) protected_uint32_adjust(&i,0)
#define protected_int64_value(i) protected_int64_adjust(&i,0)
#define protected_uint64_value(i) protected_uint64_adjust(&i,0)
#endif
/* Return 0 on success, non-zero on failure (see pthread_mutex_init): */
DLLEXPORT
int
DLLCALL
protected_int32_init
(
protected_int32_t
*
,
int32_t
value
);
...
...
@@ -230,6 +250,8 @@ DLLEXPORT int64_t DLLCALL protected_int64_set(protected_int64_t*, int64_t val);
DLLEXPORT
uint64_t
DLLCALL
protected_uint64_adjust
(
protected_uint64_t
*
,
int64_t
adjustment
);
DLLEXPORT
uint64_t
DLLCALL
protected_uint64_set
(
protected_uint64_t
*
,
uint64_t
adjustment
);
#endif
#if defined(__cplusplus)
}
#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