

#include <stdio.h>

#include "module1.h"
#include "private.h"

//init = -1;

void report_module(const char * name)
{
  if (init <= 0) {
      printf("Module not initialized for: %s\n", name);
      return;
  }

  lock();
  printf("Message from module: %s\n", name);
  unlock();
}

void report_module1(void)
{
  report_module("1");
}


void init_module()
{
  int e;

  if (init > 0)
      return;

  e = pthread_mutex_init(& m, NULL);
  if (e != 0) {
      printf("Failed!\n");
      return;
  }

  init = 1;
}

void free_module()
{
  if (init <= 0)
      return;

  pthread_mutex_destroy(& m);
  init = -1;
}

void lock(void)
{
  pthread_mutex_lock(& m);
}

void unlock(void)
{
  pthread_mutex_unlock(& m);
}
