aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2020-12-14 15:44:28 +0100
committerDavid Robillard <d@drobilla.net>2020-12-14 15:44:28 +0100
commit9226bfc74fa6580bbcec428e6291fb81cefe4e42 (patch)
tree7783a54207e94e95448a5a5278fb29c460aa3190
parent3b6afde09317b4d79ffb8a65cb49d525fc7b4101 (diff)
downloadjalv-9226bfc74fa6580bbcec428e6291fb81cefe4e42.tar.gz
jalv-9226bfc74fa6580bbcec428e6291fb81cefe4e42.tar.bz2
jalv-9226bfc74fa6580bbcec428e6291fb81cefe4e42.zip
Update zix
-rw-r--r--src/jalv.c2
-rw-r--r--src/jalv_gtk.c24
-rw-r--r--src/state.c10
-rw-r--r--src/worker.c2
-rw-r--r--src/zix/common.h57
-rw-r--r--src/zix/ring.c49
-rw-r--r--src/zix/ring.h13
-rw-r--r--src/zix/sem.h8
-rw-r--r--src/zix/thread.h20
9 files changed, 104 insertions, 81 deletions
diff --git a/src/jalv.c b/src/jalv.c
index 9ed09af..8f90ed3 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -712,7 +712,7 @@ jalv_apply_control_arg(Jalv* jalv, const char* s)
}
static void
-signal_handler(ZIX_UNUSED int sig)
+signal_handler(int ZIX_UNUSED(sig))
{
zix_sem_post(exit_sem);
}
diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c
index 2cdaf23..a3d2e74 100644
--- a/src/jalv_gtk.c
+++ b/src/jalv_gtk.c
@@ -98,7 +98,7 @@ size_request(GtkWidget* widget, GtkRequisition* req)
}
static void
-on_window_destroy(ZIX_UNUSED GtkWidget* widget, ZIX_UNUSED gpointer data)
+on_window_destroy(GtkWidget* ZIX_UNUSED(widget), gpointer ZIX_UNUSED(data))
{
gtk_main_quit();
}
@@ -162,7 +162,7 @@ jalv_native_ui_type(void)
}
static void
-on_save_activate(ZIX_UNUSED GtkWidget* widget, void* ptr)
+on_save_activate(GtkWidget* ZIX_UNUSED(widget), void* ptr)
{
Jalv* jalv = (Jalv*)ptr;
GtkWidget* dialog = gtk_file_chooser_dialog_new(
@@ -185,7 +185,7 @@ on_save_activate(ZIX_UNUSED GtkWidget* widget, void* ptr)
}
static void
-on_quit_activate(ZIX_UNUSED GtkWidget* widget, gpointer data)
+on_quit_activate(GtkWidget* ZIX_UNUSED(widget), gpointer data)
{
GtkWidget* window = (GtkWidget*)data;
gtk_widget_destroy(window);
@@ -244,7 +244,7 @@ on_preset_activate(GtkWidget* widget, gpointer data)
}
static void
-on_preset_destroy(gpointer data, ZIX_UNUSED GClosure* closure)
+on_preset_destroy(gpointer data, GClosure* ZIX_UNUSED(closure))
{
PresetRecord* record = (PresetRecord*)data;
lilv_node_free(record->preset);
@@ -287,7 +287,7 @@ pset_menu_free(PresetMenu* menu)
}
static gint
-menu_cmp(gconstpointer a, gconstpointer b, ZIX_UNUSED gpointer data)
+menu_cmp(gconstpointer a, gconstpointer b, gpointer ZIX_UNUSED(data))
{
return strcmp(((const PresetMenu*)a)->label, ((const PresetMenu*)b)->label);
}
@@ -542,10 +542,10 @@ set_float_control(const ControlID* control, float value)
}
static double
-get_atom_double(Jalv* jalv,
- ZIX_UNUSED uint32_t size,
- LV2_URID type,
- const void* body)
+get_atom_double(Jalv* jalv,
+ uint32_t ZIX_UNUSED(size),
+ LV2_URID type,
+ const void* body)
{
if (type == jalv->forge.Int || type == jalv->forge.Bool) {
return *(const int32_t*)body;
@@ -1052,7 +1052,7 @@ add_control_row(GtkWidget* table,
}
static int
-control_group_cmp(const void* p1, const void* p2, ZIX_UNUSED void* data)
+control_group_cmp(const void* p1, const void* p2, void* ZIX_UNUSED(data))
{
const ControlID* control1 = *(const ControlID*const*)p1;
const ControlID* control2 = *(const ControlID*const*)p2;
@@ -1202,7 +1202,7 @@ build_menu(Jalv* jalv, GtkWidget* window, GtkWidget* vbox)
}
bool
-jalv_discover_ui(ZIX_UNUSED Jalv* jalv)
+jalv_discover_ui(Jalv* ZIX_UNUSED(jalv))
{
return TRUE;
}
@@ -1296,7 +1296,7 @@ jalv_open_ui(Jalv* jalv)
}
int
-jalv_close_ui(ZIX_UNUSED Jalv* jalv)
+jalv_close_ui(Jalv* ZIX_UNUSED(jalv))
{
gtk_main_quit();
return 0;
diff --git a/src/state.c b/src/state.c
index 6c35b96..4237d54 100644
--- a/src/state.c
+++ b/src/state.c
@@ -120,11 +120,11 @@ jalv_unload_presets(Jalv* jalv)
}
static void
-set_port_value(const char* port_symbol,
- void* user_data,
- const void* value,
- ZIX_UNUSED uint32_t size,
- uint32_t type)
+set_port_value(const char* port_symbol,
+ void* user_data,
+ const void* value,
+ uint32_t ZIX_UNUSED(size),
+ uint32_t type)
{
Jalv* jalv = (Jalv*)user_data;
struct Port* port = jalv_port_by_symbol(jalv, port_symbol);
diff --git a/src/worker.c b/src/worker.c
index 3ad3078..db970a5 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -70,7 +70,7 @@ worker_func(void* data)
}
void
-jalv_worker_init(ZIX_UNUSED Jalv* jalv,
+jalv_worker_init(Jalv* ZIX_UNUSED(jalv),
JalvWorker* worker,
const LV2_Worker_Interface* iface,
bool threaded)
diff --git a/src/zix/common.h b/src/zix/common.h
index 9318d0e..f7ec4c3 100644
--- a/src/zix/common.h
+++ b/src/zix/common.h
@@ -17,6 +17,8 @@
#ifndef ZIX_COMMON_H
#define ZIX_COMMON_H
+#include <stdbool.h>
+
/**
@addtogroup zix
@{
@@ -44,18 +46,40 @@
# define ZIX_API
# define ZIX_PRIVATE static
#endif
+
+#ifdef __GNUC__
+# define ZIX_PURE_FUNC __attribute__((pure))
+# define ZIX_CONST_FUNC __attribute__((const))
+# define ZIX_MALLOC_FUNC __attribute__((malloc))
+#else
+# define ZIX_PURE_FUNC
+# define ZIX_CONST_FUNC
+# define ZIX_MALLOC_FUNC
+#endif
+
+#define ZIX_PURE_API ZIX_API ZIX_PURE_FUNC
+#define ZIX_CONST_API ZIX_API ZIX_CONST_FUNC
+#define ZIX_MALLOC_API ZIX_API ZIX_MALLOC_FUNC
+
/** @endcond */
#ifdef __cplusplus
extern "C" {
-#else
-# include <stdbool.h>
#endif
#ifdef __GNUC__
-#define ZIX_UNUSED __attribute__((__unused__))
+#define ZIX_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1)))
+#else
+#define ZIX_LOG_FUNC(fmt, arg1)
+#endif
+
+// Unused parameter macro to suppresses warnings and make it impossible to use
+#if defined(__cplusplus)
+# define ZIX_UNUSED(name)
+#elif defined(__GNUC__)
+# define ZIX_UNUSED(name) name##_unused __attribute__((__unused__))
#else
-#define ZIX_UNUSED
+# define ZIX_UNUSED(name) name
#endif
typedef enum {
@@ -72,20 +96,13 @@ static inline const char*
zix_strerror(const ZixStatus status)
{
switch (status) {
- case ZIX_STATUS_SUCCESS:
- return "Success";
- case ZIX_STATUS_ERROR:
- return "Unknown error";
- case ZIX_STATUS_NO_MEM:
- return "Out of memory";
- case ZIX_STATUS_NOT_FOUND:
- return "Not found";
- case ZIX_STATUS_EXISTS:
- return "Exists";
- case ZIX_STATUS_BAD_ARG:
- return "Bad argument";
- case ZIX_STATUS_BAD_PERMS:
- return "Bad permissions";
+ case ZIX_STATUS_SUCCESS: return "Success";
+ case ZIX_STATUS_ERROR: return "Unknown error";
+ case ZIX_STATUS_NO_MEM: return "Out of memory";
+ case ZIX_STATUS_NOT_FOUND: return "Not found";
+ case ZIX_STATUS_EXISTS: return "Exists";
+ case ZIX_STATUS_BAD_ARG: return "Bad argument";
+ case ZIX_STATUS_BAD_PERMS: return "Bad permissions";
}
return "Unknown error";
}
@@ -93,7 +110,9 @@ zix_strerror(const ZixStatus status)
/**
Function for comparing two elements.
*/
-typedef int (*ZixComparator)(const void* a, const void* b, void* user_data);
+typedef int (*ZixComparator)(const void* a,
+ const void* b,
+ const void* user_data);
/**
Function for testing equality of two elements.
diff --git a/src/zix/ring.c b/src/zix/ring.c
index 6af9e07..cdbcea8 100644
--- a/src/zix/ring.c
+++ b/src/zix/ring.c
@@ -1,5 +1,5 @@
/*
- Copyright 2011-2017 David Robillard <http://drobilla.net>
+ Copyright 2011 David Robillard <http://drobilla.net>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
@@ -16,6 +16,9 @@
#include "zix/ring.h"
+#include <stdlib.h>
+#include <string.h>
+
#ifdef HAVE_MLOCK
# include <sys/mman.h>
# define ZIX_MLOCK(ptr, size) mlock((ptr), (size))
@@ -27,31 +30,19 @@
# define ZIX_MLOCK(ptr, size)
#endif
-#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
-# include <stdatomic.h>
-# define ZIX_WRITE_BARRIER() atomic_thread_fence(memory_order_release)
-# define ZIX_READ_BARRIER() atomic_thread_fence(memory_order_acquire)
-#elif defined(__APPLE__) /* Pre 10.12 */
-# include <libkern/OSAtomic.h>
-# define ZIX_WRITE_BARRIER() OSMemoryBarrier()
-# define ZIX_READ_BARRIER() OSMemoryBarrier()
-#elif defined(_WIN32)
+#if defined(_MSC_VER)
# include <windows.h>
-# define ZIX_WRITE_BARRIER() MemoryBarrier()
# define ZIX_READ_BARRIER() MemoryBarrier()
-#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
-# define ZIX_WRITE_BARRIER() __sync_synchronize()
-# define ZIX_READ_BARRIER() __sync_synchronize()
+# define ZIX_WRITE_BARRIER() MemoryBarrier()
+#elif defined(__GNUC__)
+# define ZIX_READ_BARRIER() __atomic_thread_fence(__ATOMIC_ACQUIRE)
+# define ZIX_WRITE_BARRIER() __atomic_thread_fence(__ATOMIC_RELEASE)
#else
# pragma message("warning: No memory barriers, possible SMP bugs")
-# define ZIX_WRITE_BARRIER()
# define ZIX_READ_BARRIER()
+# define ZIX_WRITE_BARRIER()
#endif
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-
struct ZixRingImpl {
uint32_t write_head; ///< Read index into buf
uint32_t read_head; ///< Write index into buf
@@ -65,11 +56,11 @@ next_power_of_two(uint32_t size)
{
// http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
size--;
- size |= size >> 1;
- size |= size >> 2;
- size |= size >> 4;
- size |= size >> 8;
- size |= size >> 16;
+ size |= size >> 1u;
+ size |= size >> 2u;
+ size |= size >> 4u;
+ size |= size >> 8u;
+ size |= size >> 16u;
size++;
return size;
}
@@ -89,10 +80,8 @@ zix_ring_new(uint32_t size)
void
zix_ring_free(ZixRing* ring)
{
- if (ring) {
- free(ring->buf);
- free(ring);
- }
+ free(ring->buf);
+ free(ring);
}
void
@@ -184,9 +173,9 @@ zix_ring_read(ZixRing* ring, void* dst, uint32_t size)
ZIX_READ_BARRIER();
ring->read_head = (r + size) & ring->size_mask;
return size;
- } else {
- return 0;
}
+
+ return 0;
}
uint32_t
diff --git a/src/zix/ring.h b/src/zix/ring.h
index 168f009..de18561 100644
--- a/src/zix/ring.h
+++ b/src/zix/ring.h
@@ -17,6 +17,8 @@
#ifndef ZIX_RING_H
#define ZIX_RING_H
+#include "zix/common.h"
+
#include <stdint.h>
#ifdef __cplusplus
@@ -44,12 +46,14 @@ typedef struct ZixRingImpl ZixRing;
At most `size` - 1 bytes may be stored in the ring at once.
*/
+ZIX_MALLOC_API
ZixRing*
zix_ring_new(uint32_t size);
/**
Destroy a ring.
*/
+ZIX_API
void
zix_ring_free(ZixRing* ring);
@@ -62,6 +66,7 @@ zix_ring_free(ZixRing* ring);
ring to be truly real-time safe).
*/
+ZIX_API
void
zix_ring_mlock(ZixRing* ring);
@@ -71,48 +76,56 @@ zix_ring_mlock(ZixRing* ring);
This function is NOT thread-safe, it may only be called when there are no
readers or writers.
*/
+ZIX_API
void
zix_ring_reset(ZixRing* ring);
/**
Return the number of bytes of space available for reading.
*/
+ZIX_CONST_API
uint32_t
zix_ring_read_space(const ZixRing* ring);
/**
Return the number of bytes of space available for writing.
*/
+ZIX_CONST_API
uint32_t
zix_ring_write_space(const ZixRing* ring);
/**
Return the capacity (i.e. total write space when empty).
*/
+ZIX_CONST_API
uint32_t
zix_ring_capacity(const ZixRing* ring);
/**
Read from the ring without advancing the read head.
*/
+ZIX_API
uint32_t
zix_ring_peek(ZixRing* ring, void* dst, uint32_t size);
/**
Read from the ring and advance the read head.
*/
+ZIX_API
uint32_t
zix_ring_read(ZixRing* ring, void* dst, uint32_t size);
/**
Skip data in the ring (advance read head without reading).
*/
+ZIX_API
uint32_t
zix_ring_skip(ZixRing* ring, uint32_t size);
/**
Write data to the ring.
*/
+ZIX_API
uint32_t
zix_ring_write(ZixRing* ring, const void* src, uint32_t size);
diff --git a/src/zix/sem.h b/src/zix/sem.h
index e306052..faeb148 100644
--- a/src/zix/sem.h
+++ b/src/zix/sem.h
@@ -25,14 +25,16 @@
# include <limits.h>
# include <windows.h>
#else
-# include <semaphore.h>
# include <errno.h>
+# include <semaphore.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
+#include <stdbool.h>
+
/**
@addtogroup zix
@{
@@ -40,6 +42,8 @@ extern "C" {
@{
*/
+struct ZixSemImpl;
+
/**
A counting semaphore.
@@ -148,7 +152,7 @@ static inline ZixStatus
zix_sem_init(ZixSem* sem, unsigned initial)
{
sem->sem = CreateSemaphore(NULL, initial, LONG_MAX, NULL);
- return (sem->sem) ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS;
+ return (sem->sem) ? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR;
}
static inline void
diff --git a/src/zix/thread.h b/src/zix/thread.h
index 5802c99..3989f13 100644
--- a/src/zix/thread.h
+++ b/src/zix/thread.h
@@ -26,10 +26,10 @@
# include <pthread.h>
#endif
+#include <stddef.h>
+
#ifdef __cplusplus
extern "C" {
-#else
-# include <stdbool.h>
#endif
/**
@@ -80,6 +80,8 @@ zix_thread_create(ZixThread* thread,
static inline ZixStatus
zix_thread_join(ZixThread thread, void** retval)
{
+ (void)retval;
+
return WaitForSingleObject(thread, INFINITE)
? ZIX_STATUS_SUCCESS : ZIX_STATUS_ERROR;
}
@@ -99,17 +101,13 @@ zix_thread_create(ZixThread* thread,
const int ret = pthread_create(thread, NULL, function, arg);
pthread_attr_destroy(&attr);
- if (ret == EAGAIN) {
- return ZIX_STATUS_NO_MEM;
- } else if (ret == EINVAL) {
- return ZIX_STATUS_BAD_ARG;
- } else if (ret == EPERM) {
- return ZIX_STATUS_BAD_PERMS;
- } else if (ret) {
- return ZIX_STATUS_ERROR;
+ switch (ret) {
+ case EAGAIN: return ZIX_STATUS_NO_MEM;
+ case EINVAL: return ZIX_STATUS_BAD_ARG;
+ case EPERM: return ZIX_STATUS_BAD_PERMS;
}
- return ZIX_STATUS_SUCCESS;
+ return ret ? ZIX_STATUS_ERROR : ZIX_STATUS_SUCCESS;
}
static inline ZixStatus