#include <scheduler.h>
#endif
-pthread_mutex_t mut;
+static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
static volatile int cpt = 0;
#ifdef SA_SIGINFO
#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;
pthread_t parent_id, child_id;
int ret;
- pthread_mutex_init(&mut, NULL);
-
parent_id = pthread_self();
pthread_mutex_lock(&mut);
- ret = pthread_create(&child_id, NULL, parent, (void *)&parent_id);
+ ret = pthread_create(&child_id, NULL, parent, (void *)parent_id);
if (ret) {
printf("pthread_create() returned %d\n", ret);
pthread_mutex_unlock(&mut);
if (siginterrupt (SIGUSR1, 0) != 0)
return -1;
+ printf("hostsim_init()\n", ret);
pthread_mutex_unlock(&mut);
return 0;