X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=modules%2Fbase%2Fhostsim%2Fhostsim.c;h=bb77ad9e3f894444ac0a991dac52037ec057a33d;hp=87bbfc65298861e60db36fc92a9fdef3ca03584a;hb=0e9f190378d69540389fad5e231529ba153761b2;hpb=87ccd3af8abb0da3e0fa98dc8e9216fc7b676f97 diff --git a/modules/base/hostsim/hostsim.c b/modules/base/hostsim/hostsim.c index 87bbfc6..bb77ad9 100644 --- a/modules/base/hostsim/hostsim.c +++ b/modules/base/hostsim/hostsim.c @@ -49,7 +49,7 @@ #include #endif -pthread_mutex_t mut; +static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER; static volatile int cpt = 0; static struct termios oldterm; @@ -99,6 +99,26 @@ void sigusr1(__attribute__((unused)) int sig) #endif } +static int lock_count = 0; + +void hostsim_lock(void) +{ + if (lock_count++) + return; + pthread_mutex_lock(&mut); +} + +void hostsim_unlock(void) +{ + if (lock_count-- == 1) + pthread_mutex_unlock(&mut); +} + +int hostsim_islocked(void) +{ + return lock_count; +} + void host_wait_ms(int ms) { struct timeval tv, tv2, diff; @@ -245,8 +265,6 @@ int hostsim_init(void) pthread_t parent_id, child_id, child2_id, child3_id; int ret; - pthread_mutex_init(&mut, NULL); - parent_id = pthread_self(); pthread_mutex_lock(&mut); @@ -291,10 +309,11 @@ int hostsim_init(void) return 0; } -void hostsim_exit(void) +int hostsim_exit(void) { #ifdef CONFIG_MODULE_UART tcsetattr(0, TCSANOW, &oldterm); #endif + return 0; } #endif /* HOST_VERSION */