see subject.
Index: configure.ac
===================================================================
--- configure.ac (revision 1831)
+++ configure.ac (working copy)
@@ -101,7 +101,8 @@
AC_CHECK_FUNCS([alarm alphasort atexit bzero dup2 endgrent endpwent fcntl \
getcwd getpeerucred gettimeofday inet_ntoa memmove memset \
mkdir scandir select socket strcasecmp strchr strdup \
- strerror strrchr strspn strstr])
+ strerror strrchr strspn strstr pthread_spin_lock \
+ pthread_spin_unlock])
# add man and init dirs?
AC_CONFIG_FILES([Makefile
Index: lib/evt.c
===================================================================
--- lib/evt.c (revision 1831)
+++ lib/evt.c (working copy)
@@ -31,6 +31,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <config.h>
+
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
@@ -67,32 +69,11 @@
/*
* Event instance data
*/
-struct saHandleDatabase evt_instance_handle_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = evtHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(evt_instance_handle_db,evtHandleInstanceDestructor);
-/*
- * Channel instance data
- */
-struct saHandleDatabase channel_handle_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = chanHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(channel_handle_db,chanHandleInstanceDestructor);
-/*
- * Event instance data
- */
-struct saHandleDatabase event_handle_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = eventHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(event_handle_db,eventHandleInstanceDestructor);
struct handle_list {
SaUint64T hl_handle;
@@ -543,8 +524,6 @@
edi->edi_patterns.patterns[i].allocatedSize = pat->pattern_size;
edi->edi_patterns.patterns[i].pattern = malloc(pat->pattern_size);
if (!edi->edi_patterns.patterns[i].pattern) {
- DPRINT (("make_event: couldn't alloc %llu bytes\n",
- (unsigned long long)pat->pattern_size));
saHandleDestroy(&event_handle_db, *event_handle);
error = SA_AIS_ERR_LIBRARY;
goto make_evt_done_put2;
Index: lib/ckpt.c
===================================================================
--- lib/ckpt.c (revision 1831)
+++ lib/ckpt.c (working copy)
@@ -32,6 +32,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <config.h>
#include <stdio.h>
#include <string.h>
@@ -101,32 +102,11 @@
/*
* All CKPT instances in this database
*/
-static struct saHandleDatabase ckptHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = ckptHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(ckptHandleDatabase,ckptHandleInstanceDestructor);
-/*
- * All Checkpoint instances in this database
- */
-static struct saHandleDatabase checkpointHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = checkpointHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(checkpointHandleDatabase,checkpointHandleInstanceDestructor);
-/*
- * All section iterators in this database
- */
-static struct saHandleDatabase ckptSectionIterationHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = ckptSectionIterationHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(ckptSectionIterationHandleDatabase, ckptSectionIterationHandleInstanceDestructor);
/*
* Versions supported
Index: lib/tmr.c
===================================================================
--- lib/tmr.c (revision 1831)
+++ lib/tmr.c (working copy)
@@ -32,6 +32,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <config.h>
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -68,12 +70,7 @@
void tmrHandleInstanceDestructor (void *instance);
-static struct saHandleDatabase tmrHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = tmrHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(tmrHandleDatabase,tmrHandleInstanceDestructor);
static SaVersionT tmrVersionsSupported[] = {
{ 'A', 1, 1 }
Index: lib/amf.c
===================================================================
--- lib/amf.c (revision 1831)
+++ lib/amf.c (working copy)
@@ -33,6 +33,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <config.h>
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -70,12 +72,7 @@
/*
* All instances in one database
*/
-static struct saHandleDatabase amfHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = amfHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(amfHandleDatabase,amfHandleInstanceDestructor);
/*
* Versions supported
Index: lib/lck.c
===================================================================
--- lib/lck.c (revision 1831)
+++ lib/lck.c (working copy)
@@ -32,6 +32,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <config.h>
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -94,32 +96,11 @@
/*
* All LCK instances in this database
*/
-static struct saHandleDatabase lckHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = lckHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(lckHandleDatabase,lckHandleInstanceDestructor);
-/*
- * All Resource instances in this database
- */
-static struct saHandleDatabase lckResourceHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = lckResourceHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(lckResourceHandleDatabase,lckResourceHandleInstanceDestructor);
-/*
- * All Resource Lock Identifier instances in this database
- */
-static struct saHandleDatabase lckLockIdHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = lckResourceHandleLockIdInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(lckLockIdHandleDatabase,lckResourceHandleLockIdInstanceDestructor);
/*
* Versions supported
@@ -447,7 +428,6 @@
}
break;
case MESSAGE_RES_LCK_RESOURCELOCKASYNC:
- DPRINT (("grant\n"));
if (callbacks.saLckLockGrantCallback == NULL) {
continue;
}
Index: lib/clm.c
===================================================================
--- lib/clm.c (revision 1831)
+++ lib/clm.c (working copy)
@@ -33,6 +33,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <config.h>
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -67,12 +69,7 @@
static void clmHandleInstanceDestructor (void *);
-static struct saHandleDatabase clmHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = clmHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(clmHandleDatabase,clmHandleInstanceDestructor);
/*
* Versions supported
Index: lib/msg.c
===================================================================
--- lib/msg.c (revision 1831)
+++ lib/msg.c (working copy)
@@ -32,6 +32,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include <config.h>
+
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -81,19 +83,9 @@
void msgHandleInstanceDestructor (void *instance);
void queueHandleInstanceDestructor (void *instance);
-static struct saHandleDatabase msgHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = msgHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(msgHandleDatabase,msgHandleInstanceDestructor);
-static struct saHandleDatabase queueHandleDatabase = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = queueHandleInstanceDestructor
-};
+DECLARE_SAHDB_DATABASE(queueHandleDatabase,queueHandleInstanceDestructor);
static SaVersionT msgVersionsSupported[] = {
{ 'B', 1, 1 }
Index: include/corosync/coroipcc.h
===================================================================
--- include/corosync/coroipcc.h (revision 2098)
+++ include/corosync/coroipcc.h (working copy)
@@ -36,37 +36,14 @@
#ifndef COROIPC_H_DEFINED
#define COROIPC_H_DEFINED
+#include <config.h>
+
#include <pthread.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <corosync/corotypes.h>
#include <corosync/ipc_gen.h>
-/* Debug macro
- */
-#ifdef DEBUG
- #define DPRINT(s) printf s
-#else
- #define DPRINT(s)
-#endif
-
-#ifdef SO_NOSIGPIPE
-#ifndef MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
-#endif
-void socket_nosigpipe(int s);
-#else
-#define socket_nosigpipe(s)
-#endif
-
-struct saHandleDatabase {
- unsigned int handleCount;
- struct saHandle *handles;
- pthread_mutex_t mutex;
- void (*handleInstanceDestructor) (void *);
-};
-
-
extern cs_error_t
coroipcc_service_connect (
const char *socket_name,
@@ -110,6 +87,35 @@
unsigned int iov_len,
void **res_msg);
+/*
+ * This needs to be removed
+ */
+struct saHandleDatabase {
+ unsigned int handleCount;
+ struct saHandle *handles;
+#if defined(HAVE_PTHREAD_SPIN_LOCK)
+ pthread_spinlock_t lock;
+#else
+ pthread_mutex_t lock;
+#endif
+ void (*handleInstanceDestructor) (void *);
+};
+
+extern void saHandleDatabaseLock_init (struct saHandleDatabase *hdb);
+
+#define DECLARE_SAHDB_DATABASE(database_name,destructor) \
+static struct saHandleDatabase (database_name) = { \
+ .handleInstanceDestructor = destructor, \
+ .handleCount = 0, \
+ .handles = NULL, \
+}; \
+static void database_name##_init(void)__attribute__((constructor)); \
+static void database_name##_init(void) \
+{ \
+ saHandleDatabaseLock_init (&(database_name)); \
+}
+
+
extern cs_error_t
saHandleCreate (
struct saHandleDatabase *handleDatabase,
Index: lib/cfg.c
===================================================================
--- lib/cfg.c (revision 2098)
+++ lib/cfg.c (working copy)
@@ -74,12 +74,7 @@
/*
* All instances in one database
*/
-static struct saHandleDatabase cfg_hdb = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = cfg_handle_instance_destructor
-};
+DECLARE_SAHDB_DATABASE (cfg_hdb,cfg_handle_instance_destructor);
/*
* Implementation
Index: lib/pload.c
===================================================================
--- lib/pload.c (revision 2098)
+++ lib/pload.c (working copy)
@@ -58,12 +58,7 @@
unsigned int finalize;
};
-static struct saHandleDatabase pload_handle_t_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = pload_instance_destructor
-};
+DECLARE_SAHDB_DATABASE(pload_handle_t_db,pload_instance_destructor);
/*
* Clean up function for an evt instance (saEvtInitialize) handle
Index: lib/coroipcc.c
===================================================================
--- lib/coroipcc.c (revision 2098)
+++ lib/coroipcc.c (working copy)
@@ -763,6 +763,39 @@
return (CS_OK);
}
+#if defined(HAVE_PTHREAD_SPIN_LOCK)
+static void hdb_lock (struct saHandleDatabase *hdb)
+{
+ pthread_spin_lock (&hdb->lock);
+}
+
+static void hdb_unlock (struct saHandleDatabase *hdb)
+{
+ pthread_spin_unlock (&hdb->lock);
+}
+
+void saHandleDatabaseLock_init (struct saHandleDatabase *hdb)
+{
+ pthread_spin_init (&hdb->lock, 0);
+}
+#else
+static void hdb_lock (struct saHandleDatabase *hdb)
+{
+ pthread_mutex_lock (&hdb->lock);
+}
+
+static void hdb_unlock (struct saHandleDatabase *hdb)
+{
+ pthread_mutex_unlock (&hdb->lock);
+}
+
+void saHandleDatabaseLock_init (struct saHandleDatabase *hdb)
+{
+ pthread_mutex_init (&hdb->lock, NULL);
+}
+#endif
+
+
cs_error_t
saHandleCreate (
struct saHandleDatabase *handleDatabase,
@@ -776,7 +809,7 @@
void *instance;
int i;
- pthread_mutex_lock (&handleDatabase->mutex);
+ hdb_lock (handleDatabase);
for (handle = 0; handle < handleDatabase->handleCount; handle++) {
if (handleDatabase->handles[handle].state == SA_HANDLE_STATE_EMPTY) {
@@ -790,7 +823,7 @@
newHandles = (struct saHandle *)realloc (handleDatabase->handles,
sizeof (struct saHandle) * handleDatabase->handleCount);
if (newHandles == NULL) {
- pthread_mutex_unlock (&handleDatabase->mutex);
+ hdb_unlock (handleDatabase);
return (CS_ERR_NO_MEMORY);
}
handleDatabase->handles = newHandles;
@@ -799,7 +832,7 @@
instance = malloc (instanceSize);
if (instance == 0) {
free (newHandles);
- pthread_mutex_unlock (&handleDatabase->mutex);
+ hdb_unlock (handleDatabase);
return (CS_ERR_NO_MEMORY);
}
@@ -828,7 +861,7 @@
*handleOut = (uint64_t)((uint64_t)check << 32 | handle);
- pthread_mutex_unlock (&handleDatabase->mutex);
+ hdb_unlock (handleDatabase);
return (CS_OK);
}
@@ -843,17 +876,17 @@
uint32_t check = inHandle >> 32;
uint32_t handle = inHandle & 0xffffffff;
- pthread_mutex_lock (&handleDatabase->mutex);
+ hdb_lock (handleDatabase);
if (check != handleDatabase->handles[handle].check) {
- pthread_mutex_unlock (&handleDatabase->mutex);
+ hdb_unlock (handleDatabase);
error = CS_ERR_BAD_HANDLE;
return (error);
}
handleDatabase->handles[handle].state = SA_HANDLE_STATE_PENDINGREMOVAL;
- pthread_mutex_unlock (&handleDatabase->mutex);
+ hdb_unlock (handleDatabase);
saHandleInstancePut (handleDatabase, inHandle);
@@ -871,7 +904,7 @@
uint32_t handle = inHandle & 0xffffffff;
cs_error_t error = CS_OK;
- pthread_mutex_lock (&handleDatabase->mutex);
+ hdb_lock (handleDatabase);
if (handle >= (uint64_t)handleDatabase->handleCount) {
error = CS_ERR_BAD_HANDLE;
@@ -892,7 +925,7 @@
handleDatabase->handles[handle].refCount += 1;
error_exit:
- pthread_mutex_unlock (&handleDatabase->mutex);
+ hdb_unlock (handleDatabase);
return (error);
}
@@ -908,7 +941,7 @@
uint32_t check = inHandle >> 32;
uint32_t handle = inHandle & 0xffffffff;
- pthread_mutex_lock (&handleDatabase->mutex);
+ hdb_lock (handleDatabase);
if (check != handleDatabase->handles[handle].check) {
error = CS_ERR_BAD_HANDLE;
@@ -926,7 +959,7 @@
}
error_exit:
- pthread_mutex_unlock (&handleDatabase->mutex);
+ hdb_unlock (handleDatabase);
return (error);
}
Index: lib/cpg.c
===================================================================
--- lib/cpg.c (revision 2098)
+++ lib/cpg.c (working copy)
@@ -64,12 +64,7 @@
static void cpg_instance_destructor (void *instance);
-static struct saHandleDatabase cpg_handle_t_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = cpg_instance_destructor
-};
+DECLARE_SAHDB_DATABASE(cpg_handle_t_db,cpg_instance_destructor);
/*
* Clean up function for a cpg instance (cpg_nitialize) handle
Index: lib/votequorum.c
===================================================================
--- lib/votequorum.c (revision 2098)
+++ lib/votequorum.c (working copy)
@@ -63,12 +63,7 @@
static void votequorum_instance_destructor (void *instance);
-static struct saHandleDatabase votequorum_handle_t_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = votequorum_instance_destructor
-};
+DECLARE_SAHDB_DATABASE(votequorum_handle_t_db,votequorum_instance_destructor);
/*
* Clean up function for a quorum instance (votequorum_initialize) handle
Index: lib/quorum.c
===================================================================
--- lib/quorum.c (revision 2098)
+++ lib/quorum.c (working copy)
@@ -63,12 +63,7 @@
static void quorum_instance_destructor (void *instance);
-static struct saHandleDatabase quorum_handle_t_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = quorum_instance_destructor
-};
+DECLARE_SAHDB_DATABASE(quorum_handle_t_db,quorum_instance_destructor);
/*
* Clean up function for a quorum instance (quorum_initialize) handle
Index: lib/confdb.c
===================================================================
--- lib/confdb.c (revision 2098)
+++ lib/confdb.c (working copy)
@@ -82,14 +82,8 @@
static void confdb_instance_destructor (void *instance);
-static struct saHandleDatabase confdb_handle_t_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = confdb_instance_destructor
-};
+DECLARE_SAHDB_DATABASE(confdb_handle_t_db,confdb_instance_destructor);
-
static cs_error_t do_find_destroy(struct confdb_inst *confdb_inst, hdb_handle_t find_handle);
Index: lib/evs.c
===================================================================
--- lib/evs.c (revision 2098)
+++ lib/evs.c (working copy)
@@ -67,12 +67,7 @@
static void evs_instance_destructor (void *instance);
-static struct saHandleDatabase evs_handle_t_db = {
- .handleCount = 0,
- .handles = 0,
- .mutex = PTHREAD_MUTEX_INITIALIZER,
- .handleInstanceDestructor = evs_instance_destructor
-};
+DECLARE_SAHDB_DATABASE (evs_handle_t_db, evs_instance_destructor);
/*
* Clean up function for an evt instance (saEvtInitialize) handle
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais