예제 #1
0
OSStatus
MD_CriticalRegionCreate(MDCriticalRegionID * outCriticalRegionID)
{
  MDCriticalRegionDataPtr newCriticalRegionPtr;
  MPSemaphoreID           mpSemaphoreID;
  OSStatus                err = noErr;

  if (outCriticalRegionID == NULL)
    return paramErr;

  *outCriticalRegionID = NULL;

  newCriticalRegionPtr = (MDCriticalRegionDataPtr)MPAllocateAligned(sizeof(MDCriticalRegionData),
                        kMPAllocateDefaultAligned, kMPAllocateClearMask);
  if (newCriticalRegionPtr == NULL)
    return memFullErr;

  // Note: this semaphore is pre-fired (ready!)
  err = MPCreateBinarySemaphore(&mpSemaphoreID);
  if (err == noErr)
  {
    newCriticalRegionPtr->mMPTaskID = kInvalidID;
    newCriticalRegionPtr->mDepthCount = 0;
    newCriticalRegionPtr->mMPSemaphoreID = mpSemaphoreID;

    *outCriticalRegionID = (MDCriticalRegionID)newCriticalRegionPtr;
  }
  else
  {
    MPFree((LogicalAddress)newCriticalRegionPtr);
  }

  return err;
}
예제 #2
0
파일: main.c 프로젝트: Dangr8/Cities3D
void SetupReverb()
{
	/*
	    REVERB SETUP
	*/
	/* something to fiddle with. */
	int delay[REVERB_NUMTAPS]	= { 131, 149, 173, 211, 281, 401, 457};	/* prime numbers make it sound good! */
	int volume[REVERB_NUMTAPS]	= { 120, 100,  95,  90,  80,  60,  50};
	int pan[REVERB_NUMTAPS]		= { 100, 128, 128, 152, 128, 100, 152};
	int count;

	for (count=0; count< REVERB_NUMTAPS; count++)
	{
		DSP_ReverbTap[count].delayms		= delay[count];	
		DSP_ReverbTap[count].volume			= volume[count];
		DSP_ReverbTap[count].pan			= pan[count];
		DSP_ReverbTap[count].historyoffset	= 0;
		DSP_ReverbTap[count].historylen		= (DSP_ReverbTap[count].delayms * 44100 / 1000);
		if (DSP_ReverbTap[count].historylen < FSOUND_DSP_GetBufferLength())
			DSP_ReverbTap[count].historylen = FSOUND_DSP_GetBufferLength();	/* just in case our calc is not the same. */

#ifdef __MACH__
        DSP_ReverbTap[count].historybuff    = (char *)calloc(DSP_ReverbTap[count].historylen, 4);
#else
		if (MPLibraryIsLoaded())
		{
		    DSP_ReverbTap[count].historybuff	= (char *)MPAllocateAligned(DSP_ReverbTap[count].historylen * 4,
		                                                    kMPAllocateDefaultAligned, kMPAllocateClearMask);	/* * 4 is for 16bit stereo (mmx only) */
		}
		if (!DSP_ReverbTap[count].historybuff)
		{
		    printf("Memory not allocated!");
		    exit (EXIT_FAILURE);
		}
#endif
		
		DSP_ReverbTap[count].workarea		= NULL;
		DSP_ReverbTap[count].Unit			= FSOUND_DSP_Create(&DSP_ReverbCallback, FSOUND_DSP_DEFAULTPRIORITY_USER+20+(count*2),	(void *)&DSP_ReverbTap[count]);

		FSOUND_DSP_SetActive(DSP_ReverbTap[count].Unit, TRUE);
	}
}
static OSStatus RunOneServer(InetHost ipAddr)
	// This routine is the main line of the thread that runs
	// an HTTP server.  ipAddr is the address on which the
	// server is listening.
	//
	// The routine uses a directory whose name is the
	// dotted decimal string representation of ipAddr as the
	// root directory of the HTTP server.
{
	OSStatus 	err;
	OSStatus 	junk;
	Str255 		ipAddrString;
	FSSpec 		dirSpec;
	CInfoPBRec 	cpb;
	ServerContext *context;
	MPTaskID    junkServerThread;
	
	// Allocate a context for the preemptive thread.
	
	err = noErr;
	context = (ServerContext *) MPAllocateAligned(sizeof(*context), kMPAllocateDefaultAligned, kNilOptions);
	if (context == NULL) {
		err = memFullErr;
	}
	
	// Fill out the context.  We do this here because it needs 
	// to use services that aren't MP-safe.
	
	if (err == noErr) {
		context->ipAddr = ipAddr;
		
		// Get ipAddr as a dotted decimal Pascal string.
		OTInetHostToString(ipAddr, ((char *) ipAddrString) + 1);
		ipAddrString[0] = OTStrLength(((char *) ipAddrString) + 1);
		
		// Find the associated dirID, creating the directory
		// if necessary.

		junk = MoreProcGetCurrentProcessFSSpec(&dirSpec);
		assert(junk == noErr);
			
		(void) FSMakeFSSpec(dirSpec.vRefNum, dirSpec.parID, ipAddrString, &dirSpec);
		context->rootVRefNum = dirSpec.vRefNum;
		err = FSpGetCatInfo(&dirSpec, 0, &cpb);
		if (err == noErr && ( (cpb.hFileInfo.ioFlAttrib & (1 << 4)) != 0) ) {
			context->rootDirID = cpb.hFileInfo.ioDirID;
		} else {
			err = FSpDirCreate(&dirSpec, 0, (SInt32 *) &context->rootDirID);
		}
	}
	
	// Start a preemptive thread to run an HTTP server on the IP address.
	
	if (err == noErr) {
		err = MPCreateTask(HTTPServerProc, context, 65536, kInvalidID, NULL, NULL, kNilOptions, &junkServerThread);
		if (err == noErr) {
			context = NULL;				// it's now the task's responsibility
		}
	}
	if (context != NULL) {
		MPFree(context);
	}
	
	return err;
}
예제 #4
0
/* part of user-callable API */
void *X(malloc)(size_t n)
{
     void *p;

#if defined(MIN_ALIGNMENT)

#  if defined(WITH_OUR_MALLOC16) && (MIN_ALIGNMENT == 16)
     p = our_malloc16(n);
#    undef real_free
#    define real_free our_free16

#  elif defined(HAVE_MEMALIGN)
     p = memalign(MIN_ALIGNMENT, n);

#  elif defined(HAVE_POSIX_MEMALIGN)
     /* note: posix_memalign is broken in glibc 2.2.5: it constrains
	the size, not the alignment, to be (power of two) * sizeof(void*).
        The bug seems to have been fixed as of glibc 2.3.1. */
     if (posix_memalign(&p, MIN_ALIGNMENT, n))
	  p = (void*) 0;

#  elif defined(__ICC) || defined(__INTEL_COMPILER) || defined(HAVE__MM_MALLOC)
     /* Intel's C compiler defines _mm_malloc and _mm_free intrinsics */
     p = (void *) _mm_malloc(n, MIN_ALIGNMENT);
#    undef real_free
#    define real_free _mm_free

#  elif defined(_MSC_VER)
     /* MS Visual C++ 6.0 with a "Processor Pack" supports SIMD
	and _aligned_malloc/free (uses malloc.h) */
     p = (void *) _aligned_malloc(n, MIN_ALIGNMENT);
#    undef real_free
#    define real_free _aligned_free

#  elif (defined(__MACOSX__) || defined(__APPLE__)) && (MIN_ALIGNMENT <= 16)
     /* MacOS X malloc is already 16-byte aligned */
     p = malloc(n);

#  elif defined(macintosh) /* MacOS 9 */
     p = (void *) MPAllocateAligned(n,
#    if MIN_ALIGNMENT == 8
				    kMPAllocate8ByteAligned,
#    elif MIN_ALIGNMENT == 16
				    kMPAllocate16ByteAligned,
#    elif MIN_ALIGNMENT == 32
				    kMPAllocate32ByteAligned,
#    else
#      error "Unknown alignment for MPAllocateAligned"
#    endif
				    0);
#    undef real_free
#    define real_free MPFree

#  else
     /* Add your machine here and send a patch to [email protected] 
        or (e.g. for Windows) configure --with-our-malloc16 */
#    error "Don't know how to malloc() aligned memory."
#  endif

#else /* !defined(MIN_ALIGMENT) */
     p = malloc(n);
#endif

     return p;
}