IPCMutex.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2005 Novell, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Novell, Inc., nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc., OR THE 
00022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00025 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00026 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00027 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00028 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00035 #ifndef _BLOCXX_IPCMUTEX_HPP_INCLUDE_GUARD_
00036 #define _BLOCXX_IPCMUTEX_HPP_INCLUDE_GUARD_
00037 
00038 #if !defined (BLOCXX_HAVE_SYS_IPC_H) && !defined (BLOCXX_HAVE_SYS_SEM_H)
00039  #error "Port me!"
00040 #else
00041 
00042 #include "blocxx/BLOCXX_config.h"
00043 #include "blocxx/Exception.hpp"
00044 
00045 #include <sys/types.h>
00046 #include <sys/ipc.h>
00047 #include <sys/sem.h>
00048 
00049 
00050 namespace BLOCXX_NAMESPACE
00051 {
00052 
00053 BLOCXX_DECLARE_APIEXCEPTION(IPCMutex, BLOCXX_COMMON_API);
00054 
00055 
00056 class IPCMutex
00057 {
00058 public:
00069    IPCMutex(int semId); 
00070    ~IPCMutex() {}; 
00071 
00075    void wait(); 
00076 
00080    void signal(); 
00085    int getId() { return m_semid;}
00086 
00091    static void free(int semKey); 
00092 private:
00093    int m_semid; 
00094    struct sembuf m_sbuf; 
00095    union semun
00096    {
00097       int val; 
00098       struct sumid_ds* buf; 
00099       unsigned short* array;
00100    } m_arg; 
00101 
00102 }; 
00103 
00105 
00119 class IPCMutexLock
00120 {
00121 public:
00122    IPCMutexLock(IPCMutex& sem); 
00123    ~IPCMutexLock(); 
00124 private:
00125    IPCMutex& m_sem; 
00126 }; 
00127 
00128 } // end namespace
00129 
00130 #endif // #if !defined (BLOCXX_HAVE_SYS_IPC_H) && !defined (BLOCXX_HAVE_SYS_SEM_H)
00131 #endif // #ifndef _IPCMUTEXLOCK_HPP_INCLUDE_GUARD_
00132 

Generated on Fri Jun 16 15:39:08 2006 for blocxx by  doxygen 1.4.6