libsysprof-capture: Port from GLib to pthreads for locking and once-init

Another step towards dropping the GLib dependency.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Helps: #40
This commit is contained in:
Philip Withnall
2020-07-02 12:28:08 +01:00
parent c89a47939e
commit 5a2144e254
3 changed files with 59 additions and 32 deletions

View File

@ -71,7 +71,7 @@
#include "sysprof-macros.h"
#ifdef _WIN32
static G_LOCK_DEFINE (_sysprof_io_sync);
static void *_sysprof_io_sync_lock = SRWLOCK_INIT;
#endif
size_t
@ -102,11 +102,11 @@ ssize_t
#ifdef _WIN32
ssize_t ret = -1;
G_LOCK (_sysprof_io_sync);
AcquireSRWLockExclusive (_sysprof_io_sync_lock);
errno = 0;
if (lseek (fd, offset, SEEK_SET) != -1)
ret = read (fd, buf, count);
G_UNLOCK (_sysprof_io_sync);
ReleaseSRWLockExclusive (_sysprof_io_sync_lock);
return ret;
#else
@ -124,11 +124,11 @@ ssize_t
#ifdef _WIN32
ssize_t ret = -1;
G_LOCK (_sysprof_io_sync);
AcquireSRWLockExclusive (_sysprof_io_sync_lock);
errno = 0;
if (lseek (fd, offset, SEEK_SET) != -1)
ret = write (fd, buf, count);
G_UNLOCK (_sysprof_io_sync);
ReleaseSRWLockExclusive (_sysprof_io_sync_lock);
return ret;
#else
@ -145,10 +145,10 @@ ssize_t
#ifdef _WIN32
ssize_t ret = -1;
G_LOCK (_sysprof_io_sync);
AcquireSRWLockExclusive (_sysprof_io_sync_lock);
errno = 0;
ret = write (fd, buf, count);
G_UNLOCK (_sysprof_io_sync);
ReleaseSRWLockExclusive (_sysprof_io_sync_lock);
return ret;
#else