*** src/lib/omniORB2/orbcore/strand.cc Fri Aug 14 13:52:23 1998 --- newsrc/lib/omniORB2/orbcore/strand.cc Mon Jan 25 18:00:53 1999 *************** *** 29,34 **** --- 29,40 ---- /* $Log: strand.cc,v $ + Revision 1.7 1999/01/25 18:00:53 sll + Fixed a bug in Sync::WrTimedLock and Sync::WrUnlock(Strand* s). + Previously, WrTimedLock does not increment the reference count of the + strand. Consequently, the strand could be deleted (when its reference count + goes to zero) while a thread is still block inside WrTimedLock. + Revision 1.6 1998/08/14 13:52:23 sll Added pragma hdrstop to control pre-compile header if the compiler feature is available. *************** *** 316,321 **** --- 322,330 ---- { CORBA::Boolean notimeout; // Note: the caller must have got the mutex s->pd_rope->pd_lock + + s->incrRefCount(1); + while (s->pd_wr_nwaiting < 0) { s->pd_wr_nwaiting--; notimeout = s->pd_wrcond.timedwait(secs,nanosecs); *************** *** 325,330 **** --- 334,342 ---- s->pd_wr_nwaiting++; if (!notimeout && s->pd_wr_nwaiting < 0) { // give up; + + s->decrRefCount(1); + return 0; } } *************** *** 334,339 **** --- 346,356 ---- s->pd_heartbeat = heartbeat; heartbeat = hb; return 1; + + // XXX The caller must release the write lock using + // Strand::Sync::WrUnlock(Strand* s) *ONLY*!!! + // Otherwise the strand reference count would be messed up. + // Fix me in future. } *************** *** 359,369 **** --- 376,397 ---- Strand:: Sync::WrUnlock(Strand* s) { + // XXX The caller must have acquired the write lock previously + // with Strand::Sync::WrTimedLock. Otherwise, the strand + // reference count would be messed up. + // Fix me in future. + // Note: the caller must have got the mutex s->pd_rope->pd_lock assert(s->pd_wr_nwaiting < 0); s->pd_wr_nwaiting = -s->pd_wr_nwaiting - 1; if (s->pd_wr_nwaiting > 0) s->pd_wrcond.signal(); + + s->decrRefCount(1); + // The strand may be idle and is dying, it should be deleted but + // it is just to dangerous to do it here. Let the strand iterator + // clean it up later. + return; }