- Main Page
- Related Pages
- Classes
- Files

- File List

# messshm.h

    00001 //
    00002 // messshm.h
    00003 //
    00004 // Copyright (C) 1996 Limit Point Systems, Inc.
    00005 //
    00006 // Author: Curtis Janssen <cljanss@limitpt.com>
    00007 // Maintainer: LPS
    00008 //
    00009 // This file is part of the SC Toolkit.
    00010 //
    00011 // The SC Toolkit is free software; you can redistribute it and/or modify
    00012 // it under the terms of the GNU Library General Public License as published by
    00013 // the Free Software Foundation; either version 2, or (at your option)
    00014 // any later version.
    00015 //
    00016 // The SC Toolkit is distributed in the hope that it will be useful,
    00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00019 // GNU Library General Public License for more details.
    00020 //
    00021 // You should have received a copy of the GNU Library General Public License
    00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
    00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00024 //
    00025 // The U.S. Government is granted a limited license as per AL 91-7.
    00026 //
    00027
    00028 #ifndef _util_group_messshm_h
    00029 #define _util_group_messshm_h
    00030
    00031 #include <unistd.h>
    00032 #include <sys/types.h>
    00033 #include <sys/ipc.h>
    00034 #include <sys/sem.h>
    00035 #include <sys/shm.h>
    00036
    00037 #include <util/group/message.h>
    00038
    00039 namespace sc {
    00040
    00041 #define SHMCOMMBUFSIZE 1500000
    00042
    00043 /* Set the maximum number of processors (including the host). */
    00044 #define MAXPROCS 17
    00045
    00046
    00047 struct commbuf_struct {
    00048     int nmsg;
    00049     int n_wait_for_change;
    00050     int n_sync;
    00051     char buf[SHMCOMMBUFSIZE];
    00052 };
    00053 typedef struct commbuf_struct commbuf_t;
    00054
    00055 struct msgbuf_struct {
    00056     int type;
    00057     int from;
    00058     int size;
    00059 };
    00060 typedef struct msgbuf_struct msgbuf_t;
    00061
    00068 class ShmMessageGrp: public intMessageGrp {
    00069   protected:
    00070     void basic_send(int target, int type, const void* data, int nbyte);
    00071     void basic_recv(int type, void* data, int nbyte);
    00072     int basic_probe(int type);
    00073     void initialize(int nprocs);
    00074     void initialize();
    00075
    00076     // previously static variables
    00077     commbuf_t *commbuf[MAXPROCS];
    00078     int shmid;
    00079     int semid;
    00080     int change_semid;
    00081     void* sharedmem;
    00082     struct sembuf semdec;
    00083     struct sembuf seminc;
    00084
    00085     // previously static functions for semephore operations
    00086     msgbuf_t *NEXT_MESSAGE(msgbuf_t *m);
    00087     void get_change(int node);
    00088     void put_change(int node);
    00089     void wait_for_write(int node);
    00090     void release_write(int node);
    00091 #ifdef DEBUG
    00092     void print_buffer(int node, int me);
    00093 #endif
    00094   public:
    00096     ShmMessageGrp();
    00106     ShmMessageGrp(const Ref<KeyVal>&);
    00108     ShmMessageGrp(int nprocs);
    00109     ~ShmMessageGrp();
    00110     void sync();
    00111
    00112     Ref<MessageGrp> clone(void);
    00113 };
    00114
    00115 }
    00116
    00117 #endif
    00118
    00119 // Local Variables:
    00120 // mode: c++
    00121 // c-file-style: "CLJ"
    00122 // End: