/rusxmms/librcc

To get this branch, use:
bzr branch http://suren.me/webbzr/rusxmms/librcc

« back to all changes in this revision

Viewing changes to src/rccmutex.c

  • Committer: Suren A. Chilingaryan
  • Date: 2010-07-16 07:58:26 UTC
  • Revision ID: csa@dside.dyndns.org-20100716075826-4rvnh4iccqrqsdfj
Windows fixes and CMake scripts to build under Windows

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <stdlib.h>
21
21
#include <time.h>
22
22
 
 
23
#ifdef HAVE_UNISTD_H
 
24
# include <unistd.h>
 
25
#endif /* HAVE_UNISTD_H */
 
26
 
 
27
#ifdef WIN32
 
28
# include <windows.h>
 
29
#endif /* WIN32 */
 
30
 
23
31
#include "rccmutex.h"
24
32
 
 
33
 
25
34
#define RCC_MUTEX_SLEEP 500
26
35
 
27
36
rcc_mutex rccMutexCreate() {
49
58
 
50
59
int rccMutexLock(rcc_mutex mutex) {
51
60
#ifndef HAVE_PTHREAD
 
61
# ifdef HAVE_NANOSLEEP
52
62
    struct timespec ts;
 
63
# endif /* HAVE_NANOSLEEP */
53
64
#endif /* !HAVE_PTHREAD */
54
65
 
55
66
    if (!mutex) return -1;
58
69
    return pthread_mutex_lock(&mutex->mutex);
59
70
#else
60
71
    while (mutex->mutex) {
 
72
# if defined(HAVE_NANOSLEEP)
61
73
            ts.tv_sec = RCC_MUTEX_SLEEP / 1000000;
62
74
            ts.tv_nsec = (RCC_MUTEX_SLEEP % 1000000)*1000;
63
75
            nanosleep(&ts, NULL);
 
76
# elif defined (HAVE_USLEEP)
 
77
            usleep(RCC_MUTEX_SLEEP);
 
78
# elif defined (WIN32)
 
79
            Sleep((RCC_MUTEX_SLEEP<1000)?1:RCC_MUTEX_SLEEP/1000);
 
80
# endif /* HAVE_NANOSLEEP */
64
81
    }
65
82
    mutex->mutex = 1;
66
83