// Module.cpp // $Id$ #if !defined (ACE_MODULE_C) #define ACE_MODULE_C #define ACE_BUILD_DLL #include "ace/Module.h" #include "ace/Stream_Modules.h" #if !defined (__ACE_INLINE__) #include "ace/Module.i" #endif /* __ACE_INLINE__ */ ACE_ALLOC_HOOK_DEFINE(ACE_Module) template void ACE_Module::dump (void) const { ACE_TRACE ("ACE_Module::dump"); } template void ACE_Module::writer (ACE_Task *q) { ACE_TRACE ("ACE_Module::writer"); this->q_pair_[1] = q; if (q != 0) ACE_CLR_BITS (q->flags_, ACE_Task_Flags::ACE_READER); } template void ACE_Module::reader (ACE_Task *q) { ACE_TRACE ("ACE_Module::reader"); this->q_pair_[0] = q; if (q != 0) ACE_SET_BITS (q->flags_, ACE_Task_Flags::ACE_READER); } // Link this ACE_Module on top of ACE_Module M. template void ACE_Module::link (ACE_Module *m) { ACE_TRACE ("ACE_Module::link"); this->next (m); this->writer ()->next (m->writer ()); m->reader ()->next (this->reader ()); } template int ACE_Module::open (const char *mod_name, ACE_Task *writer_q, ACE_Task *reader_q, void *arg) { ACE_TRACE ("ACE_Module::open"); this->name (mod_name); this->arg_ = arg; if (writer_q == 0) writer_q = new ACE_Thru_Task; if (reader_q == 0) reader_q = new ACE_Thru_Task; // Make sure that the memory is allocated before proceding. if (writer_q == 0 || reader_q == 0) { delete writer_q; delete reader_q; errno = ENOMEM; return -1; } this->reader (reader_q); this->writer (writer_q); // Setup back pointers. reader_q->mod_ = this; writer_q->mod_ = this; return 0; } // Set and get pointer to sibling ACE_Task in ACE_Module. template ACE_Task * ACE_Module::sibling (ACE_Task *orig) { ACE_TRACE ("ACE_Module::sibling"); if (this->q_pair_[0] == orig) return this->q_pair_[1]; else if (this->q_pair_[1] == orig) return this->q_pair_[0]; else return 0; } template ACE_INLINE ACE_Module::ACE_Module (void) { ACE_TRACE ("ACE_Module::ACE_Module"); this->name (""); // Do nothing... } // Should never be called... template ACE_INLINE ACE_Module::~ACE_Module (void) { ACE_TRACE ("ACE_Module::~ACE_Module"); // Only close down if we haven't already done so. if (this->reader () != 0 || this->writer () != 0) this->close (); } template ACE_INLINE ACE_Module::ACE_Module (const char *mod_name, ACE_Task *writer_q, ACE_Task *reader_q, void *flags) { ACE_TRACE ("ACE_Module::ACE_Module"); if (this->open (mod_name, writer_q, reader_q, flags) == -1) ACE_ERROR ((LM_ERROR, "%p\n", "ACE_Module")); } template int ACE_Module::close (u_long flags) { ACE_TRACE ("ACE_Module::close"); ACE_Task *reader_q = this->reader (); ACE_Task *writer_q = this->writer (); int result = 0; if (reader_q != 0) { if (reader_q->close () == -1) result = -1; reader_q->flush (); reader_q->next (0); } if (writer_q != 0) { if (writer_q->close () == -1) result = -1; writer_q->flush (); writer_q->next (0); } if (ACE_BIT_ENABLED (flags, ACE_Module::M_DELETE)) { // Only delete the Tasks if there aren't any more threads // running in them. if (reader_q->thr_count () == 0) delete reader_q; if (writer_q->thr_count () == 0) delete writer_q; } // Set the reader and writers to NULL so that we don't try to close() // this object again if the destructor gets called. this->reader (0); this->writer (0); return result; } #endif /* ACE_MODULE_C */