hdb: move functions into cfile

convert int -> int32_t
rename qb_hdb_handle_t -> qb_handle_t
rename DECLARE_HDB_DATABASE -> QB_HDB_DECLARE
rename qb_hdb_handle_database -> qb_hdb

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2010-06-16 09:12:20 +10:00
parent 87f204469a
commit b8a5a74fcc
23 changed files with 488 additions and 494 deletions

View File

@ -31,39 +31,39 @@ extern "C" {
#endif
/* *INDENT-ON* */
int32_t qb_hash_initialize(qb_hdb_handle_t * handle,
int32_t qb_hash_initialize(qb_handle_t * handle,
uint32_t order, uint32_t context_size);
int32_t qb_hash_key_set(qb_hdb_handle_t handle,
int32_t qb_hash_key_set(qb_handle_t handle,
const char *key, const void *value, uint32_t value_len);
int32_t qb_hash_key_get(qb_hdb_handle_t handle,
int32_t qb_hash_key_get(qb_handle_t handle,
const char *key, void **value, uint64_t * value_len);
int32_t qb_hash_key_context_get(qb_hdb_handle_t handle,
int32_t qb_hash_key_context_get(qb_handle_t handle,
const char *key, void **context);
int32_t qb_hash_key_delete(qb_hdb_handle_t handle, const char *key);
int32_t qb_hash_key_delete(qb_handle_t handle, const char *key);
int32_t qb_hash_edge_create(qb_hdb_handle_t handle,
int32_t qb_hash_edge_create(qb_handle_t handle,
const char *source_key,
const char *dest_key, const char *edge_name);
int32_t qb_hash_edge_destroy(qb_hdb_handle_t handle,
int32_t qb_hash_edge_destroy(qb_handle_t handle,
const char *source_key,
const char *dest_key, const char *edge_name);
int32_t qb_hash_edge_follow(qb_hdb_handle_t handle,
int32_t qb_hash_edge_follow(qb_handle_t handle,
const char *source_key,
const char *edge_name, char **dest_key);
int32_t qb_hash_edge_value_set(qb_hdb_handle_t handle,
int32_t qb_hash_edge_value_set(qb_handle_t handle,
const char *source_key,
const char *dest_key,
const char *edge_name,
const void *edge_value, uint64_t edge_value_len);
int32_t qb_hash_edge_value_get(qb_hdb_handle_t handle,
int32_t qb_hash_edge_value_get(qb_handle_t handle,
const char *source_key,
const char *dest_key,
const char *edge_name,

View File

@ -26,16 +26,12 @@
#define _GNU_SOURCE
#endif
#include <errno.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
#include <stdint.h>
#include <inttypes.h>
#include <qb/qbutil.h>
typedef uint64_t qb_hdb_handle_t;
typedef uint64_t qb_handle_t;
/*
* Formatting for string printing on 32/64 bit systems
@ -43,375 +39,46 @@ typedef uint64_t qb_hdb_handle_t;
#define QB_HDB_D_FORMAT "%"PRIu64
#define QB_HDB_X_FORMAT "%"PRIx64
enum QB_HDB_HANDLE_STATE {
QB_HDB_HANDLE_STATE_EMPTY,
QB_HDB_HANDLE_STATE_PENDINGREMOVAL,
QB_HDB_HANDLE_STATE_ACTIVE
};
struct qb_hdb_handle {
int state;
int32_t state;
void *instance;
int check;
int ref_count;
int32_t check;
int32_t ref_count;
};
struct qb_hdb_handle_database {
unsigned int handle_count;
struct qb_hdb {
uint32_t handle_count;
struct qb_hdb_handle *handles;
unsigned int iterator;
uint32_t iterator;
void (*destructor) (void *);
qb_thread_lock_t *lock;
unsigned int first_run;
uint32_t first_run;
};
#define DECLARE_HDB_DATABASE(database_name,destructor_function) \
static struct qb_hdb_handle_database (database_name) = { \
#define QB_HDB_DECLARE(database_name,destructor_function) \
static struct qb_hdb (database_name) = { \
.handle_count = 0, \
.handles = NULL, \
.handles = NULL, \
.iterator = 0, \
.destructor = destructor_function, \
.first_run = 1 \
}; \
static inline void qb_hdb_create(struct qb_hdb_handle_database *handle_database)
{
memset(handle_database, 0, sizeof(struct qb_hdb_handle_database));
handle_database->lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
static inline void qb_hdb_destroy(struct qb_hdb_handle_database
*handle_database)
{
free(handle_database->handles);
qb_thread_lock_destroy(handle_database->lock);
memset(handle_database, 0, sizeof(struct qb_hdb_handle_database));
}
static inline int qb_hdb_handle_create(struct qb_hdb_handle_database
*handle_database, int instance_size,
qb_hdb_handle_t * handle_id_out)
{
int handle;
unsigned int check;
void *new_handles;
int found = 0;
void *instance;
int i;
if (handle_database->first_run == 1) {
handle_database->first_run = 0;
handle_database->lock =
qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(handle_database->lock);
for (handle = 0; handle < handle_database->handle_count; handle++) {
if (handle_database->handles[handle].state ==
QB_HDB_HANDLE_STATE_EMPTY) {
found = 1;
break;
}
}
if (found == 0) {
handle_database->handle_count += 1;
new_handles =
(struct qb_hdb_handle *)realloc(handle_database->handles,
sizeof(struct qb_hdb_handle)
*
handle_database->
handle_count);
if (new_handles == NULL) {
qb_thread_unlock(handle_database->lock);
errno = ENOMEM;
return (-1);
}
handle_database->handles = new_handles;
}
instance = (void *)malloc(instance_size);
if (instance == 0) {
errno = ENOMEM;
return (-1);
}
/*
* This code makes sure the random number isn't zero
* We use 0 to specify an invalid handle out of the 1^64 address space
* If we get 0 200 times in a row, the RNG may be broken
*/
for (i = 0; i < 200; i++) {
check = random();
if (check != 0 && check != 0xffffffff) {
break;
}
}
memset(instance, 0, instance_size);
handle_database->handles[handle].state = QB_HDB_HANDLE_STATE_ACTIVE;
handle_database->handles[handle].instance = instance;
handle_database->handles[handle].ref_count = 1;
handle_database->handles[handle].check = check;
*handle_id_out = (((unsigned long long)(check)) << 32) | handle;
qb_thread_unlock(handle_database->lock);
return (0);
}
static inline int qb_hdb_handle_get(struct qb_hdb_handle_database
*handle_database, qb_hdb_handle_t handle_in,
void **instance)
{
unsigned int check =
((unsigned int)(((unsigned long long)handle_in) >> 32));
unsigned int handle = handle_in & 0xffffffff;
if (handle_database->first_run == 1) {
handle_database->first_run = 0;
handle_database->lock =
qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(handle_database->lock);
*instance = NULL;
if (handle >= handle_database->handle_count) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
if (handle_database->handles[handle].state !=
QB_HDB_HANDLE_STATE_ACTIVE) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff &&
check != handle_database->handles[handle].check) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
*instance = handle_database->handles[handle].instance;
handle_database->handles[handle].ref_count += 1;
qb_thread_unlock(handle_database->lock);
return (0);
}
static inline int qb_hdb_handle_get_always(struct qb_hdb_handle_database
*handle_database,
qb_hdb_handle_t handle_in,
void **instance)
{
unsigned int check =
((unsigned int)(((unsigned long long)handle_in) >> 32));
unsigned int handle = handle_in & 0xffffffff;
if (handle_database->first_run == 1) {
handle_database->first_run = 0;
handle_database->lock =
qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(handle_database->lock);
*instance = NULL;
if (handle >= handle_database->handle_count) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
if (handle_database->handles[handle].state == QB_HDB_HANDLE_STATE_EMPTY) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff &&
check != handle_database->handles[handle].check) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
*instance = handle_database->handles[handle].instance;
handle_database->handles[handle].ref_count += 1;
qb_thread_unlock(handle_database->lock);
return (0);
}
static inline int qb_hdb_handle_put(struct qb_hdb_handle_database
*handle_database, qb_hdb_handle_t handle_in)
{
unsigned int check =
((unsigned int)(((unsigned long long)handle_in) >> 32));
unsigned int handle = handle_in & 0xffffffff;
if (handle_database->first_run == 1) {
handle_database->first_run = 0;
handle_database->lock =
qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(handle_database->lock);
if (handle >= handle_database->handle_count) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff &&
check != handle_database->handles[handle].check) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
handle_database->handles[handle].ref_count -= 1;
assert(handle_database->handles[handle].ref_count >= 0);
if (handle_database->handles[handle].ref_count == 0) {
if (handle_database->destructor) {
handle_database->destructor(handle_database->
handles[handle].instance);
}
free(handle_database->handles[handle].instance);
memset(&handle_database->handles[handle], 0,
sizeof(struct qb_hdb_handle));
}
qb_thread_unlock(handle_database->lock);
return (0);
}
static inline int qb_hdb_handle_destroy(struct qb_hdb_handle_database
*handle_database,
qb_hdb_handle_t handle_in)
{
unsigned int check =
((unsigned int)(((unsigned long long)handle_in) >> 32));
unsigned int handle = handle_in & 0xffffffff;
int res;
if (handle_database->first_run == 1) {
handle_database->first_run = 0;
handle_database->lock =
qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(handle_database->lock);
if (handle >= handle_database->handle_count) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff &&
check != handle_database->handles[handle].check) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
handle_database->handles[handle].state =
QB_HDB_HANDLE_STATE_PENDINGREMOVAL;
qb_thread_unlock(handle_database->lock);
res = qb_hdb_handle_put(handle_database, handle_in);
return (res);
}
static inline int qb_hdb_handle_refcount_get(struct qb_hdb_handle_database
*handle_database,
qb_hdb_handle_t handle_in)
{
unsigned int check =
((unsigned int)(((unsigned long long)handle_in) >> 32));
unsigned int handle = handle_in & 0xffffffff;
int refcount = 0;
if (handle_database->first_run == 1) {
handle_database->first_run = 0;
handle_database->lock =
qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(handle_database->lock);
if (handle >= handle_database->handle_count) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff &&
check != handle_database->handles[handle].check) {
qb_thread_unlock(handle_database->lock);
errno = EBADF;
return (-1);
}
refcount = handle_database->handles[handle].ref_count;
qb_thread_unlock(handle_database->lock);
return (refcount);
}
static inline void qb_hdb_iterator_reset(struct qb_hdb_handle_database
*handle_database)
{
handle_database->iterator = 0;
}
static inline int qb_hdb_iterator_next(struct qb_hdb_handle_database
*handle_database, void **instance,
qb_hdb_handle_t * handle)
{
int res = -1;
while (handle_database->iterator < handle_database->handle_count) {
*handle =
((unsigned long
long)(handle_database->handles[handle_database->iterator].
check) << 32) | handle_database->iterator;
res = qb_hdb_handle_get(handle_database, *handle, instance);
handle_database->iterator += 1;
if (res == 0) {
break;
}
}
return (res);
}
static inline unsigned int qb_hdb_base_convert(qb_hdb_handle_t handle)
{
return (handle & 0xffffffff);
}
static inline unsigned long long qb_hdb_nocheck_convert(unsigned int handle)
{
unsigned long long retvalue = 0xffffffffULL << 32 | handle;
return (retvalue);
}
void qb_hdb_create(struct qb_hdb *hdb);
void qb_hdb_destroy(struct qb_hdb *hdb);
int32_t qb_hdb_handle_create(struct qb_hdb *hdb, int32_t instance_size,
qb_handle_t * handle_id_out);
int32_t qb_hdb_handle_get(struct qb_hdb *hdb, qb_handle_t handle_in,
void **instance);
int32_t qb_hdb_handle_get_always(struct qb_hdb *hdb, qb_handle_t handle_in,
void **instance);
int32_t qb_hdb_handle_put(struct qb_hdb *hdb, qb_handle_t handle_in);
int32_t qb_hdb_handle_destroy(struct qb_hdb *hdb, qb_handle_t handle_in);
int32_t qb_hdb_handle_refcount_get(struct qb_hdb *hdb, qb_handle_t handle_in);
void qb_hdb_iterator_reset(struct qb_hdb *hdb);
int32_t qb_hdb_iterator_next(struct qb_hdb *hdb, void **instance,
qb_handle_t * handle);
uint32_t qb_hdb_base_convert(qb_handle_t handle);
uint64_t qb_hdb_nocheck_convert(uint32_t handle);
#endif /* QB_HDB_H_DEFINED */

View File

@ -39,45 +39,43 @@ qb_ipcc_service_connect(const char *socket_name,
uint32_t service,
size_t request_size,
size_t respnse__size,
size_t dispatch_size, qb_hdb_handle_t * handle);
size_t dispatch_size, qb_handle_t * handle);
int32_t qb_ipcc_service_disconnect(qb_hdb_handle_t handle);
int32_t qb_ipcc_service_disconnect(qb_handle_t handle);
int32_t qb_ipcc_fd_get(qb_hdb_handle_t handle, int32_t * fd);
int32_t qb_ipcc_fd_get(qb_handle_t handle, int32_t * fd);
int32_t qb_ipcc_dispatch_get(qb_hdb_handle_t handle, void **buf,
int32_t timeout);
int32_t qb_ipcc_dispatch_get(qb_handle_t handle, void **buf, int32_t timeout);
int32_t qb_ipcc_dispatch_put(qb_hdb_handle_t handle);
int32_t qb_ipcc_dispatch_put(qb_handle_t handle);
int32_t
qb_ipcc_dispatch_flow_control_get(qb_hdb_handle_t handle,
qb_ipcc_dispatch_flow_control_get(qb_handle_t handle,
uint32_t * flow_control_state);
int32_t
qb_ipcc_msg_send(qb_hdb_handle_t handle,
const struct iovec *iov, uint32_t iov_len);
qb_ipcc_msg_send(qb_handle_t handle, const struct iovec *iov, uint32_t iov_len);
int32_t
qb_ipcc_msg_send_reply_receive(qb_hdb_handle_t handle,
qb_ipcc_msg_send_reply_receive(qb_handle_t handle,
const struct iovec *iov,
uint32_t iov_len, void *res_msg, size_t res_len);
int32_t
qb_ipcc_msg_send_reply_receive_in_buf_get(qb_hdb_handle_t handle,
qb_ipcc_msg_send_reply_receive_in_buf_get(qb_handle_t handle,
const struct iovec *iov,
uint32_t iov_len, void **res_msg);
int32_t qb_ipcc_msg_send_reply_receive_in_buf_put(qb_hdb_handle_t handle);
int32_t qb_ipcc_msg_send_reply_receive_in_buf_put(qb_handle_t handle);
int32_t
qb_ipcc_zcb_alloc(qb_hdb_handle_t handle,
qb_ipcc_zcb_alloc(qb_handle_t handle,
void **buffer, size_t size, size_t header_size);
int32_t qb_ipcc_zcb_free(qb_hdb_handle_t handle, void *buffer);
int32_t qb_ipcc_zcb_free(qb_handle_t handle, void *buffer);
int32_t
qb_ipcc_zcb_msg_send_reply_receive(qb_hdb_handle_t handle,
qb_ipcc_zcb_msg_send_reply_receive(qb_handle_t handle,
void *msg, void *res_msg, size_t res_len);
/* *INDENT-OFF* */

View File

@ -61,16 +61,14 @@ struct qb_ipcs_init_state {
qb_ipcs_exit_fn_lvalue(*exit_fn_get) (uint32_t service);
qb_ipcs_handler_fn_lvalue(*handler_fn_get) (uint32_t service,
uint32_t id);
qb_hdb_handle_t(*stats_create_connection) (const char *name, pid_t pid,
qb_handle_t(*stats_create_connection) (const char *name, pid_t pid,
int32_t fd);
void (*stats_destroy_connection) (qb_hdb_handle_t handle);
void (*stats_update_value) (qb_hdb_handle_t handle,
void (*stats_destroy_connection) (qb_handle_t handle);
void (*stats_update_value) (qb_handle_t handle,
const char *name, const void *value,
size_t value_len);
void (*stats_increment_value) (qb_hdb_handle_t handle,
const char *name);
void (*stats_decrement_value) (qb_hdb_handle_t handle,
const char *name);
void (*stats_increment_value) (qb_handle_t handle, const char *name);
void (*stats_decrement_value) (qb_handle_t handle, const char *name);
};
void qb_ipcs_ipc_init(struct qb_ipcs_init_state *init_state);

View File

@ -28,11 +28,11 @@ extern "C" {
#endif
/* *INDENT-ON* */
int plugin_ifact_reference(qb_hdb_handle_t * handle,
int plugin_ifact_reference(qb_handle_t * handle,
const char *iface_name,
int version, void **interface, void *context);
int plugin_ifact_release(qb_hdb_handle_t handle);
int plugin_ifact_release(qb_handle_t handle);
/* *INDENT-OFF* */

View File

@ -32,37 +32,36 @@ extern "C" {
typedef void *qb_poll_timer_handle;
qb_hdb_handle_t qb_poll_create(void);
qb_handle_t qb_poll_create(void);
int qb_poll_destroy(qb_hdb_handle_t hdb_handle);
int qb_poll_destroy(qb_handle_t hdb_handle);
int qb_poll_dispatch_add(qb_hdb_handle_t handle,
int qb_poll_dispatch_add(qb_handle_t handle,
int fd,
int events,
void *data,
int (*dispatch_fn) (qb_hdb_handle_t handle,
int (*dispatch_fn) (qb_handle_t handle,
int fd, int revents, void *data));
int qb_poll_dispatch_modify(qb_hdb_handle_t handle,
int qb_poll_dispatch_modify(qb_handle_t handle,
int fd,
int events,
int (*dispatch_fn) (qb_hdb_handle_t hdb_handle_t,
int (*dispatch_fn) (qb_handle_t hdb_handle_t,
int fd,
int revents, void *data));
int qb_poll_dispatch_delete(qb_hdb_handle_t handle, int fd);
int qb_poll_dispatch_delete(qb_handle_t handle, int fd);
int qb_poll_timer_add(qb_hdb_handle_t handle,
int qb_poll_timer_add(qb_handle_t handle,
int msec_in_future, void *data,
void (*timer_fn) (void *data),
qb_poll_timer_handle * timer_handle_out);
int qb_poll_timer_delete(qb_hdb_handle_t handle,
qb_poll_timer_handle timer_handle);
int qb_poll_timer_delete(qb_handle_t handle, qb_poll_timer_handle timer_handle);
int qb_poll_run(qb_hdb_handle_t handle);
int qb_poll_run(qb_handle_t handle);
int qb_poll_stop(qb_hdb_handle_t handle);
int qb_poll_stop(qb_handle_t handle);
/* *INDENT-OFF* */
#ifdef __cplusplus

View File

@ -130,7 +130,7 @@ void qb_rb_close(qb_ringbuffer_t * rb);
* @param rb ringbuffer instance
* @return name.
*/
char* qb_rb_name_get(qb_ringbuffer_t * rb);
char *qb_rb_name_get(qb_ringbuffer_t * rb);
/**
* Write a chunk to the ring buffer.
@ -183,7 +183,8 @@ int32_t qb_rb_chunk_commit(qb_ringbuffer_t * rb, size_t len);
*
* @return the size of the chunk (0 if buffer empty).
*/
ssize_t qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out, int32_t ms_timeout);
ssize_t qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out,
int32_t ms_timeout);
/**
* Reclaim the oldest chunk.

View File

@ -44,7 +44,8 @@ lib_LTLIBRARIES = libqb.la
libqb_la_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
libqb_la_LDFLAGS = -version-info 0:0:0
libqb_la_SOURCES = util.c tsafe.c hash.c poll.c timer.c wthread.c \
ipcc.c ipcs.c logsys.c ringbuffer.c ringbuffer_helper.c
ipcc.c ipcs.c logsys.c ringbuffer.c ringbuffer_helper.c \
hdb.c
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libqb.pc

View File

@ -32,7 +32,7 @@
#define FNV_32_PRIME ((uint32_t)0x01000193)
DECLARE_HDB_DATABASE(qb_hash_handle_db, NULL);
QB_HDB_DECLARE(qb_hash_handle_db, NULL);
struct hash_node {
struct qb_list_head list;
@ -70,7 +70,7 @@ static uint32_t hash_fnv(const void *value, uint32_t valuelen, uint32_t order)
return (res);
}
int32_t qb_hash_initialize(qb_hdb_handle_t * handle,
int32_t qb_hash_initialize(qb_handle_t * handle,
uint32_t order, uint32_t context_size)
{
struct hash_table *hash_table;
@ -113,7 +113,7 @@ hash_destroy:
return (-1);
}
int32_t qb_hash_key_set(qb_hdb_handle_t handle,
int32_t qb_hash_key_set(qb_handle_t handle,
const char *key, const void *value, uint32_t value_len)
{
struct hash_table *hash_table;
@ -177,7 +177,7 @@ error_exit:
return (res);
}
int32_t qb_hash_key_get(qb_hdb_handle_t handle,
int32_t qb_hash_key_get(qb_handle_t handle,
const char *key, void **value, uint64_t * value_len)
{
struct hash_table *hash_table;
@ -218,7 +218,7 @@ unlock_exit:
return (res);
}
int32_t qb_hash_key_delete(qb_hdb_handle_t handle, const char *key)
int32_t qb_hash_key_delete(qb_handle_t handle, const char *key)
{
struct hash_table *hash_table;
struct qb_list_head *list;
@ -258,7 +258,7 @@ unlock_exit:
return (res);
}
int32_t qb_hash_key_context_get(qb_hdb_handle_t handle,
int32_t qb_hash_key_context_get(qb_handle_t handle,
const char *key, void **context)
{
struct hash_table *hash_table;

334
lib/hdb.c Normal file
View File

@ -0,0 +1,334 @@
/*
* Copyright (C) 2006-2010 Red Hat, Inc.
*
* Author: Steven Dake <sdake@redhat.com>
*
* This file is part of libqb.
*
* libqb is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* libqb is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libqb. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os_base.h"
#include <qb/qbutil.h>
#include <qb/qbhdb.h>
enum QB_HDB_HANDLE_STATE {
QB_HDB_HANDLE_STATE_EMPTY,
QB_HDB_HANDLE_STATE_PENDINGREMOVAL,
QB_HDB_HANDLE_STATE_ACTIVE
};
void qb_hdb_create(struct qb_hdb *hdb)
{
memset(hdb, 0, sizeof(struct qb_hdb));
hdb->lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
void qb_hdb_destroy(struct qb_hdb
*hdb)
{
free(hdb->handles);
qb_thread_lock_destroy(hdb->lock);
memset(hdb, 0, sizeof(struct qb_hdb));
}
int32_t qb_hdb_handle_create(struct qb_hdb *hdb, int32_t instance_size,
qb_handle_t * handle_id_out)
{
int32_t handle;
uint32_t check;
void *new_handles;
int32_t found = 0;
void *instance;
int32_t i;
if (hdb->first_run == 1) {
hdb->first_run = 0;
hdb->lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(hdb->lock);
for (handle = 0; handle < hdb->handle_count; handle++) {
if (hdb->handles[handle].state == QB_HDB_HANDLE_STATE_EMPTY) {
found = 1;
break;
}
}
if (found == 0) {
hdb->handle_count += 1;
new_handles = realloc(hdb->handles,
sizeof(struct qb_hdb_handle) *
hdb->handle_count);
if (new_handles == NULL) {
qb_thread_unlock(hdb->lock);
errno = ENOMEM;
return (-1);
}
hdb->handles = new_handles;
}
instance = malloc(instance_size);
if (instance == 0) {
errno = ENOMEM;
return (-1);
}
/*
* This code makes sure the random number isn't zero
* We use 0 to specify an invalid handle out of the 1^64 address space
* If we get 0 200 times in a row, the RNG may be broken
*/
for (i = 0; i < 200; i++) {
check = random();
if (check != 0 && check != 0xffffffff) {
break;
}
}
memset(instance, 0, instance_size);
hdb->handles[handle].state = QB_HDB_HANDLE_STATE_ACTIVE;
hdb->handles[handle].instance = instance;
hdb->handles[handle].ref_count = 1;
hdb->handles[handle].check = check;
*handle_id_out = (((uint64_t) (check)) << 32) | handle;
qb_thread_unlock(hdb->lock);
return (0);
}
int32_t qb_hdb_handle_get(struct qb_hdb * hdb, qb_handle_t handle_in,
void **instance)
{
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
if (hdb->first_run == 1) {
hdb->first_run = 0;
hdb->lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(hdb->lock);
*instance = NULL;
if (handle >= hdb->handle_count) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
if (hdb->handles[handle].state != QB_HDB_HANDLE_STATE_ACTIVE) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff && check != hdb->handles[handle].check) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
*instance = hdb->handles[handle].instance;
hdb->handles[handle].ref_count += 1;
qb_thread_unlock(hdb->lock);
return (0);
}
int32_t qb_hdb_handle_get_always(struct qb_hdb * hdb, qb_handle_t handle_in,
void **instance)
{
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
if (hdb->first_run == 1) {
hdb->first_run = 0;
hdb->lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(hdb->lock);
*instance = NULL;
if (handle >= hdb->handle_count) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
if (hdb->handles[handle].state == QB_HDB_HANDLE_STATE_EMPTY) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff && check != hdb->handles[handle].check) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
*instance = hdb->handles[handle].instance;
hdb->handles[handle].ref_count += 1;
qb_thread_unlock(hdb->lock);
return (0);
}
int32_t qb_hdb_handle_put(struct qb_hdb * hdb, qb_handle_t handle_in)
{
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
if (hdb->first_run == 1) {
hdb->first_run = 0;
hdb->lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(hdb->lock);
if (handle >= hdb->handle_count) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff && check != hdb->handles[handle].check) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
hdb->handles[handle].ref_count -= 1;
assert(hdb->handles[handle].ref_count >= 0);
if (hdb->handles[handle].ref_count == 0) {
if (hdb->destructor) {
hdb->destructor(hdb->handles[handle].instance);
}
free(hdb->handles[handle].instance);
memset(&hdb->handles[handle], 0, sizeof(struct qb_hdb_handle));
}
qb_thread_unlock(hdb->lock);
return (0);
}
int32_t qb_hdb_handle_destroy(struct qb_hdb * hdb, qb_handle_t handle_in)
{
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
int32_t res;
if (hdb->first_run == 1) {
hdb->first_run = 0;
hdb->lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(hdb->lock);
if (handle >= hdb->handle_count) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff && check != hdb->handles[handle].check) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
hdb->handles[handle].state = QB_HDB_HANDLE_STATE_PENDINGREMOVAL;
qb_thread_unlock(hdb->lock);
res = qb_hdb_handle_put(hdb, handle_in);
return (res);
}
int32_t qb_hdb_handle_refcount_get(struct qb_hdb * hdb, qb_handle_t handle_in)
{
uint32_t check = ((uint32_t) (((uint64_t) handle_in) >> 32));
uint32_t handle = handle_in & 0xffffffff;
int32_t refcount = 0;
if (hdb->first_run == 1) {
hdb->first_run = 0;
hdb->lock = qb_thread_lock_create(QB_THREAD_LOCK_SHORT);
}
qb_thread_lock(hdb->lock);
if (handle >= hdb->handle_count) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
if (check != 0xffffffff && check != hdb->handles[handle].check) {
qb_thread_unlock(hdb->lock);
errno = EBADF;
return (-1);
}
refcount = hdb->handles[handle].ref_count;
qb_thread_unlock(hdb->lock);
return (refcount);
}
void qb_hdb_iterator_reset(struct qb_hdb
*hdb)
{
hdb->iterator = 0;
}
int32_t qb_hdb_iterator_next(struct qb_hdb *hdb, void **instance,
qb_handle_t * handle)
{
int32_t res = -1;
uint64_t checker;
while (hdb->iterator < hdb->handle_count) {
checker = (uint64_t) (hdb->handles[hdb->iterator].check);
*handle = (checker << 32) | hdb->iterator;
res = qb_hdb_handle_get(hdb, *handle, instance);
hdb->iterator += 1;
if (res == 0) {
break;
}
}
return (res);
}
uint32_t qb_hdb_base_convert(qb_handle_t handle)
{
return (handle & 0xffffffff);
}
uint64_t qb_hdb_nocheck_convert(uint32_t handle)
{
uint64_t retvalue = 0xffffffffULL << 32 | handle;
return (retvalue);
}

View File

@ -62,7 +62,7 @@ struct ipc_instance {
void ipc_hdb_destructor(void *context);
DECLARE_HDB_DATABASE(ipc_hdb, ipc_hdb_destructor);
QB_HDB_DECLARE(ipc_hdb, ipc_hdb_destructor);
#if defined(QB_LINUX) || defined(QB_SOLARIS)
#define QB_SUN_LEN(a) sizeof(*(a))
@ -515,7 +515,7 @@ qb_ipcc_service_connect(const char *socket_name,
uint32_t service,
size_t request_size,
size_t response_size,
size_t dispatch_size, qb_hdb_handle_t * handle)
size_t dispatch_size, qb_handle_t * handle)
{
int32_t request_fd;
struct sockaddr_un address;
@ -718,7 +718,7 @@ error_connect:
return (res);
}
int32_t qb_ipcc_service_disconnect(qb_hdb_handle_t handle)
int32_t qb_ipcc_service_disconnect(qb_handle_t handle)
{
int32_t res;
struct ipc_instance *ipc_instance;
@ -736,7 +736,7 @@ int32_t qb_ipcc_service_disconnect(qb_hdb_handle_t handle)
}
int32_t
qb_ipcc_dispatch_flow_control_get(qb_hdb_handle_t handle,
qb_ipcc_dispatch_flow_control_get(qb_handle_t handle,
uint32_t * flow_control_state)
{
struct ipc_instance *ipc_instance;
@ -753,7 +753,7 @@ qb_ipcc_dispatch_flow_control_get(qb_hdb_handle_t handle,
return (res);
}
int32_t qb_ipcc_fd_get(qb_hdb_handle_t handle, int32_t * fd)
int32_t qb_ipcc_fd_get(qb_handle_t handle, int32_t * fd)
{
struct ipc_instance *ipc_instance;
int32_t res;
@ -769,8 +769,7 @@ int32_t qb_ipcc_fd_get(qb_hdb_handle_t handle, int32_t * fd)
return (res);
}
int32_t qb_ipcc_dispatch_get(qb_hdb_handle_t handle, void **data,
int32_t timeout)
int32_t qb_ipcc_dispatch_get(qb_handle_t handle, void **data, int32_t timeout)
{
struct pollfd ufds;
int32_t poll_events;
@ -861,7 +860,7 @@ error_put:
return (error);
}
int32_t qb_ipcc_dispatch_put(qb_hdb_handle_t handle)
int32_t qb_ipcc_dispatch_put(qb_handle_t handle)
{
qb_ipc_response_header_t *header;
struct ipc_instance *ipc_instance;
@ -898,8 +897,7 @@ error_exit:
}
int32_t
qb_ipcc_msg_send(qb_hdb_handle_t handle,
const struct iovec * iov, uint32_t iov_len)
qb_ipcc_msg_send(qb_handle_t handle, const struct iovec * iov, uint32_t iov_len)
{
int32_t res;
struct ipc_instance *ipc_instance;
@ -920,7 +918,7 @@ qb_ipcc_msg_send(qb_hdb_handle_t handle,
}
int32_t
qb_ipcc_msg_send_reply_receive(qb_hdb_handle_t handle,
qb_ipcc_msg_send_reply_receive(qb_handle_t handle,
const struct iovec * iov,
uint32_t iov_len, void *res_msg, size_t res_len)
{
@ -949,7 +947,7 @@ error_exit:
}
int32_t
qb_ipcc_msg_send_reply_receive_in_buf_get(qb_hdb_handle_t handle,
qb_ipcc_msg_send_reply_receive_in_buf_get(qb_handle_t handle,
const struct iovec * iov,
uint32_t iov_len, void **res_msg)
{
@ -976,7 +974,7 @@ error_exit:
return (res);
}
int32_t qb_ipcc_msg_send_reply_receive_in_buf_put(qb_hdb_handle_t handle)
int32_t qb_ipcc_msg_send_reply_receive_in_buf_put(qb_handle_t handle)
{
int32_t res;
struct ipc_instance *ipc_instance;
@ -992,7 +990,7 @@ int32_t qb_ipcc_msg_send_reply_receive_in_buf_put(qb_hdb_handle_t handle)
}
int32_t
qb_ipcc_zcb_alloc(qb_hdb_handle_t handle,
qb_ipcc_zcb_alloc(qb_handle_t handle,
void **buffer, size_t size, size_t header_size)
{
struct ipc_instance *ipc_instance;
@ -1035,7 +1033,7 @@ qb_ipcc_zcb_alloc(qb_hdb_handle_t handle,
return (res);
}
int32_t qb_ipcc_zcb_free(qb_hdb_handle_t handle, void *buffer)
int32_t qb_ipcc_zcb_free(qb_handle_t handle, void *buffer)
{
struct ipc_instance *ipc_instance;
mar_req_qb_ipcc_zc_free_t req_qb_ipcc_zc_free;
@ -1073,7 +1071,7 @@ int32_t qb_ipcc_zcb_free(qb_hdb_handle_t handle, void *buffer)
}
int32_t
qb_ipcc_zcb_msg_send_reply_receive(qb_hdb_handle_t handle,
qb_ipcc_zcb_msg_send_reply_receive(qb_handle_t handle,
void *msg, void *res_msg, size_t res_len)
{
struct ipc_instance *ipc_instance;

View File

@ -28,6 +28,7 @@
#include "os_base.h"
#include <sys/mman.h>
#include <sys/poll.h>
#include <pthread.h>
#if defined(HAVE_GETPEERUCRED)
#include <ucred.h>
#endif
@ -103,7 +104,7 @@ struct conn_info {
int32_t notify_flow_control_enabled;
int32_t flow_control_state;
int32_t refcount;
qb_hdb_handle_t stats_handle;
qb_handle_t stats_handle;
#if _POSIX_THREAD_PROCESS_SHARED < 1
key_t semkey;
int32_t semid;
@ -139,24 +140,23 @@ static void ipc_disconnect(struct conn_info *conn_info);
static void msg_send(void *conn, const struct iovec *iov, uint32_t iov_len,
int32_t locked);
static qb_hdb_handle_t dummy_stats_create_connection(const char *name,
pid_t pid, int32_t fd)
static qb_handle_t dummy_stats_create_connection(const char *name,
pid_t pid, int32_t fd)
{
return (0ULL);
}
static void dummy_stats_destroy_connection(qb_hdb_handle_t handle)
static void dummy_stats_destroy_connection(qb_handle_t handle)
{
}
static void dummy_stats_update_value(qb_hdb_handle_t handle,
static void dummy_stats_update_value(qb_handle_t handle,
const char *name,
const void *value, size_t value_size)
{
}
static void dummy_stats_increment_value(qb_hdb_handle_t handle,
const char *name)
static void dummy_stats_increment_value(qb_handle_t handle, const char *name)
{
}

View File

@ -951,7 +951,7 @@ void _logsys_log_rec(uint32_t rec_ident,
qb_thread_lock(logsys_flt_lock);
flt_data = qb_rb_chunk_alloc(rb,
(record_reclaim_size * sizeof(uint32_t)));
(record_reclaim_size * sizeof(uint32_t)));
assert(flt_data != NULL);
idx = 0;

View File

@ -37,21 +37,21 @@
struct plugin_component_instance {
struct plugin_iface *ifaces;
int iface_count;
qb_hdb_handle_t comp_handle;
qb_handle_t comp_handle;
void *dl_handle;
int refcount;
char library_name[256];
};
struct plugin_iface_instance {
qb_hdb_handle_t component_handle;
qb_handle_t component_handle;
void *context;
void (*destructor) (void *context);
};
DECLARE_HDB_DATABASE(plugin_component_instance_database, NULL);
QB_HDB_DECLARE(plugin_component_instance_database, NULL);
DECLARE_HDB_DATABASE(plugin_iface_instance_database, NULL);
QB_HDB_DECLARE(plugin_iface_instance_database, NULL);
/*
static struct hdb_handle_database plugin_component_instance_database = {
@ -67,7 +67,7 @@ static struct hdb_handle_database plugin_iface_instance_database = {
};
*/
static qb_hdb_handle_t g_component_handle = 0xFFFFFFFF;
static qb_handle_t g_component_handle = 0xFFFFFFFF;
#if defined(QB_LINUX) || defined(QB_SOLARIS)
static int plugin_select_so(const struct dirent *dirent)
@ -110,7 +110,7 @@ static inline struct plugin_component_instance *plugin_comp_find(const char
{
struct plugin_component_instance *instance;
void *instance_p = NULL;
qb_hdb_handle_t component_handle = 0;
qb_handle_t component_handle = 0;
int i;
/*
@ -141,7 +141,7 @@ static inline int plugin_lib_loaded(char *library_name)
{
struct plugin_component_instance *instance;
void *instance_p = NULL;
qb_hdb_handle_t component_handle = 0;
qb_handle_t component_handle = 0;
/*
* Try to find interface in already loaded component
@ -450,7 +450,7 @@ found:
static unsigned int plugin_initialized = 0;
int plugin_ifact_reference(qb_hdb_handle_t * iface_handle,
int plugin_ifact_reference(qb_handle_t * iface_handle,
const char *iface_name,
int version, void **iface, void *context)
{
@ -511,7 +511,7 @@ found:
return (0);
}
int plugin_ifact_release(qb_hdb_handle_t handle)
int plugin_ifact_release(qb_handle_t handle)
{
struct plugin_iface_instance *iface_instance;
int res = 0;
@ -534,7 +534,7 @@ int plugin_ifact_release(qb_hdb_handle_t handle)
void plugin_component_register(struct plugin_comp *comp)
{
struct plugin_component_instance *instance;
static qb_hdb_handle_t comp_handle;
static qb_handle_t comp_handle;
qb_hdb_handle_create(&plugin_component_instance_database,
sizeof(struct plugin_component_instance),

View File

@ -34,7 +34,7 @@
#include "tlist.h"
#include "util_int.h"
typedef int (*dispatch_fn_t) (qb_hdb_handle_t hdb_handle, int fd, int revents,
typedef int (*dispatch_fn_t) (qb_handle_t hdb_handle, int fd, int revents,
void *data);
struct qb_poll_entry {
@ -51,11 +51,11 @@ struct qb_poll_instance {
int stop_requested;
};
DECLARE_HDB_DATABASE(poll_instance_database, NULL);
QB_HDB_DECLARE(poll_instance_database, NULL);
qb_hdb_handle_t qb_poll_create(void)
qb_handle_t qb_poll_create(void)
{
qb_hdb_handle_t handle;
qb_handle_t handle;
struct qb_poll_instance *poll_instance;
unsigned int res;
@ -85,7 +85,7 @@ error_exit:
return (-1);
}
int qb_poll_destroy(qb_hdb_handle_t handle)
int qb_poll_destroy(qb_handle_t handle)
{
struct qb_poll_instance *poll_instance;
int res = 0;
@ -108,11 +108,11 @@ error_exit:
return (res);
}
int qb_poll_dispatch_add(qb_hdb_handle_t handle,
int qb_poll_dispatch_add(qb_handle_t handle,
int fd,
int events,
void *data,
int (*dispatch_fn) (qb_hdb_handle_t hdb_handle_t,
int (*dispatch_fn) (qb_handle_t hdb_handle_t,
int fd, int revents, void *data))
{
struct qb_poll_instance *poll_instance;
@ -183,10 +183,10 @@ error_exit:
return (res);
}
int qb_poll_dispatch_modify(qb_hdb_handle_t handle,
int qb_poll_dispatch_modify(qb_handle_t handle,
int fd,
int events,
int (*dispatch_fn) (qb_hdb_handle_t hdb_handle_t,
int (*dispatch_fn) (qb_handle_t hdb_handle_t,
int fd,
int revents, void *data))
{
@ -223,7 +223,7 @@ error_exit:
return (res);
}
int qb_poll_dispatch_delete(qb_hdb_handle_t handle, int fd)
int qb_poll_dispatch_delete(qb_handle_t handle, int fd)
{
struct qb_poll_instance *poll_instance;
int i;
@ -257,7 +257,7 @@ error_exit:
return (res);
}
int qb_poll_timer_add(qb_hdb_handle_t handle,
int qb_poll_timer_add(qb_handle_t handle,
int msec_duration, void *data,
void (*timer_fn) (void *data),
qb_poll_timer_handle * timer_handle_out)
@ -287,7 +287,7 @@ error_exit:
return (res);
}
int qb_poll_timer_delete(qb_hdb_handle_t handle, qb_poll_timer_handle th)
int qb_poll_timer_delete(qb_handle_t handle, qb_poll_timer_handle th)
{
struct qb_poll_instance *poll_instance;
int res = 0;
@ -310,7 +310,7 @@ error_exit:
return (res);
}
int qb_poll_stop(qb_hdb_handle_t handle)
int qb_poll_stop(qb_handle_t handle)
{
struct qb_poll_instance *poll_instance;
unsigned int res;
@ -329,7 +329,7 @@ error_exit:
return (res);
}
int qb_poll_run(qb_hdb_handle_t handle)
int qb_poll_run(qb_handle_t handle)
{
struct qb_poll_instance *poll_instance;
int i;
@ -401,7 +401,7 @@ error_exit:
}
#ifdef COMPILE_OUT
void qb_poll_print_state(qb_hdb_handle_t handle, int fd)
void qb_poll_print_state(qb_handle_t handle, int fd)
{
struct qb_poll_instance *poll_instance;
int i;

View File

@ -226,7 +226,7 @@ void qb_rb_close(qb_ringbuffer_t * rb)
free(rb);
}
char* qb_rb_name_get(qb_ringbuffer_t * rb)
char *qb_rb_name_get(qb_ringbuffer_t * rb)
{
return rb->shared_hdr->hdr_path;
}
@ -452,8 +452,7 @@ void qb_rb_chunk_reclaim(qb_ringbuffer_t * rb)
rb->unlock_fn(rb);
}
ssize_t qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out, int32_t
timeout)
ssize_t qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out, int32_t timeout)
{
uint32_t read_pt;
uint32_t chunk_size;
@ -463,8 +462,8 @@ ssize_t qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out, int32_t
res = rb->sem_timedwait_fn(rb, timeout);
if (res == -1 && errno == ETIMEDOUT && rb->shared_hdr->count > 0) {
qb_util_log(LOG_ERR,
"sem timedout but count is %d",
rb->shared_hdr->count);
"sem timedout but count is %d",
rb->shared_hdr->count);
} else if (res == -1 && errno != EIDRM) {
if (errno != ETIMEDOUT) {
qb_util_log(LOG_ERR,

View File

@ -40,18 +40,18 @@
#include <qb/qbutil.h>
#include <qb/qbrb.h>
struct qb_ringbuffer_s;
int32_t qb_rb_lock_create(struct qb_ringbuffer_s * rb, uint32_t flags);
typedef int32_t (*qb_rb_lock_fn_t) (struct qb_ringbuffer_s * rb);
typedef int32_t (*qb_rb_unlock_fn_t) (struct qb_ringbuffer_s * rb);
typedef int32_t (*qb_rb_lock_destroy_fn_t) (struct qb_ringbuffer_s * rb);
int32_t qb_rb_lock_create(struct qb_ringbuffer_s *rb, uint32_t flags);
typedef int32_t(*qb_rb_lock_fn_t) (struct qb_ringbuffer_s * rb);
typedef int32_t(*qb_rb_unlock_fn_t) (struct qb_ringbuffer_s * rb);
typedef int32_t(*qb_rb_lock_destroy_fn_t) (struct qb_ringbuffer_s * rb);
int32_t qb_rb_sem_create(struct qb_ringbuffer_s * rb, uint32_t flags);
typedef int32_t (*qb_rb_sem_post_fn_t) (struct qb_ringbuffer_s * rb);
typedef int32_t (*qb_rb_sem_timedwait_fn_t) (struct qb_ringbuffer_s * rb, int32_t ms_timeout);
typedef int32_t (*qb_rb_sem_destroy_fn_t) (struct qb_ringbuffer_s * rb);
int32_t qb_rb_sem_create(struct qb_ringbuffer_s *rb, uint32_t flags);
typedef int32_t(*qb_rb_sem_post_fn_t) (struct qb_ringbuffer_s * rb);
typedef int32_t(*qb_rb_sem_timedwait_fn_t) (struct qb_ringbuffer_s * rb,
int32_t ms_timeout);
typedef int32_t(*qb_rb_sem_destroy_fn_t) (struct qb_ringbuffer_s * rb);
struct qb_ringbuffer_shared_s {
volatile uint32_t write_pt;
@ -92,6 +92,4 @@ union semun {
#define RB_NS_IN_MSEC 1000000ULL
#endif /* _RINGBUFFER_H_ */

View File

@ -44,7 +44,7 @@ static int32_t my_posix_sem_timedwait(qb_ringbuffer_t * rb, int32_t ms_timeout)
ts_timeout.tv_nsec = (ms_timeout % 1000) * RB_NS_IN_MSEC;
}
sem_wait_again:
sem_wait_again:
if (ms_timeout > 0) {
res = sem_timedwait(&rb->shared_hdr->posix_sem, &ts_timeout);
} else if (ms_timeout == 0) {
@ -57,8 +57,8 @@ static int32_t my_posix_sem_timedwait(qb_ringbuffer_t * rb, int32_t ms_timeout)
goto sem_wait_again;
} else if (errno != ETIMEDOUT) {
qb_util_log(LOG_ERR,
"error waiting for semaphore : %s",
strerror(errno));
"error waiting for semaphore : %s",
strerror(errno));
}
}
return res;

View File

@ -22,6 +22,7 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <qb/qbipcc.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
@ -81,7 +82,7 @@ static void bm_finish(const char *operation, int size)
printf("MB/sec %9.3f\n", mbs_per_sec);
}
qb_hdb_handle_t bmc_ipc_handle;
qb_handle_t bmc_ipc_handle;
static void bmc_connect(void)
{

View File

@ -32,7 +32,7 @@
#define ITERATIONS 10000000
struct bm_ctx {
qb_hdb_handle_t bmc_ipc_handle;
qb_handle_t bmc_ipc_handle;
struct timeval tv1;
struct timeval tv2;
struct timeval tv_elapsed;

View File

@ -49,7 +49,7 @@
int blocking = 1;
int verbose = 0;
static qb_hdb_handle_t bms_poll_handle;
static qb_handle_t bms_poll_handle;
struct lib_handler {
void (*lib_handler_fn) (void *conn, const void *msg);
@ -212,7 +212,7 @@ static void ipc_fatal_error(const char *error_msg)
exit(1);
}
static int bms_poll_handler_accept(qb_hdb_handle_t handle,
static int bms_poll_handler_accept(qb_handle_t handle,
int fd, int revent, void *context)
{
if (verbose) {
@ -221,7 +221,7 @@ static int bms_poll_handler_accept(qb_hdb_handle_t handle,
return (qb_ipcs_handler_accept(fd, revent, context));
}
static int bms_poll_handler_dispatch(qb_hdb_handle_t handle,
static int bms_poll_handler_dispatch(qb_handle_t handle,
int fd, int revent, void *context)
{
return (qb_ipcs_handler_dispatch(fd, revent, context));

View File

@ -29,11 +29,11 @@ START_TEST(test_hash_load)
char word[1000];
FILE *fp;
int res = 0;
qb_hdb_handle_t handle = 0;
qb_handle_t handle = 0;
void *value;
uint64_t value_len;
if (access("/usr/shar/dict/words", R_OK) != 0 ) {
if (access("/usr/share/dict/words", R_OK) != 0) {
printf("no dict/words - not testing\n");
return;
}

View File

@ -33,15 +33,15 @@ struct iface {
START_TEST(test_plugin)
{
qb_hdb_handle_t a_ifact_handle_ver0;
qb_hdb_handle_t b_ifact_handle_ver0;
qb_handle_t a_ifact_handle_ver0;
qb_handle_t b_ifact_handle_ver0;
struct iface *a_iface_ver0;
struct iface *a_iface_ver1;
void *a_iface_ver0_p;
void *a_iface_ver1_p;
qb_hdb_handle_t a_ifact_handle_ver1;
qb_hdb_handle_t b_ifact_handle_ver1;
qb_handle_t a_ifact_handle_ver1;
qb_handle_t b_ifact_handle_ver1;
struct iface *b_iface_ver0;
struct iface *b_iface_ver1;
void *b_iface_ver0_p;