123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
-
- #include <pthread.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <time.h>
- #include <sys/time.h>
- #include <assert.h>
- #include <string.h>
- #include <math.h>
- #include <errno.h>
- #include "pa_util.h"
- #if PA_TRACK_MEMORY
- static int numAllocations_ = 0;
- #endif
- void *PaUtil_AllocateMemory( long size )
- {
- void *result = malloc( size );
- #if PA_TRACK_MEMORY
- if( result != NULL ) numAllocations_ += 1;
- #endif
- return result;
- }
- void PaUtil_FreeMemory( void *block )
- {
- if( block != NULL )
- {
- free( block );
- #if PA_TRACK_MEMORY
- numAllocations_ -= 1;
- #endif
- }
- }
- int PaUtil_CountCurrentlyAllocatedBlocks( void )
- {
- #if PA_TRACK_MEMORY
- return numAllocations_;
- #else
- return 0;
- #endif
- }
- void Pa_Sleep( long msec )
- {
- #ifdef HAVE_NANOSLEEP
- struct timespec req = {0}, rem = {0};
- PaTime time = msec / 1.e3;
- req.tv_sec = (time_t)time;
- assert(time - req.tv_sec < 1.0);
- req.tv_nsec = (long)((time - req.tv_sec) * 1.e9);
- nanosleep(&req, &rem);
-
- #else
- while( msec > 999 )
- {
- usleep( 999000 );
- msec -= 999;
- }
- usleep( msec * 1000 );
- #endif
- }
- void PaUtil_InitializeClock( void )
- {
-
- }
- PaTime PaUtil_GetTime( void )
- {
- #ifdef HAVE_CLOCK_GETTIME
- struct timespec tp;
- clock_gettime(CLOCK_REALTIME, &tp);
- return (PaTime)(tp.tv_sec + tp.tv_nsec / 1.e9);
- #else
- struct timeval tv;
- gettimeofday( &tv, NULL );
- return (PaTime) tv.tv_usec / 1000000. + tv.tv_sec;
- #endif
- }
|