Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
miniaudio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
miniaudio
Commits
59feeafc
Commit
59feeafc
authored
Oct 19, 2016
by
David Reid
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some infrastructure for better thread-safety.
parent
9698068d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
0 deletions
+99
-0
mini_al.h
mini_al.h
+99
-0
No files found.
mini_al.h
View file @
59feeafc
...
@@ -98,9 +98,11 @@ typedef void* mal_ptr;
...
@@ -98,9 +98,11 @@ typedef void* mal_ptr;
#ifdef MAL_WIN32
#ifdef MAL_WIN32
typedef
mal_handle
mal_thread
;
typedef
mal_handle
mal_thread
;
typedef
mal_handle
mal_mutex
;
typedef
mal_handle
mal_event
;
typedef
mal_handle
mal_event
;
#else
#else
typedef
pthread_t
mal_thread
;
typedef
pthread_t
mal_thread
;
typedef
pthread_mutex_t
mal_mutex
;
typedef
struct
typedef
struct
{
{
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
...
@@ -209,6 +211,7 @@ struct mal_device
...
@@ -209,6 +211,7 @@ struct mal_device
mal_send_proc
onSend
;
mal_send_proc
onSend
;
mal_log_proc
onLog
;
mal_log_proc
onLog
;
void
*
pUserData
;
// Application defined data.
void
*
pUserData
;
// Application defined data.
mal_mutex
lock
;
mal_event
wakeupEvent
;
mal_event
wakeupEvent
;
mal_event
startEvent
;
mal_event
startEvent
;
mal_event
stopEvent
;
mal_event
stopEvent
;
...
@@ -763,6 +766,32 @@ void mal_sleep__win32(mal_uint32 milliseconds)
...
@@ -763,6 +766,32 @@ void mal_sleep__win32(mal_uint32 milliseconds)
}
}
mal_bool32
mal_mutex_create__win32
(
mal_mutex
*
pMutex
)
{
*
pMutex
=
CreateEventA
(
NULL
,
FALSE
,
TRUE
,
NULL
);
if
(
*
pMutex
==
NULL
)
{
return
DR_FALSE
;
}
return
DR_TRUE
;
}
void
mal_mutex_delete__win32
(
mal_mutex
*
pMutex
)
{
CloseHandle
(
*
pMutex
);
}
void
mal_mutex_lock__win32
(
mal_mutex
*
pMutex
)
{
WaitForSingleObject
(
*
pMutex
,
INFINITE
);
}
void
mal_mutex_unlock__win32
(
mal_mutex
*
pMutex
)
{
SetEvent
(
*
pMutex
);
}
mal_bool32
mal_event_create__win32
(
mal_event
*
pEvent
)
mal_bool32
mal_event_create__win32
(
mal_event
*
pEvent
)
{
{
*
pEvent
=
CreateEventW
(
NULL
,
FALSE
,
FALSE
,
NULL
);
*
pEvent
=
CreateEventW
(
NULL
,
FALSE
,
FALSE
,
NULL
);
...
@@ -807,6 +836,27 @@ void mal_sleep__posix(mal_uint32 milliseconds)
...
@@ -807,6 +836,27 @@ void mal_sleep__posix(mal_uint32 milliseconds)
}
}
mal_bool32
mal_mutex_create__posix
(
mal_mutex
*
pMutex
)
{
return
pthread_mutex_init
(
pMutex
,
NULL
)
==
0
;
}
void
mal_mutex_delete__posix
(
mal_mutex
*
pMutex
)
{
pthread_mutex_destroy
(
pMutex
);
}
void
mal_mutex_lock__posix
(
mal_mutex
*
pMutex
)
{
pthread_mutex_lock
(
pMutex
);
}
void
mal_mutex_unlock__posix
(
mal_mutex
*
pMutex
)
{
pthread_mutex_unlock
(
pMutex
);
}
mal_bool32
mal_event_create__posix
(
mal_event
*
pEvent
)
mal_bool32
mal_event_create__posix
(
mal_event
*
pEvent
)
{
{
if
(
pthread_mutex_init
(
&
pEvent
->
mutex
,
NULL
)
!=
0
)
{
if
(
pthread_mutex_init
(
&
pEvent
->
mutex
,
NULL
)
!=
0
)
{
...
@@ -890,6 +940,55 @@ void mal_sleep(mal_uint32 milliseconds)
...
@@ -890,6 +940,55 @@ void mal_sleep(mal_uint32 milliseconds)
}
}
mal_bool32
mal_mutex_create
(
mal_mutex
*
pMutex
)
{
if
(
pMutex
==
NULL
)
return
MAL_FALSE
;
#ifdef MAL_WIN32
return
mal_mutex_create__win32
(
pMutex
);
#endif
#ifdef MAL_POSIX
return
mal_mutex_create__posix
(
pMutex
);
#endif
}
void
mal_mutex_delete
(
mal_mutex
*
pMutex
)
{
if
(
pMutex
==
NULL
)
return
;
#ifdef MAL_WIN32
mal_mutex_delete__win32
(
pMutex
);
#endif
#ifdef MAL_POSIX
mal_mutex_delete__posix
(
pMutex
);
#endif
}
void
mal_mutex_lock
(
mal_mutex
*
pMutex
)
{
if
(
pMutex
==
NULL
)
return
;
#ifdef MAL_WIN32
mal_mutex_lock__win32
(
pMutex
);
#endif
#ifdef MAL_POSIX
mal_mutex_lock__posix
(
pMutex
);
#endif
}
void
mal_mutex_unlock
(
mal_mutex
*
pMutex
)
{
if
(
pMutex
==
NULL
)
return
;
#ifdef MAL_WIN32
mal_mutex_unlock__win32
(
pMutex
);
#endif
#ifdef MAL_POSIX
mal_mutex_unlock__posix
(
pMutex
);
#endif
}
mal_bool32
mal_event_create
(
mal_event
*
pEvent
)
mal_bool32
mal_event_create
(
mal_event
*
pEvent
)
{
{
if
(
pEvent
==
NULL
)
return
MAL_FALSE
;
if
(
pEvent
==
NULL
)
return
MAL_FALSE
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment