communicable.cpp

00001 // "comm.cpp"
00002 
00003 // (c) OPAC Team, LIFL, August 2005
00004 
00005 /* 
00006    Contact: paradiseo-help@lists.gforge.inria.fr
00007 */
00008 
00009 #include <vector>
00010 #include <map>
00011 #include <cassert>
00012 
00013 #include "communicable.h"
00014 
00015 static std :: vector <Communicable *> key_to_comm (1); /* Vector of registered cooperators */
00016 
00017 static std :: map <const Communicable *, unsigned> comm_to_key; /* Map of registered cooperators */
00018 
00019 unsigned Communicable :: num_comm = 0;
00020 
00021 Communicable :: Communicable () {
00022 
00023   comm_to_key [this] = key = ++ num_comm;
00024   key_to_comm.push_back (this);
00025   sem_init (& sem_lock, 0, 1);
00026   sem_init (& sem_stop, 0, 0);
00027 }
00028 
00029 Communicable :: ~ Communicable () {
00030 
00031 }
00032 
00033 COMM_ID Communicable :: getKey () {
00034 
00035   return key;
00036 }
00037 
00038 Communicable * getCommunicable (COMM_ID __key) {
00039 
00040   assert (__key < key_to_comm.size ());
00041   return key_to_comm [__key];  
00042 }
00043 
00044 COMM_ID getKey (const Communicable * __comm) {
00045   
00046   return comm_to_key [__comm];
00047 }
00048 
00049 void Communicable :: lock () {
00050 
00051   sem_wait (& sem_lock);
00052 }
00053 
00054 void Communicable :: unlock () {
00055 
00056   sem_post (& sem_lock);
00057 }
00058 
00059 void Communicable :: stop () {
00060 
00061   sem_wait (& sem_stop);
00062 }
00063 
00064 void Communicable :: resume () {
00065 
00066   sem_post (& sem_stop);
00067 }
00068 
00069 
00070 

Generated on Thu Jul 5 13:43:30 2007 for ParadisEO-PEO by  doxygen 1.4.7