The DejaVU Framework -- hush 3.0
[.] Papers Tutorials Examples Manuals Interfaces Sources Packages Resources ?

source: mutex.c hush-3.0b4/auxiliary/net/thread


[.] - [up] [top] - index README make include source scripts
  // a simple mutex class
  //
  // October 1995
  // Bastiaan Sch\"onhage
  
  include <hush/source.h>
  
  include <net/thread/thread.h>
  include <net/thread/mutex.h>
  include <hush/flags.h>
  
  ifdef THREADS
  include <synch.h>
  endif
  
  ifndef THREADS
  mutex::mutex(int) {
  else
  mutex::mutex(int process) {
          mp = new mutex_t;
          if (process) mutex_init((mutex_t*) mp, USYNC_PROCESS, 0);
          else mutex_init((mutex_t*) mp, USYNC_THREAD, 0);
  endif
  }
  
  mutex::~mutex()
  {
  ifdef THREADS
          mutex_destroy((mutex_t*)mp);
          delete (mutex_t*)mp;
  endif
  }
  
  void mutex::lock()
  {
  ifdef THREADS
          mutex_lock((mutex_t*) mp);
  endif
  }
  
  void mutex::unlock()
  {        
  ifdef THREADS
          mutex_unlock((mutex_t*) mp);
  endif
  }
  
  int mutex::trylock()
  {
  ifdef THREADS
          if( mutex_trylock((mutex_t*) mp) == 0) return 1;
          else return 0;
  else
          return 0;
  endif
  }
  

[.] Papers Tutorials Examples Manuals Interfaces Sources Packages Resources ?
Hush Online Technology
hush@cs.vu.nl
09/09/98