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
c0e45c61
Commit
c0e45c61
authored
9 years ago
by
deuce
Browse files
Options
Downloads
Patches
Plain Diff
Add a pthread_once() implementation for Win32 (untested on Win32).
parent
ebf1bda7
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/xpdev/threadwrap.c
+22
-0
22 additions, 0 deletions
src/xpdev/threadwrap.c
src/xpdev/threadwrap.h
+8
-0
8 additions, 0 deletions
src/xpdev/threadwrap.h
with
30 additions
and
0 deletions
src/xpdev/threadwrap.c
+
22
−
0
View file @
c0e45c61
...
...
@@ -126,6 +126,28 @@ pthread_mutex_t DLLCALL pthread_mutex_initializer_np(BOOL recursive)
#if !defined(_POSIX_THREADS)
int
DLLCALL
pthread_once
(
pthread_once_t
*
oc
,
void
(
*
init
)(
void
))
{
if
(
oc
==
NULL
||
init
==
NULL
)
return
EINVAL
;
switch
(
InterlockedCompareExchange
(
&
(
oc
->
state
),
1
,
0
))
{
case
0
:
// Never called
init
();
InterlockedIncrement
(
&
(
oc
->
state
));
return
0
;
case
1
:
// In init function
/* We may not need to use InterlockedCompareExchange() here,
* but I hate marking things as volatile, and hate tight loops
* testing things that aren't marked volatile.
*/
while
(
InterlockedCompareExchange
(
&
(
oc
->
state
),
1
,
0
)
!=
2
)
SLEEP
(
1
);
return
0
;
case
2
:
// Done.
return
0
;
}
}
int
DLLCALL
pthread_mutex_init
(
pthread_mutex_t
*
mutex
,
void
*
attr
)
{
(
void
)
attr
;
...
...
This diff is collapsed.
Click to expand it.
src/xpdev/threadwrap.h
+
8
−
0
View file @
c0e45c61
...
...
@@ -123,6 +123,14 @@ DLLEXPORT int DLLCALL pthread_mutex_destroy(pthread_mutex_t*);
#define SetThreadName(c)
// A structure in case we need to add an event or something...
typedef
struct
{
uint32_t
state
;
}
pthread_once_t
;
#define PTHREAD_ONCE_INIT {0};
DLLEXPORT
int
DLLCALL
pthread_once
(
pthread_once_t
*
oc
,
void
(
*
init
)(
void
));
#endif
#if !defined(PTHREAD_MUTEX_INITIALIZER_NP)
...
...
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