diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1996-12-08 00:08:45 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1996-12-08 00:08:45 +0000 |
commit | e5aac168f9bb01257e912050aa5137551ea394e7 (patch) | |
tree | 5b32d0edb97c3bebcf6aee4a2d57aa40763f7b29 /ace/Module.cpp | |
parent | a54582c074ef294353ef67380b782e957aad3522 (diff) | |
download | ATCD-e5aac168f9bb01257e912050aa5137551ea394e7.tar.gz |
jammer
Diffstat (limited to 'ace/Module.cpp')
-rw-r--r-- | ace/Module.cpp | 152 |
1 files changed, 109 insertions, 43 deletions
diff --git a/ace/Module.cpp b/ace/Module.cpp index 35db70ee7ac..09b562497ab 100644 --- a/ace/Module.cpp +++ b/ace/Module.cpp @@ -21,21 +21,37 @@ ACE_Module<ACE_SYNCH_2>::dump (void) const } template <ACE_SYNCH_1> void -ACE_Module<ACE_SYNCH_2>::writer (ACE_Task<ACE_SYNCH_2> *q) +ACE_Module<ACE_SYNCH_2>::writer (ACE_Task<ACE_SYNCH_2> *q, + int flags /* = M_DELETE_WRITER */) { ACE_TRACE ("ACE_Module<ACE_SYNCH_2>::writer"); + + // Close and maybe delete old writer + this->close_i (1); + this->q_pair_[1] = q; if (q != 0) ACE_CLR_BITS (q->flags_, ACE_Task_Flags::ACE_READER); + + // don't allow the caller to change the reader status + ACE_SET_BITS (flags_, (flags & M_DELETE_WRITER)); } template <ACE_SYNCH_1> void -ACE_Module<ACE_SYNCH_2>::reader (ACE_Task<ACE_SYNCH_2> *q) +ACE_Module<ACE_SYNCH_2>::reader (ACE_Task<ACE_SYNCH_2> *q, + int flags /* = M_DELETE_READER */) { ACE_TRACE ("ACE_Module<ACE_SYNCH_2>::reader"); + + // Close and maybe delete old writer + this->close_i (0); + this->q_pair_[0] = q; if (q != 0) ACE_SET_BITS (q->flags_, ACE_Task_Flags::ACE_READER); + + // don't allow the caller to change the reader status + ACE_SET_BITS (flags_, (flags & M_DELETE_READER)); } // Link this ACE_Module on top of ACE_Module M. @@ -53,32 +69,58 @@ template <ACE_SYNCH_1> int ACE_Module<ACE_SYNCH_2>::open (const char *mod_name, ACE_Task<ACE_SYNCH_2> *writer_q, ACE_Task<ACE_SYNCH_2> *reader_q, - void *arg) + void *arg, + int flags /* = M_DELETE */) { ACE_TRACE ("ACE_Module<ACE_SYNCH_2>::open"); this->name (mod_name); this->arg_ = arg; - if (writer_q == 0) + // we may already have readers and/or writers + if (this->reader ()) + this->close_i (0); + + if (this->writer ()) + this->close_i (1); + + + if (writer_q == 0) { writer_q = new ACE_Thru_Task<ACE_SYNCH_2>; - if (reader_q == 0) + ACE_SET_BITS (flags, M_DELETE_WRITER); + } + + if (reader_q == 0) { reader_q = new ACE_Thru_Task<ACE_SYNCH_2>; + ACE_SET_BITS (flags, M_DELETE_READER); + } + + this->reader (reader_q); + this->writer (writer_q); + + // Setup back pointers. + reader_q->mod_ = this; + writer_q->mod_ = this; + + // Save the flags + ACE_SET_BITS (flags_, flags); // Make sure that the memory is allocated before proceding. if (writer_q == 0 || reader_q == 0) { + this->close_i (0); + this->close_i (1); + + // Reset back pointers. + reader_q->mod_ = NULL; + writer_q->mod_ = NULL; + 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; } @@ -104,14 +146,13 @@ ACE_Module<ACE_SYNCH_2>::ACE_Module (void) // Do nothing... } -// Should never be called... template <ACE_SYNCH_1> ACE_INLINE ACE_Module<ACE_SYNCH_2>::~ACE_Module (void) { ACE_TRACE ("ACE_Module<ACE_SYNCH_2>::~ACE_Module"); // Only close down if we haven't already done so. - if (this->reader () != 0 || this->writer () != 0) + if (this->reader () || this->writer ()) this->close (); } @@ -119,52 +160,77 @@ template <ACE_SYNCH_1> ACE_INLINE ACE_Module<ACE_SYNCH_2>::ACE_Module (const char *mod_name, ACE_Task<ACE_SYNCH_2> *writer_q, ACE_Task<ACE_SYNCH_2> *reader_q, - void *flags) + void *args, + int flags /* = M_DELETE */) { ACE_TRACE ("ACE_Module<ACE_SYNCH_2>::ACE_Module"); - if (this->open (mod_name, writer_q, reader_q, flags) == -1) + + this->q_pair_[0] = 0; + this->q_pair_[1] = 0; + + if (this->open (mod_name, writer_q, reader_q, args, flags) == -1) ACE_ERROR ((LM_ERROR, "%p\n", "ACE_Module")); } template <ACE_SYNCH_1> int -ACE_Module<ACE_SYNCH_2>::close (u_long flags) +ACE_Module<ACE_SYNCH_2>::close (int flags /* = M_DELETE_NONE */) { ACE_TRACE ("ACE_Module<ACE_SYNCH_2>::close"); + ACE_Task<ACE_SYNCH_2> *reader_q = this->reader (); ACE_Task<ACE_SYNCH_2> *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); - } + ACE_SET_BITS (flags_, flags); - if (writer_q != 0) - { - if (writer_q->close () == -1) - result = -1; - writer_q->flush (); - writer_q->next (0); - } + if (this->close_i (0) == -1) + result = -1; - if (ACE_BIT_ENABLED (flags, ACE_Module<ACE_SYNCH_2>::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; - } + if (this->close_i (1) == -1) + result = -1; - // 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; } +template <ACE_SYNCH_1> int +ACE_Module<ACE_SYNCH_2>::close_i (int which) +{ + ACE_TRACE ("ACE_Module<ACE_SYNCH_2>::close_i"); + + if (this->q_pair_[which] == NULL) + return 0; + + // Copy task pointer to prevent problems when ACE_Task::close + // changes the task pointer + ACE_Task<ACE_SYNCH_2> *task = this->q_pair_[which]; + + // Change so that close doesn't get called again from the task base. + + // Now close the task + int result = 0; + + if (task->module_closed() == -1) + result = -1; + + task->flush (); + task->next (0); + + // Should we also delete it ? + if (ACE_BIT_ENABLED (flags_, which+1) ) { + // Only delete the Tasks if there aren't any more threads + // running in them. + if (task->thr_count() == 0) + delete task; + } + + // Set the tasks pointer to NULL so that we don't try to close() + // this object again if the destructor gets called. + this->q_pair_[which] = NULL; + + // Finally remove the delete bit. + ACE_CLR_BITS (flags_, which + 1); + + return result; +} #endif /* ACE_MODULE_C */ |