[beast: 56/95] BSE: port pcm device, pcm writer and storage to Rapicorn Mutex
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 56/95] BSE: port pcm device, pcm writer and storage to Rapicorn Mutex
- Date: Mon, 25 Mar 2013 00:41:12 +0000 (UTC)
commit 13b488a41606c55499d08a5c0cf1f235c9c4adec
Author: Tim Janik <timj gnu org>
Date: Wed Mar 20 02:57:44 2013 +0100
BSE: port pcm device, pcm writer and storage to Rapicorn Mutex
bse/bsepcmdevice.cc | 27 +++++++++++++++------------
bse/bsepcmdevice.hh | 2 +-
bse/bsepcmwriter.cc | 23 +++++++++++++----------
bse/bsepcmwriter.hh | 2 +-
4 files changed, 30 insertions(+), 24 deletions(-)
---
diff --git a/bse/bsepcmdevice.cc b/bse/bsepcmdevice.cc
index 6e3e543..44b2f81 100644
--- a/bse/bsepcmdevice.cc
+++ b/bse/bsepcmdevice.cc
@@ -44,20 +44,23 @@ bse_pcm_device_dispose (GObject *object)
/* chain parent class' handler */
G_OBJECT_CLASS (parent_class)->dispose (object);
}
+
static void
pcm_device_post_open (BseDevice *device)
{
BsePcmDevice *self = BSE_PCM_DEVICE (device);
g_return_if_fail (BSE_DEVICE_OPEN (self) && self->handle);
g_return_if_fail (BSE_DEVICE_OPEN (self) && self->handle->block_length == 0);
- sfi_mutex_init (&self->handle->mutex);
+ new (&self->handle->spinlock) Bse::Spinlock();
}
+
static void
pcm_device_pre_close (BseDevice *device)
{
BsePcmDevice *self = BSE_PCM_DEVICE (device);
- sfi_mutex_destroy (&self->handle->mutex);
+ self->handle->spinlock.~Spinlock();
}
+
guint
bse_pcm_device_get_mix_freq (BsePcmDevice *pdev)
{
@@ -74,10 +77,10 @@ bse_pcm_device_get_handle (BsePcmDevice *pdev,
g_return_val_if_fail (BSE_IS_PCM_DEVICE (pdev), NULL);
g_return_val_if_fail (BSE_DEVICE_OPEN (pdev), NULL);
g_return_val_if_fail (block_length > 0, NULL);
- GSL_SPIN_LOCK (&pdev->handle->mutex);
+ pdev->handle->spinlock.lock();
if (!pdev->handle->block_length)
pdev->handle->block_length = block_length;
- GSL_SPIN_UNLOCK (&pdev->handle->mutex);
+ pdev->handle->spinlock.unlock();
if (pdev->handle->block_length == block_length)
return pdev->handle;
else
@@ -92,9 +95,9 @@ bse_pcm_handle_read (BsePcmHandle *handle,
g_return_val_if_fail (handle != NULL, 0);
g_return_val_if_fail (handle->readable, 0);
g_return_val_if_fail (n_values == handle->block_length * handle->n_channels, 0);
- GSL_SPIN_LOCK (&handle->mutex);
+ handle->spinlock.lock();
n = handle->read (handle, values);
- GSL_SPIN_UNLOCK (&handle->mutex);
+ handle->spinlock.unlock();
g_return_val_if_fail (n == handle->block_length * handle->n_channels, n);
return n;
}
@@ -107,9 +110,9 @@ bse_pcm_handle_write (BsePcmHandle *handle,
g_return_if_fail (handle->writable);
g_return_if_fail (values != NULL);
g_return_if_fail (n_values == handle->block_length * handle->n_channels);
- GSL_SPIN_LOCK (&handle->mutex);
+ handle->spinlock.lock();
handle->write (handle, values);
- GSL_SPIN_UNLOCK (&handle->mutex);
+ handle->spinlock.unlock();
}
gboolean
bse_pcm_handle_check_io (BsePcmHandle *handle,
@@ -119,18 +122,18 @@ bse_pcm_handle_check_io (BsePcmHandle *handle,
glong dummy;
if (!timeoutp)
timeoutp = &dummy;
- GSL_SPIN_LOCK (&handle->mutex);
+ handle->spinlock.lock();
gboolean can_read_write = handle->check_io (handle, timeoutp);
- GSL_SPIN_UNLOCK (&handle->mutex);
+ handle->spinlock.unlock();
return can_read_write;
}
guint
bse_pcm_handle_latency (BsePcmHandle *handle)
{
g_return_val_if_fail (handle != NULL, 0);
- GSL_SPIN_LOCK (&handle->mutex);
+ handle->spinlock.lock();
guint n_frames = handle->latency (handle);
- GSL_SPIN_UNLOCK (&handle->mutex);
+ handle->spinlock.unlock();
return n_frames;
}
/* --- frequency utilities --- */
diff --git a/bse/bsepcmdevice.hh b/bse/bsepcmdevice.hh
index 4a4604c..17241dd 100644
--- a/bse/bsepcmdevice.hh
+++ b/bse/bsepcmdevice.hh
@@ -30,7 +30,7 @@ struct _BsePcmHandle
guint n_channels; /* should be req_n_channels */
guint mix_freq; /* should be req_mix_freq within 1% tolerance */
guint block_length; /* in frames, filled in after open() before i/o */
- BirnetMutex mutex;
+ Bse::Spinlock spinlock;
gsize (*read) (BsePcmHandle *handle,
gfloat *values); /* n_channels * block_length values */
void (*write) (BsePcmHandle *handle,
diff --git a/bse/bsepcmwriter.cc b/bse/bsepcmwriter.cc
index 5004acb..40c8e73 100644
--- a/bse/bsepcmwriter.cc
+++ b/bse/bsepcmwriter.cc
@@ -40,11 +40,13 @@ bse_pcm_writer_class_init (BsePcmWriterClass *klass)
parent_class = g_type_class_peek_parent (klass);
gobject_class->finalize = bse_pcm_writer_finalize;
}
+
static void
bse_pcm_writer_init (BsePcmWriter *self)
{
- sfi_mutex_init (&self->mutex);
+ new (&self->mutex) Bse::Mutex();
}
+
static void
bse_pcm_writer_finalize (GObject *object)
{
@@ -56,8 +58,9 @@ bse_pcm_writer_finalize (GObject *object)
}
/* chain parent class' handler */
G_OBJECT_CLASS (parent_class)->finalize (object);
- sfi_mutex_destroy (&self->mutex);
+ self->mutex.~Mutex();
}
+
BseErrorType
bse_pcm_writer_open (BsePcmWriter *self,
const gchar *file,
@@ -71,26 +74,26 @@ bse_pcm_writer_open (BsePcmWriter *self,
g_return_val_if_fail (file != NULL, BSE_ERROR_INTERNAL);
g_return_val_if_fail (n_channels > 0, BSE_ERROR_INTERNAL);
g_return_val_if_fail (sample_freq >= 1000, BSE_ERROR_INTERNAL);
- sfi_mutex_lock (&self->mutex);
+ self->mutex.lock();
self->n_bytes = 0;
self->recorded_maximum = recorded_maximum;
fd = open (file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0)
{
- sfi_mutex_unlock (&self->mutex);
+ self->mutex.unlock();
return bse_error_from_errno (errno, BSE_ERROR_FILE_OPEN_FAILED);
}
errno = bse_wave_file_dump_header (fd, 0x7fff0000, 16, n_channels, sample_freq);
if (errno)
{
close (fd);
- sfi_mutex_unlock (&self->mutex);
+ self->mutex.unlock();
return bse_error_from_errno (errno, BSE_ERROR_FILE_OPEN_FAILED);
}
self->fd = fd;
self->open = TRUE;
self->broken = FALSE;
- sfi_mutex_unlock (&self->mutex);
+ self->mutex.unlock();
return BSE_ERROR_NONE;
}
void
@@ -98,12 +101,12 @@ bse_pcm_writer_close (BsePcmWriter *self)
{
g_return_if_fail (BSE_IS_PCM_WRITER (self));
g_return_if_fail (self->open);
- sfi_mutex_lock (&self->mutex);
+ self->mutex.lock();
bse_wave_file_patch_length (self->fd, self->n_bytes);
close (self->fd);
self->fd = -1;
self->open = FALSE;
- sfi_mutex_unlock (&self->mutex);
+ self->mutex.unlock();
errno = 0;
}
static gboolean
@@ -123,7 +126,7 @@ bse_pcm_writer_write (BsePcmWriter *self,
g_return_if_fail (values != NULL);
else
return;
- sfi_mutex_lock (&self->mutex);
+ self->mutex.lock();
const uint bw = 2; /* 16bit */
if (!self->broken && (!self->recorded_maximum || self->n_bytes < bw * self->recorded_maximum))
{
@@ -152,5 +155,5 @@ bse_pcm_writer_write (BsePcmWriter *self,
self->broken = TRUE;
}
}
- sfi_mutex_unlock (&self->mutex);
+ self->mutex.unlock();
}
diff --git a/bse/bsepcmwriter.hh b/bse/bsepcmwriter.hh
index 12525e4..5def768 100644
--- a/bse/bsepcmwriter.hh
+++ b/bse/bsepcmwriter.hh
@@ -14,7 +14,7 @@ G_BEGIN_DECLS
struct _BsePcmWriter
{
BseItem parent_instance;
- BirnetMutex mutex;
+ Bse::Mutex mutex;
guint open : 1;
guint broken : 1;
gint fd;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]