Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

thread_mutex.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 2000, Brown University, Providence, RI.
00003  * 
00004  *                         All Rights Reserved
00005  * 
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  * 
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00022  */
00023 
00024 #ifndef _JOT_STD_THREAD_MUTEX_H
00025 #define _JOT_STD_THREAD_MUTEX_H
00026 // This file should contain generalized thread support, but for now
00027 // it's just a pthread implmentation of a thread syncronization primitive.
00028 
00029 #ifdef USE_PTHREAD
00030 #include <pthread.h>
00031 class ThreadMutex {
00032    public:
00033       ThreadMutex() { pthread_mutex_init(&_mtx, 0); }
00034      ~ThreadMutex() { pthread_mutex_destroy(&_mtx); }
00035       void lock()   { pthread_mutex_lock(&_mtx);    }
00036       void unlock() { pthread_mutex_unlock(&_mtx);  }
00037    protected:
00038       pthread_mutex_t _mtx;
00039 };
00040 #else
00041 class ThreadMutex {
00042    public:
00043       ThreadMutex() { }
00044      ~ThreadMutex() { }
00045       void lock()   { }
00046       void unlock() { }
00047 };
00048 #endif
00049 
00050 class CriticalSection {
00051    public:
00052       CriticalSection(ThreadMutex *mutex) : _mutex(mutex) { _mutex->lock(); }
00053       ~CriticalSection() { _mutex->unlock(); }
00054    protected:
00055       ThreadMutex *_mutex;
00056 };
00057 #endif

Generated on Mon Sep 15 16:25:57 2003 for gluebase by doxygen1.2.18