Revision: 65548
http://sourceforge.net/p/brlcad/code/65548
Author: ejno
Date: 2015-07-09 19:00:08 +0000 (Thu, 09 Jul 2015)
Log Message:
-----------
enable use of spin/mutex locks if there is no atomics support
Modified Paths:
--------------
brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mm.c
brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mm.h
brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmatomic.h
brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmbitmap.c
brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmthread.h
brlcad/trunk/src/librt/primitives/bot/gct_decimation/meshdecimation.c
Modified: brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mm.c
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mm.c
2015-07-09 18:07:29 UTC (rev 65547)
+++ brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mm.c
2015-07-09 19:00:08 UTC (rev 65548)
@@ -423,6 +423,75 @@
mmContext mmcontext;
+#ifndef MM_ATOMIC_SUPPORT
+#include "cc.h"
+#include <stdlib.h>
+void mmBlockProcessList(mmBlockHead *head, void *userpointer, int
(*processchunk)(void *chunk, void *userpointer))
+{
+ static const int INTPTR_BITS = sizeof(intptr_t) * CHAR_BIT;
+ const int INTPTR_BITSHIFT = ccLog2Int(INTPTR_BITS);
+
+ int i, blockcount, blockrefsize, chunkperblock;
+ intptr_t **bitsref;
+ intptr_t *blockmask;
+ intptr_t blockindex, chunkindex;
+ size_t chunksize;
+ void *p, *chunk;
+ mmBlock *block;
+ mmListNode *list;
+
+ mtSpinLock(&head->spinlock);
+
+ blockcount = 0;
+
+ for (block = (mmBlock *)head->blocklist ; block ; block = (mmBlock
*)block->listnode.next)
+ block->blockindex = blockcount++;
+
+ chunksize = head->chunksize;
+ chunkperblock = head->chunkperblock;
+ blockrefsize = ((chunkperblock + INTPTR_BITS - 1) >> INTPTR_BITSHIFT) *
sizeof(intptr_t);
+ bitsref = (intptr_t **)malloc(blockcount * (sizeof(intptr_t *) +
blockrefsize));
+ memset(bitsref, 0, blockcount * (sizeof(intptr_t *) + blockrefsize));
+
+ p = ADDRESS(bitsref, blockcount * sizeof(intptr_t *));
+
+ for (i = 0 ; i < blockcount ; i++) {
+ bitsref[i] = (intptr_t *)p;
+ p = ADDRESS(p, blockrefsize);
+ }
+
+ for (list = (mmListNode *)head->freelist ; list ; list = (mmListNode
*)list->next) {
+ block = mmBlockResolveChunk(list, (mmBlock *)head->treeroot);
+ chunkindex = ADDRESSDIFF(list, ADDRESS(block, sizeof(mmBlock))) /
chunksize;
+ bitsref[ block->blockindex ][ chunkindex >> INTPTR_BITSHIFT ] |=
(intptr_t)1 << (chunkindex & (INTPTR_BITS - 1));
+ }
+
+ blockindex = 0;
+
+ for (block = (mmBlock *)head->blocklist ; block ; block = (mmBlock
*)block->listnode.next) {
+ blockmask = bitsref[ blockindex ];
+ chunk = ADDRESS(block, sizeof(mmBlock));
+
+ for (chunkindex = 0 ; chunkindex < chunkperblock ; chunkindex++, chunk
= ADDRESS(chunk, chunksize)) {
+ if (blockmask[ chunkindex >> INTPTR_BITSHIFT ] & ((intptr_t)1 <<
(chunkindex & (INTPTR_BITS - 1))))
+ continue;
+
+ if (processchunk(chunk, userpointer))
+ goto end;
+ }
+
+ blockindex++;
+ }
+
+end:
+ free(bitsref);
+ mtSpinUnlock(&head->spinlock);
+
+ return;
+}
+#endif
+
+
void mmInit()
{
int64_t sysmemory;
Modified: brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mm.h
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mm.h
2015-07-09 18:07:29 UTC (rev 65547)
+++ brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mm.h
2015-07-09 19:00:08 UTC (rev 65548)
@@ -130,7 +130,11 @@
void *mmNodeAlloc(int nodeindex, size_t size);
void mmNodeFree(int nodeindex, void *v, size_t size);
+#ifndef MM_ATOMIC_SUPPORT
+void mmBlockProcessList(mmBlockHead *head, void *userpointer, int
(*processchunk)(void *chunk, void *userpointer));
+#endif
+
void mmListAdd(void **list, void *item, intptr_t offset);
void mmListRemove(void *item, intptr_t offset);
Modified:
brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmatomic.h
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmatomic.h
2015-07-09 18:07:29 UTC (rev 65547)
+++ brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmatomic.h
2015-07-09 19:00:08 UTC (rev 65548)
@@ -40,7 +40,7 @@
#include "cpuconfig.h"
-#if ( defined(CPUCONF_ARCH_IA32) || defined(CPUCONF_ARCH_AMD64) ) &&
defined(__GNUC__)
+#if (defined(CPUCONF_ARCH_IA32) || defined(CPUCONF_ARCH_AMD64)) &&
defined(__GNUC__)
#define MM_ATOMIC_SUPPORT
Modified:
brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmbitmap.c
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmbitmap.c
2015-07-09 18:07:29 UTC (rev 65547)
+++ brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmbitmap.c
2015-07-09 19:00:08 UTC (rev 65548)
@@ -51,28 +51,23 @@
{
size_t mapsize, vindex;
long value;
-#ifdef MM_ATOMIC_SUPPORT
- mmAtomicL *map;
-#else
- long *map;
-#endif
mapsize = (entrycount + LONG_BITS - 1) >> LONG_BITSHIFT;
- bitmap->map = (mmAtomic64 *)malloc(mapsize * sizeof(mmAtomicL));
bitmap->mapsize = mapsize;
bitmap->entrycount = entrycount;
- map = bitmap->map;
value = (initvalue & 0x1 ? ~0x0 : 0x0);
#ifdef MM_ATOMIC_SUPPORT
+ bitmap->map = (mmAtomic64 *)malloc(mapsize * sizeof(mmAtomicL));
for (vindex = 0 ; vindex < mapsize ; vindex++)
- mmAtomicWriteL(&map[vindex], value);
+ mmAtomicWriteL(&bitmap->map[vindex], value);
#else
+ bitmap->map = (long *)malloc(mapsize * sizeof(long));
for (vindex = 0 ; vindex < mapsize ; vindex++)
- map[vindex] = value;
+ bitmap->map[vindex] = value;
mtMutexInit(&bitmap->mutex);
#endif
Modified:
brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmthread.h
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmthread.h
2015-07-09 18:07:29 UTC (rev 65547)
+++ brlcad/trunk/src/librt/primitives/bot/gct_decimation/auxiliary/mmthread.h
2015-07-09 19:00:08 UTC (rev 65548)
@@ -50,13 +50,6 @@
#endif
-static inline void mtYield()
-{
- sched_yield();
- return;
-}
-
-
typedef struct mtThread mtThread;
struct mtThread {
@@ -68,6 +61,9 @@
#define MT_THREAD_FLAGS_SETSTACK (0x2)
+#define MT_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
+
+
static inline void mtThreadCreate(mtThread *thread, void *(*threadmain)(void
*value), void *value, int flags, void *stack, size_t stacksize)
{
pthread_attr_t attr;
@@ -105,31 +101,9 @@
}
-static inline size_t mtGetMinimumStackSize()
-{
-#ifdef PTHREAD_STACK_MIN
- return PTHREAD_STACK_MIN;
-#else
- return (mmcontext.pagesize ? 4 * mmcontext.pagesize : 16384);
-#endif
-}
-
-
-#ifdef MT_DEBUG
-#ifndef DEBUG_WARNING()
-#define DEBUG_WARNING() ({printf( "\nRF WARNING : %s %s %d\n", __FILE__,
__FUNCTION__, __LINE__ ); fflush( stdout );})
-#endif
-#endif
-
-
typedef struct mtMutex mtMutex;
struct mtMutex {
-#ifdef MT_DEBUG
- unsigned char *function;
- unsigned char *file;
- int line;
-#endif
pthread_mutex_t pmutex;
};
@@ -145,61 +119,6 @@
return;
}
-#ifdef MT_DEBUG
-
-#define mtMutexLock(a) mtMutexLockDebug(a,__FUNCTION__,__FILE__,__LINE__)
-#define mtMutexUnlock(a) mtMutexUnlockDebug(a,__FUNCTION__,__FILE__,__LINE__)
-#define mtMutexTryLock(a) mtMutexTryLockDebug(a,__FUNCTION__,__FILE__,__LINE__)
-
-static inline void mtMutexLockDebug(mtMutex *mutex, const unsigned char
*function, const unsigned char *file, const int line)
-{
- printf("Mutex lock : Thread %d on %p from %s() in %s:%d\n",
(int)pthread_self(), mutex, function, file, line);
- fflush(stdout);
-
- if (pthread_mutex_trylock(&mutex->pmutex)) {
- printf(" Mutex %p locked by %s() in %s:%d\n", mutex,
mutex->function, mutex->file, mutex->line);
- fflush(stdout);
-
- if (pthread_mutex_lock(&mutex->pmutex))
- DEBUG_WARNING();
- }
-
- mutex->function = (unsigned char *)function;
- mutex->file = (unsigned char *)file;
- mutex->line = line;
- return;
-}
-
-static inline void mtMutexUnlockDebug(mtMutex *mutex, const unsigned char
*function, const unsigned char *file, const int line)
-{
- mutex->function = (unsigned char *)function;
- mutex->file = (unsigned char *)file;
- mutex->line = line;
- printf("Mutex Unlock : Thread %d on %p from %s() in %s:%d\n",
(int)pthread_self(), mutex, function, file, line);
- fflush(stdout);
-
- if (pthread_mutex_unlock(&mutex->pmutex))
- DEBUG_WARNING();
-
- return;
-}
-
-static inline int mtMutexTryLockDebug(mtMutex *mutex, const unsigned char
*function, const unsigned char *file, const int line)
-{
- printf("Mutex Trylock : Thread %d on %p from %s() in %s:%d\n",
(int)pthread_self(), mutex, function, file, line);
- fflush(stdout);
-
- if (!(pthread_mutex_trylock(&mutex->pmutex))) {
- mutex->function = (unsigned char *)function;
- mutex->file = (unsigned char *)file;
- mutex->line = line;
- return 1;
- } else
- return 0;
-}
-
-#else
-
static inline void mtMutexLock(mtMutex *mutex)
{
pthread_mutex_lock(&mutex->pmutex);
@@ -217,9 +136,6 @@
return !(pthread_mutex_trylock(&mutex->pmutex));
}
-#endif
-
-
/****/
@@ -243,41 +159,20 @@
static inline void mtSignalWake(mtSignal *signal)
{
-#ifdef MT_DEBUG
-
- if (pthread_cond_signal(&signal->pcond))
- DEBUG_WARNING();
-
-#else
pthread_cond_signal(&signal->pcond);
-#endif
return;
}
static inline void mtSignalBroadcast(mtSignal *signal)
{
-#ifdef MT_DEBUG
-
- if (pthread_cond_broadcast(&signal->pcond))
- DEBUG_WARNING();
-
-#else
pthread_cond_broadcast(&signal->pcond);
-#endif
return;
}
static inline void mtSignalWait(mtSignal *signal, mtMutex *mutex)
{
-#ifdef MT_DEBUG
-
- if (pthread_cond_wait(&signal->pcond, &mutex->pmutex))
- DEBUG_WARNING();
-
-#else
pthread_cond_wait(&signal->pcond, &mutex->pmutex);
-#endif
return;
}
@@ -301,13 +196,6 @@
}
-#ifdef MT_DEBUG
-#define MT_MUTEX_INITIALIZER { 0, 0, 0, PTHREAD_MUTEX_INITIALIZER }
-#else
-#define MT_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
-#endif
-
-
/****/
@@ -352,11 +240,6 @@
typedef struct mtSpin mtSpin;
struct mtSpin {
-#ifdef MT_DEBUG
- unsigned char *function;
- unsigned char *file;
- int line;
-#endif
pthread_spinlock_t pspinlock;
};
@@ -374,27 +257,13 @@
static inline void mtSpinLock(mtSpin *spin)
{
-#ifdef MT_DEBUG
-
- if (pthread_spin_lock(&spin->pspinlock))
- DEBUG_WARNING();
-
-#else
pthread_spin_lock(&spin->pspinlock);
-#endif
return;
}
static inline void mtSpinUnlock(mtSpin *spin)
{
-#ifdef MT_DEBUG
-
- if (pthread_spin_unlock(&spin->pspinlock))
- DEBUG_WARNING();
-
-#else
pthread_spin_unlock(&spin->pspinlock);
-#endif
return;
}
Modified: brlcad/trunk/src/librt/primitives/bot/gct_decimation/meshdecimation.c
===================================================================
--- brlcad/trunk/src/librt/primitives/bot/gct_decimation/meshdecimation.c
2015-07-09 18:07:29 UTC (rev 65547)
+++ brlcad/trunk/src/librt/primitives/bot/gct_decimation/meshdecimation.c
2015-07-09 19:00:08 UTC (rev 65548)
@@ -1157,7 +1157,7 @@
if (updatebuffer->opcount >= updatebuffer->opalloc) {
updatebuffer->opalloc <<= 1;
- updatebuffer->opbuffer = realloc(updatebuffer->opbuffer,
updatebuffer->opalloc * sizeof(mdOp *));
+ updatebuffer->opbuffer = (void **)realloc(updatebuffer->opbuffer,
updatebuffer->opalloc * sizeof(mdOp *));
}
updatebuffer->opbuffer[ updatebuffer->opcount++ ] = op;
@@ -2741,11 +2741,11 @@
static void mdMeshEnd(mdMesh *mesh)
{
#ifndef MD_CONFIG_ATOMIC_SUPPORT
- mdi index;
+ mdi vindex;
mdVertex *vertex;
vertex = mesh->vertexlist;
- for (index = 0 ; index < mesh->vertexcount ; index++, vertex++)
+ for (vindex = 0; vindex < mesh->vertexcount ; vindex++, vertex++)
mtSpinDestroy(&vertex->ownerspinlock);
mtSpinDestroy(&mesh->trirefspinlock);
@@ -2799,7 +2799,7 @@
if (op->flags & MD_OP_FLAGS_DETACHED) {
mmBinSortAdd(tdata->binsort, op, collapsecost);
op->flags &= ~MD_OP_FLAGS_DETACHED;
- } else if (op->collapsecost != collapsecost)
+ } else if (!EQUAL(op->collapsecost, collapsecost))
mmBinSortUpdate(tdata->binsort, op, op->collapsecost, collapsecost);
mtSpinUnlock(&op->spinlock);
@@ -3551,11 +3551,12 @@
} mdThreadInit;
#ifndef MD_CONFIG_ATOMIC_SUPPORT
-int mdFreeOpCallback(void *chunk, void *userpointer)
+int mdFreeOpCallback(void *chunk, void *UNUSED(userpointer))
{
mdOp *op;
- op = chunk;
+ op = (mdOp *)chunk;
mtSpinDestroy(&op->spinlock);
+ return 0;
}
#endif
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits