95#define AlignedExtent(size,alignment) \
96 (((size)+((alignment)-1)) & ~((alignment)-1))
107 if ((count == 0) || (quantum != (size/count)))
110 return((
void *) NULL);
115 if ((size == 0) || (extent < size))
116 return((
void *) NULL);
117#if defined(WIZARDSTOOLKIT_HAVE_POSIX_MEMALIGN)
118 if (posix_memalign(&memory,alignment,extent) != 0)
120#elif defined(WIZARDSTOOLKIT_HAVE__ALIGNED_MALLOC)
121 memory=_aligned_malloc(extent,alignment);
127 extent=(size+alignment-1)+
sizeof(
void *);
133 memory=(
void *)
AlignedExtent((
size_t) p+
sizeof(
void *),alignment);
134 *((
void **) memory-1)=p;
144 if (memory == (
void *) NULL)
145 return((
void *) NULL);
146#if defined(WIZARDSTOOLKIT_HAVE_POSIX_MEMALIGN)
148#elif defined(WIZARDSTOOLKIT_HAVE__ALIGNED_MALLOC)
149 _aligned_free(memory);
151 free(*((
void **) memory-1));
165 sizeof(*semaphore_info));
172#if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT)
173 omp_init_lock((omp_lock_t *) &semaphore_info->
mutex);
174#elif defined(WIZARDSTOOLKIT_THREAD_SUPPORT)
182 status=pthread_mutexattr_init(&mutex_info);
186 perror(
"unable to initialize mutex attributes");
189 status=pthread_mutex_init(&semaphore_info->
mutex,&mutex_info);
193 perror(
"unable to initialize mutex");
196 status=pthread_mutexattr_destroy(&mutex_info);
200 perror(
"unable to destroy mutex");
204#elif defined(WIZARDSTOOLKIT_HAVE_WINTHREADS)
209 status=InitializeCriticalSectionAndSpinCount(&semaphore_info->
mutex,0x400);
213 perror(
"unable to initialize critical section");
221 return(semaphore_info);
286#if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT)
287 omp_set_lock((omp_lock_t *) &semaphore_info->
mutex);
288#elif defined(WIZARDSTOOLKIT_THREAD_SUPPORT)
293 status=pthread_mutex_lock(&semaphore_info->
mutex);
297 perror(
"unable to lock mutex");
301#elif defined(WIZARDSTOOLKIT_HAVE_WINTHREADS)
302 EnterCriticalSection(&semaphore_info->
mutex);
304#if defined(WIZARDSTOOLKIT_DEBUG)
308 perror(
"unexpected recursive lock!");
345#if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT)
346 omp_destroy_lock((omp_lock_t *) &(*semaphore_info)->mutex);
347#elif defined(WIZARDSTOOLKIT_THREAD_SUPPORT)
352 status=pthread_mutex_destroy(&(*semaphore_info)->mutex);
356 perror(
"unable to destroy mutex");
360#elif defined(WIZARDSTOOLKIT_HAVE_WINTHREADS)
361 DeleteCriticalSection(&(*semaphore_info)->mutex);
363 (*semaphore_info)->signature=(~WizardSignature);
441#if defined(WIZARDSTOOLKIT_DEBUG)
445 (void) fprintf(stderr,
"Warning: semaphore lock already unlocked!\n");
446 (void) fflush(stderr);
451#if defined(WIZARDSTOOLKIT_OPENMP_SUPPORT)
452 omp_unset_lock((omp_lock_t *) &semaphore_info->
mutex);
453#elif defined(WIZARDSTOOLKIT_THREAD_SUPPORT)
458 status=pthread_mutex_unlock(&semaphore_info->
mutex);
462 perror(
"unable to unlock mutex");
466#elif defined(WIZARDSTOOLKIT_HAVE_WINTHREADS)
467 LeaveCriticalSection(&semaphore_info->
mutex);
#define ThrowFatalException(severity, tag)
static size_t GetWizardThreadId(void)
static void DestroyWizardMutex(void)
static void InitializeWizardMutex(void)
static void UnlockWizardMutex(void)
static void LockWizardMutex(void)
WizardExport void SemaphoreComponentTerminus(void)
WizardExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
WizardExport SemaphoreInfo * AcquireSemaphoreInfo(void)
static void * RelinquishSemaphoreMemory(void *memory)
WizardExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
WizardExport WizardBooleanType SemaphoreComponentGenesis(void)
WizardExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
static void * AcquireSemaphoreMemory(const size_t count, const size_t quantum)
WizardExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info)
#define AlignedExtent(size, alignment)
static WizardBooleanType IsWizardThreadEqual(const WizardThreadType id)