diff options
author | cleeland <cleeland@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-23 01:47:23 +0000 |
---|---|---|
committer | cleeland <cleeland@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-04-23 01:47:23 +0000 |
commit | 1741649f404eb44495785a7b1b19bba270093d40 (patch) | |
tree | 07c2167f99417177c35e145ef7c204d2c183e389 | |
parent | 35947311a76dd57f4467449633017d52ba45ae05 (diff) | |
download | ATCD-1741649f404eb44495785a7b1b19bba270093d40.tar.gz |
Swept through and hopefully removed the last of the Pthreads stuff
from code. Cross ye fingers!
-rw-r--r-- | TAO/ChangeLog-98c | 14 | ||||
-rw-r--r-- | TAO/IIOP/lib/any.cpp | 46 | ||||
-rw-r--r-- | TAO/IIOP/lib/any.hh | 121 | ||||
-rw-r--r-- | TAO/IIOP/lib/except.cpp | 59 | ||||
-rw-r--r-- | TAO/IIOP/lib/except.hh | 73 | ||||
-rw-r--r-- | TAO/IIOP/lib/giop.cpp | 75 | ||||
-rw-r--r-- | TAO/IIOP/lib/giop.hh | 285 | ||||
-rw-r--r-- | TAO/IIOP/lib/iiopobj.cpp | 33 | ||||
-rw-r--r-- | TAO/IIOP/lib/iiopobj.hh | 179 | ||||
-rw-r--r-- | TAO/IIOP/lib/invoke.cpp | 503 | ||||
-rw-r--r-- | TAO/IIOP/lib/nvlist.cpp | 50 | ||||
-rw-r--r-- | TAO/IIOP/lib/nvlist.hh | 142 | ||||
-rw-r--r-- | TAO/IIOP/lib/orbobj.cpp | 263 | ||||
-rw-r--r-- | TAO/IIOP/lib/orbobj.hh | 75 | ||||
-rw-r--r-- | TAO/IIOP/lib/params.i | 6 | ||||
-rw-r--r-- | TAO/IIOP/lib/principa.cpp | 31 | ||||
-rw-r--r-- | TAO/IIOP/lib/principa.hh | 71 | ||||
-rw-r--r-- | TAO/IIOP/lib/request.cpp | 27 | ||||
-rw-r--r-- | TAO/IIOP/lib/request.hh | 90 | ||||
-rw-r--r-- | TAO/IIOP/lib/roa.cpp | 29 | ||||
-rw-r--r-- | TAO/IIOP/lib/svrrqst.cpp | 45 | ||||
-rw-r--r-- | TAO/IIOP/lib/svrrqst.hh | 147 | ||||
-rw-r--r-- | TAO/IIOP/lib/typecode.cpp | 30 | ||||
-rw-r--r-- | TAO/IIOP/lib/typecode.hh | 353 |
24 files changed, 1322 insertions, 1425 deletions
diff --git a/TAO/ChangeLog-98c b/TAO/ChangeLog-98c index cf4f5e56bef..01f9da366b7 100644 --- a/TAO/ChangeLog-98c +++ b/TAO/ChangeLog-98c @@ -1,5 +1,19 @@ Tue Apr 22 16:15:52 1997 Chris Cleeland <cleeland@cs.wustl.edu> + * IIOP/lib/roa.cpp: Removed more POSIX thread calls. + + * IIOP/lib/invoke.cpp: Changed ForceSynchronousCancellation to + ACE_Synchronous_Cancellation_Required and made it use the ACE_OS + calls. + + * IIOP/lib/{typecode,svrrqst,request,principa,orbobj,nvlist,iiopobj,giop,except,any}.*: + Removed all vestiges of pthread mutexes...they are now + ACE_Thread_Mutexes. This will likely have to change if we want to + compile something completely devoid of threads, but that's another + day. Also, the mutexes have moved from being globals to being + members on the respective classes. No files should be dependent + on thread.hh any longer. + * IIOP/lib/connect.cpp (open): Removed code obsoleted by use of the Strategy_Acceptor. diff --git a/TAO/IIOP/lib/any.cpp b/TAO/IIOP/lib/any.cpp index ccade61641e..1d75991e303 100644 --- a/TAO/IIOP/lib/any.cpp +++ b/TAO/IIOP/lib/any.cpp @@ -40,16 +40,6 @@ #include <initguid.h> - -#ifdef _POSIX_THREADS -// -// If POSIX threads are available, set up lock covering refcounts. -// -static pthread_mutex_t any_lock = PTHREAD_MUTEX_INITIALIZER; -#endif // _POSIX_THREADS - - - CORBA_TypeCode_ptr CORBA_Any::type () const { @@ -521,30 +511,24 @@ ULONG __stdcall CORBA_Any::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&any_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - return ++_refcnt; + return ++_refcnt; } ULONG __stdcall CORBA_Any::Release () { -#ifdef _POSIX_THREADS - Critical region (&any_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - if (--_refcnt != 0) - return _refcnt; + if (--_refcnt != 0) + return _refcnt; -#ifdef _POSIX_THREADS - region.leave (); -#endif + guard.release(); - delete this; - return 0; + delete this; + return 0; } HRESULT @@ -554,16 +538,16 @@ CORBA_Any::QueryInterface ( void **ppv ) { - *ppv = 0; + *ppv = 0; - if (IID_CORBA_Any == riid || IID_IUnknown == riid) - *ppv = this; + if (IID_CORBA_Any == riid || IID_IUnknown == riid) + *ppv = this; - if (*ppv == 0) - return ResultFromScode (E_NOINTERFACE); + if (*ppv == 0) + return ResultFromScode (E_NOINTERFACE); - (void) AddRef (); - return NOERROR; + (void) AddRef (); + return NOERROR; } diff --git a/TAO/IIOP/lib/any.hh b/TAO/IIOP/lib/any.hh index 4b0a6590e5b..cf5398cef29 100644 --- a/TAO/IIOP/lib/any.hh +++ b/TAO/IIOP/lib/any.hh @@ -13,75 +13,76 @@ extern const IID IID_CORBA_Any; class CORBA_Any : public IUnknown { - public: - // minor codes for exceptional returns - enum { - uninitialised_type = 0xf000, - value_without_type, - unsupported_operation - }; +public: + // minor codes for exceptional returns + enum { + uninitialised_type = 0xf000, + value_without_type, + unsupported_operation + }; - CORBA_Any (); - CORBA_Any ( - CORBA_TypeCode_ptr type, - void *value = 0, - CORBA_Boolean orb_owns_data - = CORBA_B_FALSE - ); - CORBA_Any (const CORBA_Any &a); - virtual ~CORBA_Any (); + CORBA_Any (); + CORBA_Any ( + CORBA_TypeCode_ptr type, + void *value = 0, + CORBA_Boolean orb_owns_data + = CORBA_B_FALSE + ); + CORBA_Any (const CORBA_Any &a); + virtual ~CORBA_Any (); - void *operator new (size_t, const void *p) - { return (void *) p; } - void *operator new (size_t s) - { return ::operator new (s); } - void operator delete (void *p) - { ::operator delete (p); } + void *operator new (size_t, const void *p) + { return (void *) p; } + void *operator new (size_t s) + { return ::operator new (s); } + void operator delete (void *p) + { ::operator delete (p); } - // - // NOTE: 94-9-14 has assignment operator plus many insertion, - // extraction operators, various from_xx and to_xx helper classes. - // + // + // NOTE: 94-9-14 has assignment operator plus many insertion, + // extraction operators, various from_xx and to_xx helper classes. + // - void replace ( - CORBA_TypeCode_ptr type, - const void *value, - CORBA_Boolean orb_owns_data, - CORBA_Environment &env - ); + void replace ( + CORBA_TypeCode_ptr type, + const void *value, + CORBA_Boolean orb_owns_data, + CORBA_Environment &env + ); - CORBA_TypeCode_ptr type () const; - void *value () const; + CORBA_TypeCode_ptr type () const; + void *value () const; - // - // Stuff required for COM IUnknown support - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); - HRESULT __stdcall QueryInterface ( - REFIID riid, - void **ppv - ); + // + // Stuff required for COM IUnknown support + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); + HRESULT __stdcall QueryInterface ( + REFIID riid, + void **ppv + ); - // - // Conversion to/from COM Variant types: copy constructor, - // assignment operator, cast. - // - CORBA_Any (const VARIANT &src); - CORBA_Any &operator = (const VARIANT &src); - operator VARIANT (); + // + // Conversion to/from COM Variant types: copy constructor, + // assignment operator, cast. + // + CORBA_Any (const VARIANT &src); + CORBA_Any &operator = (const VARIANT &src); + operator VARIANT (); - private: - CORBA_TypeCode_ptr _type; - void *_value; - CORBA_Boolean _orb_owns_data; +private: + CORBA_TypeCode_ptr _type; + void *_value; + CORBA_Boolean _orb_owns_data; - unsigned _refcnt; + ACE_Thread_Mutex lock_; + unsigned _refcnt; - // NOT PROVIDED - CORBA_Any &operator = (const CORBA_Any &a); + // NOT PROVIDED + CORBA_Any &operator = (const CORBA_Any &a); - // - // 94-9-14 hides unsigned char insert/extract - // + // + // 94-9-14 hides unsigned char insert/extract + // }; diff --git a/TAO/IIOP/lib/except.cpp b/TAO/IIOP/lib/except.cpp index d721c5c8c0b..a9ff6cc2a31 100644 --- a/TAO/IIOP/lib/except.cpp +++ b/TAO/IIOP/lib/except.cpp @@ -12,11 +12,12 @@ #include <limits.h> #include <string.h> #include <stdio.h> +#include <ace/Log_Msg.h> + #include <orb.hh> #include "cdr.hh" #include "debug.hh" -#include "thread.hh" #include <initguid.h> @@ -24,20 +25,6 @@ # include <widec.h> #endif -#ifdef _POSIX_THREADS -// -// If POSIX threads are available, set up lock covering refcounts. -// -static pthread_mutex_t except_lock = PTHREAD_MUTEX_INITIALIZER; - -#else - - // stub out these _POSIX_THREAD_SAFE_FUNCTIONS -# define flockfile(f) -# define funlockfile(f) -#endif // _POSIX_THREADS - - // {77420082-F276-11ce-9598-0000C07CA898} @@ -132,38 +119,32 @@ ULONG __stdcall CORBA_Exception::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&except_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - assert (_refcnt > 0); - return ++_refcnt; + assert (_refcnt > 0); + return ++_refcnt; } ULONG __stdcall CORBA_Exception::Release () { -#ifdef _POSIX_THREADS - Critical region (&except_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - assert (_refcnt > 0); - _refcnt--; - if (_refcnt != 0) - return _refcnt; + assert (_refcnt > 0); + _refcnt--; + if (_refcnt != 0) + return _refcnt; -#ifdef _POSIX_THREADS - region.leave (); -#endif + guard.release (); - // CORBA_TypeCode_ptr tc = _type->_duplicate (); + // CORBA_TypeCode_ptr tc = _type->_duplicate (); - { CORBA_Any free_it_all (_type, this, CORBA_B_TRUE); } + { CORBA_Any free_it_all (_type, this, CORBA_B_TRUE); } - // tc->Release (); + // tc->Release (); - return 0; + return 0; } HRESULT @@ -484,8 +465,7 @@ print_exception ( { CORBA_String id = x->id (); - flockfile (stream); - ACE_OS::fprintf (stream, "EXCEPTION, %s\n", info); + ACE_DEBUG((LM_ERROR, "EXCEPTION, %s\n", info)); // // XXX get rid of this logic, and rely on some member function @@ -507,8 +487,8 @@ print_exception ( // the exception value so it can be queried. // - ACE_OS::fprintf (stream, "ACE_OS::system exception, ID '%s'\n", id); - ACE_OS::fprintf (stream, "minor code = %#lx, completed = ", x2->minor ()); + ACE_DEBUG((LM_ERROR, "ACE_OS::system exception, ID '%s'\n", id)); + ACE_DEBUG((LM_ERROR, "minor code = %#lx, completed = ", x2->minor ())); switch (x2->completion ()) { case COMPLETED_YES: fputs ("YES", stream); @@ -529,7 +509,6 @@ print_exception ( // XXX we can use the exception's typecode to dump all the data // held within it ... // - ACE_OS::fprintf (stream, "user exception, ID '%s'\n", id); + ACE_DEBUG((LM_ERROR, "user exception, ID '%s'\n", id)); } - funlockfile (stream); } diff --git a/TAO/IIOP/lib/except.hh b/TAO/IIOP/lib/except.hh index 0dacdfb0900..f94d3d5a655 100644 --- a/TAO/IIOP/lib/except.hh +++ b/TAO/IIOP/lib/except.hh @@ -12,43 +12,49 @@ // and available through the Interface Repositories. Think of it as a // "globally scoped" name distinguishing each exception. // +#if !defined(ACE_ROA_EXCEPT_H) +# define ACE_ROA_EXCEPT_H + +# include <ace/Synch.h> + extern const IID IID_CORBA_Exception; extern const IID IID_CORBA_UserException; extern const IID IID_CORBA_SystemException; -class _EXPCLASS CORBA_Exception : public IUnknown { - public: - CORBA_Exception (const CORBA_Exception &src); - CORBA_Exception &operator = (const CORBA_Exception &src); - - void *operator new (size_t, const void *p) - { return (void *) p; } - void *operator new (size_t s) - { return ::operator new (s); } - void operator delete (void *p) - { ::operator delete (p); } - - - const CORBA_String id () const; - const CORBA_TypeCode_ptr type () const; - - // - // Stuff required for COM IUnknown support - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); - HRESULT __stdcall QueryInterface ( - REFIID riid, - void **ppv - ); - - CORBA_Exception ( - CORBA_TypeCode_ptr type - ); - virtual ~CORBA_Exception (); - private: - CORBA_TypeCode_ptr _type; - unsigned _refcnt; +class _EXPCLASS CORBA_Exception : public IUnknown +{ +public: + CORBA_Exception (const CORBA_Exception &src); + CORBA_Exception &operator = (const CORBA_Exception &src); + + void *operator new (size_t, const void *p) + { return (void *) p; } + void *operator new (size_t s) + { return ::operator new (s); } + void operator delete (void *p) + { ::operator delete (p); } + + + const CORBA_String id () const; + const CORBA_TypeCode_ptr type () const; + + // + // Stuff required for COM IUnknown support + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); + HRESULT __stdcall QueryInterface ( + REFIID riid, + void **ppv + ); + + CORBA_Exception (CORBA_TypeCode_ptr type); + virtual ~CORBA_Exception (); +private: + CORBA_TypeCode_ptr _type; + + ACE_Thread_Mutex lock_; + unsigned _refcnt; }; typedef CORBA_Exception *CORBA_Exception_ptr; @@ -184,3 +190,4 @@ class CORBA_Environment { CORBA_Environment (const CORBA_Environment &src); CORBA_Environment &operator = (const CORBA_Environment &src); }; +#endif diff --git a/TAO/IIOP/lib/giop.cpp b/TAO/IIOP/lib/giop.cpp index 636b63e100c..d08d9d4d8df 100644 --- a/TAO/IIOP/lib/giop.cpp +++ b/TAO/IIOP/lib/giop.cpp @@ -71,18 +71,6 @@ #define GIOP_HDR_LEN 12 // defined by GIOP 1.0 protocol -#ifdef _POSIX_THREADS -// #ifdef ACE_HAS_THREADS -// -// This lock covers the mutable info in all IIOP objref data, -// namely the forwarded-to objref. It must be held when a client -// thread is reading or modifying that data, to prevent one from -// overwriting data the other's reading or writing. -// -static pthread_mutex_t fwd_info_lock = PTHREAD_MUTEX_INITIALIZER; -#endif // ACE_HAS_THREADS - - // // Apart from the length word, headers are specified to be arrays of // bytes. They're dealt with as such, rather than using CDR routines, @@ -535,20 +523,18 @@ GIOP::Invocation::Invocation ( do_rsvp (is_roundtrip), stream (&buffer [0], sizeof buffer) { - -#ifdef _POSIX_THREADS // Leave for NT until POSIX calls removed -// #ifdef ACE_HAS_THREADS - // - // POSIX does not require this to be true, it's an implementation - // assumption that will at some point be removed but is true on - // many current POSIX.1c implementations. - // - assert (sizeof (CORBA_ULong) == sizeof (pthread_t)); - - my_request_id = (CORBA_ULong) pthread_self (); -#else - my_request_id = 0; -#endif // ACE_HAS_THREADS + // The assumption that thread ids are ints is false and horribly + // implementation-dependent, so this code just sucks. But, at least + // it will compile on multiple platforms through the magic of ACE :-/ + + //assert (sizeof (CORBA_ULong) == sizeof (ACE_thread_t)); + ACE_thread_t me = ACE_OS::thr_self(); + my_request_id = 0; + + // Copy in only as many bytes are valid, or only as many as we have + // room for, whichever is less. + // -------> What a friggin' HACK!?!?! + memcpy(&my_request_id, &me, ACE_MIN(sizeof(me), sizeof(my_request_id))); } GIOP::Invocation::~Invocation () @@ -670,10 +656,7 @@ GIOP::Invocation::start ( assert (endpoint == 0); assert (_data != 0); -#ifdef _POSIX_THREADS -// #ifdef ACE_HAS_THREADS - Critical section (&fwd_info_lock); -#endif // ACE_HAS_THREADS + ACE_GUARD(ACE_Thread_Mutex, guard, lock_); if (_data->fwd_profile != 0) { key = &_data->fwd_profile->object_key; @@ -844,18 +827,15 @@ GIOP::Invocation::invoke ( // error reports to applications. // { -#ifdef _POSIX_THREADS -// #ifdef ACE_HAS_THREADS - Critical section (&fwd_info_lock); -#endif // ACE_HAS_THREADS + ACE_GUARD(ACE_Thread_Mutex, guard, lock_); - delete _data->fwd_profile; - _data->fwd_profile = 0; + delete _data->fwd_profile; + _data->fwd_profile = 0; - (void) ACE_OS::closesocket (endpoint->fd); - endpoint->fd = ACE_INVALID_HANDLE; - endpoint = 0; - return LOCATION_FORWARD; + (void) ACE_OS::closesocket (endpoint->fd); + endpoint->fd = ACE_INVALID_HANDLE; + endpoint = 0; + return LOCATION_FORWARD; } case Request: @@ -1066,15 +1046,13 @@ GIOP::Invocation::invoke ( // that one of the facets of this object will be an IIOP // invocation profile. // - if (CDR::decoder (_tc_CORBA_Object, &obj, 0, &stream, env) - != CORBA_TypeCode::TRAVERSE_CONTINUE - || obj->QueryInterface (IID_IIOP_Object, (void **)&obj2) - != NOERROR - ) { + if (CDR::decoder (_tc_CORBA_Object, &obj, 0, &stream, env) != CORBA_TypeCode::TRAVERSE_CONTINUE + || obj->QueryInterface (IID_IIOP_Object, (void **)&obj2) != NOERROR) + { dexc (env, "invoke, location forward"); send_error (endpoint->fd); return SYSTEM_EXCEPTION; - } + } CORBA_release (obj); // @@ -1088,10 +1066,7 @@ GIOP::Invocation::invoke ( // be recorded here. (This is just an optimization, and is // not related to correctness.) // -#ifdef _POSIX_THREADS -// #ifdef ACE_HAS_THREADS - Critical section (&fwd_info_lock); -#endif // ACE_HAS_THREADS + ACE_GUARD(ACE_Thread_Mutex, guard, lock_); delete _data->fwd_profile; _data->fwd_profile = new IIOP::ProfileBody (obj2->profile); diff --git a/TAO/IIOP/lib/giop.hh b/TAO/IIOP/lib/giop.hh index 0043872c595..4a575a4e69f 100644 --- a/TAO/IIOP/lib/giop.hh +++ b/TAO/IIOP/lib/giop.hh @@ -110,171 +110,162 @@ class IOP { // namespace }; -class GIOP { // namespace +class GIOP // namespace +{ +public: + struct Version { CORBA_Octet major, minor; }; - public: - struct Version { CORBA_Octet major, minor; }; + // + // GIOP protocol version information + // + enum { MY_MAJOR = 1, MY_MINOR = 0 }; // 1.0 - // - // GIOP protocol version information - // - enum { MY_MAJOR = 1, MY_MINOR = 0 }; // 1.0 + // + // All GIOP messages include a header and message type. + // + enum MsgType { + Request = 0, // sent by client + Reply = 1, // by server + CancelRequest = 2, // by client + LocateRequest = 3, // by client + LocateReply = 4, // by server + CloseConnection = 5, // by server + MessageError = 6, // by both + EndOfFile = 7 // "discovered" by either + }; + + struct MessageHeader { + CORBA_Char magic [4]; // "GIOP" + Version giop_version; + CORBA_Octet byte_order; // 0 = big, 1 = little + CORBA_Octet message_type; // MsgType above + CORBA_ULong message_size; // in byte_order! + }; + // + // Support for Implicit ORB Service Context + // + typedef CORBA_ULong ServiceID; + enum { + TransactionService = 0 // - // All GIOP messages include a header and message type. + // more service IDs may be defined by OMG // - enum MsgType { - Request = 0, // sent by client - Reply = 1, // by server - CancelRequest = 2, // by client - LocateRequest = 3, // by client - LocateReply = 4, // by server - CloseConnection = 5, // by server - MessageError = 6, // by both - EndOfFile = 7 // "discovered" by either - }; + }; + struct ServiceContext { + ServiceID context_id; + opaque context_data; + }; + typedef CORBA_SEQUENCE <ServiceContext> ServiceContextList; - struct MessageHeader { - CORBA_Char magic [4]; // "GIOP" - Version giop_version; - CORBA_Octet byte_order; // 0 = big, 1 = little - CORBA_Octet message_type; // MsgType above - CORBA_ULong message_size; // in byte_order! - }; + // + // Request, Reply headers + // + struct RequestHeader { + ServiceContextList service_info; + CORBA_ULong request_id; + CORBA_Boolean response_expected; + opaque object_key; + CORBA_String operation; + CORBA_Principal_ptr requesting_principal; + }; + + enum ReplyStatusType { + NO_EXCEPTION, + USER_EXCEPTION, + SYSTEM_EXCEPTION, + LOCATION_FORWARD + }; + + struct ReplyHeader { + ServiceContextList service_info; + CORBA_ULong request_id; + ReplyStatusType reply_status; + }; - // - // Support for Implicit ORB Service Context - // - typedef CORBA_ULong ServiceID; - enum { - TransactionService = 0 - // - // more service IDs may be defined by OMG - // - }; - struct ServiceContext { - ServiceID context_id; - opaque context_data; - }; - typedef CORBA_SEQUENCE <ServiceContext> ServiceContextList; + // + // Cancellation -- applies both to Requests and LocateRequests. + // + struct CancelRequestHeader { + CORBA_ULong request_id; + }; - // - // Request, Reply headers - // - struct RequestHeader { - ServiceContextList service_info; - CORBA_ULong request_id; - CORBA_Boolean response_expected; - opaque object_key; - CORBA_String operation; - CORBA_Principal_ptr requesting_principal; - }; + // + // Location service support + // + struct LocateRequestHeader { + CORBA_ULong request_id; + opaque object_key; + }; - enum ReplyStatusType { - NO_EXCEPTION, - USER_EXCEPTION, - SYSTEM_EXCEPTION, - LOCATION_FORWARD - }; + enum LocateStatusType { + UNKNOWN_OBJECT, + OBJECT_HERE, + OBJECT_FORWARD + }; - struct ReplyHeader { - ServiceContextList service_info; - CORBA_ULong request_id; - ReplyStatusType reply_status; - }; + struct LocateReplyHeader { + CORBA_ULong request_id; + LocateStatusType locate_status; + }; - // - // Cancellation -- applies both to Requests and LocateRequests. - // - struct CancelRequestHeader { - CORBA_ULong request_id; - }; + + // + // Invocation: Sends a Request, optionally reads associated Reply. + // Uses transport info passed in, doesn't locate anything. + // + class Invocation + { + public: + Invocation (IIOP_Object* data, + const char* operation, + CORBA_Boolean is_roundtrip); + ~Invocation (); // - // Location service support + // "start" goes beyond initialising data structures, and + // makes calls that may fail -- and thus throw exceptions. // - struct LocateRequestHeader { - CORBA_ULong request_id; - opaque object_key; - }; + void start(CORBA_Environment& env); - enum LocateStatusType { - UNKNOWN_OBJECT, - OBJECT_HERE, - OBJECT_FORWARD - }; + void put_param(CORBA_TypeCode_ptr tc, void* value, CORBA_Environment& env) + { + (void) CDR::encoder (tc, value, 0, &stream, env); + } - struct LocateReplyHeader { - CORBA_ULong request_id; - LocateStatusType locate_status; - }; + ReplyStatusType invoke(CORBA_ExceptionList& exceptions, + CORBA_Environment& env); + void get_value(CORBA_TypeCode_ptr tc, + void* value, + CORBA_Environment& env) + { + (void) CDR::decoder (tc, value, 0, &stream, env); + } - // - // Invocation: Sends a Request, optionally reads associated Reply. - // Uses transport info passed in, doesn't locate anything. - // - class Invocation { - public: - Invocation ( - IIOP_Object *data, - const char *operation, - CORBA_Boolean is_roundtrip - ); - ~Invocation (); + // no CORBA_Context support (deprecated) - // - // "start" goes beyond initialising data structures, and - // makes calls that may fail -- and thus throw exceptions. - // - void start ( - CORBA_Environment &env - ); - - void put_param ( - CORBA_TypeCode_ptr tc, - void *value, - CORBA_Environment &env - ) - { - (void) CDR::encoder (tc, value, 0, &stream, env); - } - - ReplyStatusType invoke ( - CORBA_ExceptionList &exceptions, - CORBA_Environment &env - ); - - void get_value ( - CORBA_TypeCode_ptr tc, - void *value, - CORBA_Environment &env - ) - { - (void) CDR::decoder (tc, value, 0, &stream, env); - } - - // no CORBA_Context support (deprecated) - - private: - IIOP_Object *_data; - const char *opname; - CORBA_Boolean do_rsvp; - CORBA_ULong my_request_id; - - unsigned char buffer [CDR::DEFAULT_BUFSIZE]; - CDR stream; - - autorelease <client_endpoint> endpoint; - }; + private: + IIOP_Object* _data; + const char* opname; + CORBA_Boolean do_rsvp; + CORBA_ULong my_request_id; + ACE_Thread_Mutex lock_; - // - // Close a connection, first sending GIOP::CloseConnection - // - static void close_connection (ACE_SOCK_Stream &fd, void *ctx); - static void close_connection (ACE_HANDLE &fd, void *ctx); - // + unsigned char buffer [CDR::DEFAULT_BUFSIZE]; + CDR stream; + + autorelease <client_endpoint> endpoint; + }; + + // + // Close a connection, first sending GIOP::CloseConnection + // + static void close_connection (ACE_SOCK_Stream &fd, void *ctx); + static void close_connection (ACE_HANDLE &fd, void *ctx); + + // // Generic server side data dispatch -- called for all file descriptors // on which incoming messages are expected. // @@ -308,9 +299,9 @@ class GIOP { // namespace static CORBA_Boolean send_message (CDR& stream, ACE_SOCK_Stream& peer); static CORBA_Boolean send_message (CDR& stream, ACE_HANDLE& connection); - // - // Reads message, returns message type from header - // + // + // Reads message, returns message type from header + // static MsgType read_message (ACE_SOCK_Stream& peer, CDR& msg, CORBA_Environment& env); static MsgType read_message (ACE_HANDLE& connection, CDR& msg, CORBA_Environment& env); }; diff --git a/TAO/IIOP/lib/iiopobj.cpp b/TAO/IIOP/lib/iiopobj.cpp index 7ede9b7df17..736175e6cbf 100644 --- a/TAO/IIOP/lib/iiopobj.cpp +++ b/TAO/IIOP/lib/iiopobj.cpp @@ -18,20 +18,9 @@ #include <stub.hh> -#include "thread.hh" - #include "iiopobj.hh" -#ifdef _POSIX_THREADS -// -// If POSIX threads are available, set up lock covering refcounts. -// -static pthread_mutex_t iiopobj_lock = PTHREAD_MUTEX_INITIALIZER; -#endif // _POSIX_THREADS - - - IIOP::ProfileBody::ProfileBody ( const IIOP::ProfileBody &src ) : @@ -152,30 +141,24 @@ ULONG __stdcall IIOP_Object::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&iiopobj_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - return ++_refcount; + return ++_refcount; } ULONG __stdcall IIOP_Object::Release () { -#ifdef _POSIX_THREADS - Critical region (&iiopobj_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - if (--_refcount != 0) - return _refcount; + if (--_refcount != 0) + return _refcount; -#ifdef _POSIX_THREADS - region.leave (); -#endif + guard.release(); - delete this; - return 0; + delete this; + return 0; } diff --git a/TAO/IIOP/lib/iiopobj.hh b/TAO/IIOP/lib/iiopobj.hh index 1ca702b23b3..45e0e4d7196 100644 --- a/TAO/IIOP/lib/iiopobj.hh +++ b/TAO/IIOP/lib/iiopobj.hh @@ -12,6 +12,10 @@ #ifndef _iiopobj_hh #define _iiopobj_hh +# if !defined(ACE_HAS_THREADS) +typedef ACE_Null_Mutex ACE_Thread_Mutex; +# endif + typedef CORBA_SEQUENCE <CORBA_Octet> opaque; class _EXPCLASS IIOP @@ -60,94 +64,95 @@ extern "C" const IID IID_IIOP_Object; class _EXPCLASS IIOP_Object : public STUB_Object { - public: - // - // stub-based invocation - // - void do_call ( - CORBA_Environment &env, - const calldata *info, - ... - ); - - // - // DII based invocation - // - void do_dynamic_call ( - const char *opname, - CORBA_Boolean is_roundtrip, - CORBA_NVList_ptr args, - CORBA_NamedValue_ptr result, - CORBA_Flags flags, - CORBA_ExceptionList &exceptions, - CORBA_Environment &env - ); - - // - // Support for tables keyed by objrefs. - // - CORBA_ULong hash ( - CORBA_ULong maximum, - CORBA_Environment &env - ); - CORBA_Boolean is_equivalent ( - CORBA_Object_ptr other_obj, - CORBA_Environment &env - ); - - // - // XXX All objref representations should know how to marshal themselves. - // That will involve ensuring that the IOR that gets marshaled talks a - // specific protocol, otherwise the target of a message would not be - // invoke using the objref it receives (compromising functionality in - // a very basic and mysterious mannter). So for example an objref might - // need to create a proxy for itself rather than marshaling its own - // representation. [ The IIOP engine does not need to worry about such - // issues since it only supports one protocol -- the problem won't show - // up. "Multiprotocol ORBs" will need to solve that problem though. ] - // - - IIOP::ProfileBody profile; - IIOP::ProfileBody *fwd_profile; - - IIOP_Object (char *repository_id) - : fwd_profile (0), base (this), - STUB_Object (repository_id), - _refcount (1) - { } - - // - // COM stuff - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); - HRESULT __stdcall QueryInterface ( - REFIID type_id, - void **ppv - ); - - private: - CORBA_Object base; - unsigned _refcount; - - // - // Destructor is to be called only through Release() - // - ~IIOP_Object () - { assert (_refcount == 0); - delete fwd_profile; } - - // - // Disallow copy constructor and assignment operator - // - IIOP_Object (const IIOP_Object &); - operator = (const IIOP_Object &); +public: + // + // stub-based invocation + // + void do_call ( + CORBA_Environment &env, + const calldata *info, + ... + ); + + // + // DII based invocation + // + void do_dynamic_call ( + const char *opname, + CORBA_Boolean is_roundtrip, + CORBA_NVList_ptr args, + CORBA_NamedValue_ptr result, + CORBA_Flags flags, + CORBA_ExceptionList &exceptions, + CORBA_Environment &env + ); + + // + // Support for tables keyed by objrefs. + // + CORBA_ULong hash ( + CORBA_ULong maximum, + CORBA_Environment &env + ); + CORBA_Boolean is_equivalent ( + CORBA_Object_ptr other_obj, + CORBA_Environment &env + ); + + // + // XXX All objref representations should know how to marshal themselves. + // That will involve ensuring that the IOR that gets marshaled talks a + // specific protocol, otherwise the target of a message would not be + // invoke using the objref it receives (compromising functionality in + // a very basic and mysterious mannter). So for example an objref might + // need to create a proxy for itself rather than marshaling its own + // representation. [ The IIOP engine does not need to worry about such + // issues since it only supports one protocol -- the problem won't show + // up. "Multiprotocol ORBs" will need to solve that problem though. ] + // + + IIOP::ProfileBody profile; + IIOP::ProfileBody *fwd_profile; + + IIOP_Object (char *repository_id) + : fwd_profile (0), base (this), + STUB_Object (repository_id), + _refcount (1) + { } + + // + // COM stuff + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); + HRESULT __stdcall QueryInterface ( + REFIID type_id, + void **ppv + ); + +private: + CORBA_Object base; + ACE_Thread_Mutex lock_; + unsigned _refcount; + + // + // Destructor is to be called only through Release() + // + ~IIOP_Object () + { assert (_refcount == 0); + delete fwd_profile; } + + // + // Disallow copy constructor and assignment operator + // + IIOP_Object (const IIOP_Object &); + operator = (const IIOP_Object &); #if defined (__GNUG__) - // - // G++ (even 2.6.3) stupidly thinks instances can't be - // created. This de-warns. - // - friend class everyone_needs_a_friend; + // + // G++ (even 2.6.3) stupidly thinks instances can't be + // created. This de-warns. + // + friend class everyone_needs_a_friend; #endif }; diff --git a/TAO/IIOP/lib/invoke.cpp b/TAO/IIOP/lib/invoke.cpp index beaa47a71b8..615bd83f944 100644 --- a/TAO/IIOP/lib/invoke.cpp +++ b/TAO/IIOP/lib/invoke.cpp @@ -33,11 +33,42 @@ #include <orb.hh> #include "cdr.hh" -#include "thread.hh" #include "debug.hh" #include "giop.hh" #include "connmgr.hh" +class ACE_Synchronous_Cancellation_Required +// = TITLE +// +// ACE_Synchronous_Cancellation_Required +// +// = DESCRIPTION +// +// Stick one of these at the beginning of a block that can't +// support asynchronous cancellation, and which must be +// cancel-safe. +// +// = EXAMPLE +// somefunc() +// { +// ACE_Synchronous_Cancellation_Required NOT_USED; +// ... +// } +{ +public: + ACE_Synchronous_Cancellation_Required() + { + ACE_OS::thr_setcanceltype(THR_CANCEL_DEFERRED, &old_type_); + } + + ~ACE_Synchronous_Cancellation_Required() + { + int dont_care; + ACE_OS::thr_setcanceltype(old_type_, &dont_care); + } +private: + int old_type_; +}; // // "stub interpreter" for static stubs. IDL compiler (or human equivalent @@ -54,142 +85,140 @@ IIOP_Object::do_call ( ... // ... any parameters ) { -#ifdef _POSIX_THREADS - ForceSynchronousCancel temp; // side effect driven -#endif // _POSIX_THREADS - - GIOP::Invocation call (this, info->opname, - info->is_roundtrip); - + ACE_Synchronous_Cancellation_Required NOT_USED; + + GIOP::Invocation call (this, info->opname, + info->is_roundtrip); + + // + // We may need to loop through here more than once if we're forwarded + // to some other object reference. + // + // NOTE: A quality-of-service policy may be useful to establish here, + // specifically one controlling how many times the call is reissued + // before failing the call on the assumption that something is broken. + // + // NOTE: something missing is a dynamic way to change the policy of + // whether to issue LocateRequest messages or not. This code uses a + // simple, fixed policy: never use LocateRequest messages. + // + for (;;) { // - // We may need to loop through here more than once if we're forwarded - // to some other object reference. + // Start the call by constructing the request message header. // - // NOTE: A quality-of-service policy may be useful to establish here, - // specifically one controlling how many times the call is reissued - // before failing the call on the assumption that something is broken. + env.clear (); + call.start (env); + if (env.exception ()) { + dexc (env, "do_call, start request message"); + return; + } + // - // NOTE: something missing is a dynamic way to change the policy of - // whether to issue LocateRequest messages or not. This code uses a - // simple, fixed policy: never use LocateRequest messages. + // Now, put all "in" and "inout" parameters into the request + // message body. // - for (;;) { - // - // Start the call by constructing the request message header. - // - env.clear (); - call.start (env); - if (env.exception ()) { - dexc (env, "do_call, start request message"); - return; - } - - // - // Now, put all "in" and "inout" parameters into the request - // message body. - // - // Some "inout" data have an extra level of indirection, specified - // by the language mapping's memory allocation policies ... the - // indirection only shows up here when it's needed later for - // allocating "out" memory, otherwise there's just one indirection. - // - unsigned i; - const paramdata *pdp; - va_list param_vector; - - va_start (param_vector, info); - for (i = 0, pdp = info->params; - i < info->param_count; - i++, pdp++) { - void *ptr = va_arg (param_vector, void *); - - if (pdp->mode == PARAM_IN) - call.put_param (pdp->tc, ptr, env); - else if (pdp->mode == PARAM_INOUT) { - if (pdp->value_size == 0) - call.put_param (pdp->tc, ptr, env); - else - call.put_param (pdp->tc, *(void **)ptr, env); - } - - if (env.exception ()) { - dexc (env, "do_call, put request parameter"); - return; - } - } - va_end (param_vector); + // Some "inout" data have an extra level of indirection, specified + // by the language mapping's memory allocation policies ... the + // indirection only shows up here when it's needed later for + // allocating "out" memory, otherwise there's just one indirection. + // + unsigned i; + const paramdata *pdp; + va_list param_vector; + + va_start (param_vector, info); + for (i = 0, pdp = info->params; + i < info->param_count; + i++, pdp++) { + void *ptr = va_arg (param_vector, void *); + + if (pdp->mode == PARAM_IN) + call.put_param (pdp->tc, ptr, env); + else if (pdp->mode == PARAM_INOUT) { + if (pdp->value_size == 0) + call.put_param (pdp->tc, ptr, env); + else + call.put_param (pdp->tc, *(void **)ptr, env); + } + + if (env.exception ()) { + dexc (env, "do_call, put request parameter"); + return; + } + } + va_end (param_vector); - // - // Make the call ... blocking for response if needed. Note that - // "oneway" calls can't return any exceptions except system ones. - // - GIOP::ReplyStatusType status; - CORBA_ExceptionList exceptions; + // + // Make the call ... blocking for response if needed. Note that + // "oneway" calls can't return any exceptions except system ones. + // + GIOP::ReplyStatusType status; + CORBA_ExceptionList exceptions; - exceptions.length = exceptions.maximum = info->except_count; - exceptions.buffer = (CORBA_TypeCode_ptr *) info->excepts; + exceptions.length = exceptions.maximum = info->except_count; + exceptions.buffer = (CORBA_TypeCode_ptr *) info->excepts; - status = call.invoke (exceptions, env); + status = call.invoke (exceptions, env); - exceptions.buffer = 0; // don't free it + exceptions.buffer = 0; // don't free it - if (env.exception ()) { - dexc (env, "do_call, invoke"); - return; - } - if (!info->is_roundtrip - || status == GIOP::SYSTEM_EXCEPTION - || status == GIOP::USER_EXCEPTION) - return; + if (env.exception ()) { + dexc (env, "do_call, invoke"); + return; + } + if (!info->is_roundtrip + || status == GIOP::SYSTEM_EXCEPTION + || status == GIOP::USER_EXCEPTION) + return; - // - // Now, get all the "return", "out", and "inout" parameters from - // the response message body. - // - if (status == GIOP::NO_EXCEPTION) { - va_start (param_vector, info); - for (i = 0, pdp = info->params; - i < info->param_count; - i++, pdp++) { - void *ptr = va_arg (param_vector, void *); - - if (pdp->mode == PARAM_RETURN - || pdp->mode == PARAM_OUT - || pdp->mode == PARAM_INOUT) { - // - // The language mapping's memory allocation policy says - // that some data is heap-allocated. This interpreter - // is told about the relevant policy by whoever built - // the operation description (e.g. the IDL compiler) so - // it doesn't have to know the policy associated with a - // particular language binding (e.g. C/C++ differ, and - // C++ even has different policies for different kinds - // of structures). - // - if (pdp->value_size == 0) { - call.get_value (pdp->tc, ptr, env); - } else { - // assert (value_size == tc->size()); - *(void **)ptr = new CORBA_Octet [pdp->value_size]; - call.get_value (pdp->tc, *(void **)ptr, env); - } - - if (env.exception ()) { - dexc (env, "do_call, get reply parameter"); - return; - } - } - } - va_end (param_vector); + // + // Now, get all the "return", "out", and "inout" parameters from + // the response message body. + // + if (status == GIOP::NO_EXCEPTION) { + va_start (param_vector, info); + for (i = 0, pdp = info->params; + i < info->param_count; + i++, pdp++) { + void *ptr = va_arg (param_vector, void *); + + if (pdp->mode == PARAM_RETURN + || pdp->mode == PARAM_OUT + || pdp->mode == PARAM_INOUT) { + // + // The language mapping's memory allocation policy says + // that some data is heap-allocated. This interpreter + // is told about the relevant policy by whoever built + // the operation description (e.g. the IDL compiler) so + // it doesn't have to know the policy associated with a + // particular language binding (e.g. C/C++ differ, and + // C++ even has different policies for different kinds + // of structures). + // + if (pdp->value_size == 0) { + call.get_value (pdp->tc, ptr, env); + } else { + // assert (value_size == tc->size()); + *(void **)ptr = new CORBA_Octet [pdp->value_size]; + call.get_value (pdp->tc, *(void **)ptr, env); + } + + if (env.exception ()) { + dexc (env, "do_call, get reply parameter"); return; + } } - - // - // ... or maybe this request got forwarded to someplace else; send - // the request there instead. - // - assert (status == GIOP::LOCATION_FORWARD); + } + va_end (param_vector); + return; } + + // + // ... or maybe this request got forwarded to someplace else; send + // the request there instead. + // + assert (status == GIOP::LOCATION_FORWARD); + } } @@ -209,138 +238,136 @@ IIOP_Object::do_dynamic_call ( CORBA_Environment &env // exception reporting ) { -#ifdef _POSIX_THREADS - ForceSynchronousCancel temp; // side effect driven -#endif // _POSIX_THREADS + ACE_Synchronous_Cancellation_Required NOT_USED; - GIOP::Invocation call (this, opname, is_roundtrip); + GIOP::Invocation call (this, opname, is_roundtrip); + // + // Loop as needed for forwarding; see above. + // + for (;;) { // - // Loop as needed for forwarding; see above. + // Start the call by constructing the request message header. // - for (;;) { - // - // Start the call by constructing the request message header. - // - env.clear (); - call.start (env); - if (env.exception ()) { - dexc (env, "do_call, start request message"); - return; - } + env.clear (); + call.start (env); + if (env.exception ()) { + dexc (env, "do_call, start request message"); + return; + } - // - // Now, put all "in" and "inout" parameters into the request - // message body. - // - unsigned i; + // + // Now, put all "in" and "inout" parameters into the request + // message body. + // + unsigned i; - for (i = 0; i < args->count (); i++) { - CORBA_NamedValue_ptr value = args->item (i); + for (i = 0; i < args->count (); i++) { + CORBA_NamedValue_ptr value = args->item (i); - if (value->flags () == CORBA_ARG_IN - || value->flags () == CORBA_ARG_INOUT) { - call.put_param (value->value ()->type (), + if (value->flags () == CORBA_ARG_IN + || value->flags () == CORBA_ARG_INOUT) { + call.put_param (value->value ()->type (), value->value ()->value (), env); - if (env.exception ()) { - dexc (env, "do_dynamic_call, put request parameter"); - return; - } - } + if (env.exception ()) { + dexc (env, "do_dynamic_call, put request parameter"); + return; } + } + } - // - // Make the call ... blocking for response if needed. Note that - // "oneway" calls can't return any exceptions except system ones. - // - GIOP::ReplyStatusType status; + // + // Make the call ... blocking for response if needed. Note that + // "oneway" calls can't return any exceptions except system ones. + // + GIOP::ReplyStatusType status; - status = call.invoke (exceptions, env); - if (env.exception ()) { - dexc (env, "do_dynamic_call, invoke"); - return; - } - if (!is_roundtrip - || status == GIOP::SYSTEM_EXCEPTION - || status == GIOP::USER_EXCEPTION) - return; + status = call.invoke (exceptions, env); + if (env.exception ()) { + dexc (env, "do_dynamic_call, invoke"); + return; + } + if (!is_roundtrip + || status == GIOP::SYSTEM_EXCEPTION + || status == GIOP::USER_EXCEPTION) + return; + + // + // Now, get all the "return", "out", and "inout" parameters from the + // response message body ... return parameter is first, the rest are + // in the order defined in the IDL spec (which is also the order that + // DII users are required to use). + // + if (status == GIOP::NO_EXCEPTION) { + if (result != 0) { // - // Now, get all the "return", "out", and "inout" parameters from the - // response message body ... return parameter is first, the rest are - // in the order defined in the IDL spec (which is also the order that - // DII users are required to use). + // If caller didn't set OUT_LIST_MEMORY flag, allocate + // memory for return value ... // - if (status == GIOP::NO_EXCEPTION) { - if (result != 0) { - - // - // If caller didn't set OUT_LIST_MEMORY flag, allocate - // memory for return value ... - // - if (!(flags & CORBA_OUT_LIST_MEMORY)) { - CORBA_TypeCode_ptr tcp; - size_t size; - - tcp = result->value ()->type (); - size = tcp->size (env); - dexc (env, "do_dynamic_call, get result size"); - - if (size != 0) { - void *ptr = new CORBA_Octet [size]; - - tcp->AddRef (); - result->value ()->replace (tcp, ptr, - CORBA_B_TRUE, env); - dexc (env, "do_dynamic_call, set result mem"); - } - } - - call.get_value (result->value ()->type (), + if (!(flags & CORBA_OUT_LIST_MEMORY)) { + CORBA_TypeCode_ptr tcp; + size_t size; + + tcp = result->value ()->type (); + size = tcp->size (env); + dexc (env, "do_dynamic_call, get result size"); + + if (size != 0) { + void *ptr = new CORBA_Octet [size]; + + tcp->AddRef (); + result->value ()->replace (tcp, ptr, + CORBA_B_TRUE, env); + dexc (env, "do_dynamic_call, set result mem"); + } + } + + call.get_value (result->value ()->type (), result->value ()->value (), env); + } + + for (i = 0; i < args->count (); i++) { + CORBA_NamedValue_ptr value = args->item (i); + + if (value->flags () == CORBA_ARG_OUT + || value->flags () == CORBA_ARG_INOUT) { + // + // If caller didn't set OUT_LIST_MEMORY flag, allocate + // memory for this parameter ... + // + if (!(flags & CORBA_OUT_LIST_MEMORY)) { + CORBA_TypeCode_ptr tcp; + size_t size; + + tcp = value->value ()->type (); + size = tcp->size (env); + dexc (env, "do_dynamic_call, get param size"); + + if (size != 0) { + void *ptr = new CORBA_Octet [size]; + + tcp->AddRef (); + value->value ()->replace (tcp, ptr, + CORBA_B_TRUE, env); + dexc (env, "do_dynamic_call, set result mem"); } + } - for (i = 0; i < args->count (); i++) { - CORBA_NamedValue_ptr value = args->item (i); - - if (value->flags () == CORBA_ARG_OUT - || value->flags () == CORBA_ARG_INOUT) { - // - // If caller didn't set OUT_LIST_MEMORY flag, allocate - // memory for this parameter ... - // - if (!(flags & CORBA_OUT_LIST_MEMORY)) { - CORBA_TypeCode_ptr tcp; - size_t size; - - tcp = value->value ()->type (); - size = tcp->size (env); - dexc (env, "do_dynamic_call, get param size"); - - if (size != 0) { - void *ptr = new CORBA_Octet [size]; - - tcp->AddRef (); - value->value ()->replace (tcp, ptr, - CORBA_B_TRUE, env); - dexc (env, "do_dynamic_call, set result mem"); - } - } - - call.get_value (value->value ()->type (), - value->value ()->value (), env); - if (env.exception ()) { - dexc (env, "do_dynamic_call, get response parameter"); - return; - } - } - } + call.get_value (value->value ()->type (), + value->value ()->value (), env); + if (env.exception ()) { + dexc (env, "do_dynamic_call, get response parameter"); return; + } } - - // - // ... or maybe this request got forwarded to someplace else. - // - assert (status == GIOP::LOCATION_FORWARD); + } + return; } + + // + // ... or maybe this request got forwarded to someplace else. + // + assert (status == GIOP::LOCATION_FORWARD); + } } diff --git a/TAO/IIOP/lib/nvlist.cpp b/TAO/IIOP/lib/nvlist.cpp index afe797124a5..4107565c9d7 100644 --- a/TAO/IIOP/lib/nvlist.cpp +++ b/TAO/IIOP/lib/nvlist.cpp @@ -13,16 +13,6 @@ #include <initguid.h> #include "debug.hh" -#include "thread.hh" - - -#ifdef _POSIX_THREADS -// -// If POSIX threads are available, set up lock covering refcounts. -// -static pthread_mutex_t nvlist_lock = PTHREAD_MUTEX_INITIALIZER; -#endif // _POSIX_THREADS - // @@ -38,28 +28,24 @@ ULONG __stdcall CORBA_NamedValue::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&nvlist_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - return _refcount++; + return _refcount++; } ULONG __stdcall CORBA_NamedValue::Release () { -#ifdef _POSIX_THREADS - Critical region (&nvlist_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - assert (this != 0); + assert (this != 0); - if (--_refcount != 0) - return _refcount; + if (--_refcount != 0) + return _refcount; - delete this; - return 0; + delete this; + return 0; } HRESULT @@ -117,28 +103,24 @@ ULONG __stdcall CORBA_NVList::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&nvlist_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - return _refcount++; + return _refcount++; } ULONG __stdcall CORBA_NVList::Release () { -#ifdef _POSIX_THREADS - Critical region (&nvlist_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - assert (this != 0); + assert (this != 0); - if (--_refcount != 0) - return _refcount; + if (--_refcount != 0) + return _refcount; - delete this; - return 0; + delete this; + return 0; } HRESULT diff --git a/TAO/IIOP/lib/nvlist.hh b/TAO/IIOP/lib/nvlist.hh index e7b8b8e20dd..8c62ab9e9ac 100644 --- a/TAO/IIOP/lib/nvlist.hh +++ b/TAO/IIOP/lib/nvlist.hh @@ -10,6 +10,10 @@ // and the value is packaged as an Any. The flags indicate parameter // mode, and some ownership rules for "top level" memory. // + +#if !defined(ACE_ROA_NVLIST_H) +# define ACE_ROA_NVLIST_H + class _EXPCLASS CORBA_NamedValue; void CORBA_release (CORBA_NamedValue_ptr x); @@ -26,34 +30,35 @@ enum { class _EXPCLASS CORBA_NamedValue { - public: - const CORBA_String _FAR name () { return (const CORBA_String) _name; } - CORBA_Any_ptr _FAR value () { return &_any; } - CORBA_Flags flags () const { return _flags; } - - ~CORBA_NamedValue (); - - // - // Stuff required for COM IUnknown support - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); - HRESULT __stdcall QueryInterface ( - REFIID riid, - void **ppv - ); - - private: - unsigned _refcount; - - CORBA_Any _any; - CORBA_Flags _flags; - const CORBA_Char *_FAR _name; - - CORBA_NamedValue () : _flags (0), _name (0) { } - - friend class CORBA_NVList; - friend class CORBA_Request; +public: + const CORBA_String _FAR name () { return (const CORBA_String) _name; } + CORBA_Any_ptr _FAR value () { return &_any; } + CORBA_Flags flags () const { return _flags; } + + ~CORBA_NamedValue (); + + // + // Stuff required for COM IUnknown support + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); + HRESULT __stdcall QueryInterface ( + REFIID riid, + void **ppv + ); + +private: + unsigned _refcount; + ACE_Thread_Mutex lock_; + + CORBA_Any _any; + CORBA_Flags _flags; + const CORBA_Char *_FAR _name; + + CORBA_NamedValue () : _flags (0), _name (0) { } + + friend class CORBA_NVList; + friend class CORBA_Request; }; @@ -77,43 +82,46 @@ extern "C" const IID IID_CORBA_NVList; class _EXPCLASS CORBA_NVList { - public: - CORBA_ULong count () const - { return _len; } - - CORBA_NamedValue_ptr add_value ( - const CORBA_Char *_FAR , - const CORBA_Any _FAR &, - CORBA_Flags, - CORBA_Environment _FAR & - ); - - CORBA_NamedValue_ptr item (CORBA_Long n) const - { return &_values [(unsigned) n]; } - - ~CORBA_NVList (); - - // - // Stuff required for COM IUnknown support - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); - HRESULT __stdcall QueryInterface ( - REFIID riid, - void **ppv - ); - - private: - CORBA_NamedValue *_FAR _values; - unsigned _max; - unsigned _len; - unsigned _refcount; - - CORBA_NVList () - : _values (0), _max (0), - _len (0), _refcount (1) - { } - - friend class CORBA_ORB; - friend class CORBA_Request; +public: + CORBA_ULong count () const + { return _len; } + + CORBA_NamedValue_ptr add_value ( + const CORBA_Char *_FAR , + const CORBA_Any _FAR &, + CORBA_Flags, + CORBA_Environment _FAR & + ); + + CORBA_NamedValue_ptr item (CORBA_Long n) const + { return &_values [(unsigned) n]; } + + ~CORBA_NVList (); + + // + // Stuff required for COM IUnknown support + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); + HRESULT __stdcall QueryInterface ( + REFIID riid, + void **ppv + ); + +private: + CORBA_NamedValue *_FAR _values; + unsigned _max; + unsigned _len; + ACE_Thread_Mutex lock_; + unsigned _refcount; + + CORBA_NVList () + : _values (0), _max (0), + _len (0), _refcount (1) + { } + + friend class CORBA_ORB; + friend class CORBA_Request; }; + +#endif diff --git a/TAO/IIOP/lib/orbobj.cpp b/TAO/IIOP/lib/orbobj.cpp index f091b4db1b0..bb8899f9135 100644 --- a/TAO/IIOP/lib/orbobj.cpp +++ b/TAO/IIOP/lib/orbobj.cpp @@ -18,7 +18,6 @@ #include <stub.hh> #include "debug.hh" -#include "thread.hh" #include "iioporb.hh" // XXX @@ -27,10 +26,6 @@ extern void __TC_init_table (); extern void __TC_init_standard_exceptions (CORBA_Environment &env); -#ifdef _POSIX_THREADS -static pthread_mutex_t refcnt_lock = PTHREAD_MUTEX_INITIALIZER; -#endif - #if defined (SIG_IGN_BROKEN) # undef SIG_IGN # define SIG_IGN ((RETSIGTYPE (*)(int))1) @@ -105,32 +100,26 @@ ULONG __stdcall CORBA_ORB::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&refcnt_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - return _refcount++; + return _refcount++; } ULONG __stdcall CORBA_ORB::Release () { -#ifdef _POSIX_THREADS - Critical region (&refcnt_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - assert (this != 0); + assert (this != 0); - if (--_refcount != 0) - return _refcount; + if (--_refcount != 0) + return _refcount; -#ifdef _POSIX_THREADS - region.leave (); -#endif + guard.release(); - delete this; - return 0; + delete this; + return 0; } @@ -151,142 +140,142 @@ CORBA_ORB_init ( CORBA_Environment &env ) { -#ifdef _POSIX_THREADS - static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; - - Critical region (&lock); -#endif // _POSIX_THREADS - - env.clear (); - - // - // Initialising is done only once. - // - // XXX Applications that can't tell if they've initialized (e.g. - // some library modules) must check for a particular error and ignore - // it if they get it. We need a minor code to indicate this case. - // In general, one-time initialization is suboptimal. - // - // XXX We also need to enable initialising more than one ORB!! - // - if (the_orb) { - env.exception (new CORBA_INITIALIZE (COMPLETED_NO)); - return 0; + static ACE_Thread_Mutex lock; + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock, 0); + + env.clear (); + + // + // Initialising is done only once. + // + // XXX Applications that can't tell if they've initialized (e.g. + // some library modules) must check for a particular error and ignore + // it if they get it. We need a minor code to indicate this case. + // In general, one-time initialization is suboptimal. + // + // XXX We also need to enable initialising more than one ORB!! + // + if (the_orb) + { + env.exception (new CORBA_INITIALIZE (COMPLETED_NO)); + return 0; + } + + // + // Verify some of the basic implementation requirements. This test + // gets optimized away by a decent compiler (or else the rest of the + // routine does). + // + // NOTE: we still "just" assume that native floating point is IEEE. + // + + if (sizeof (CORBA_Short) != 2 + || sizeof (CORBA_Long) != 4 + || sizeof (CORBA_LongLong) != 8 + || sizeof (CORBA_Float) != 4 + || sizeof (CORBA_Double) != 8 + || sizeof (CORBA_LongDouble) != 16 + || sizeof (CORBA_WChar) < 2 + || sizeof (void *) != SIZEOF_VOID_P + ) + { + env.exception (new CORBA_INITIALIZE (COMPLETED_NO)); + return 0; } - // - // Verify some of the basic implementation requirements. This test - // gets optimized away by a decent compiler (or else the rest of the - // routine does). - // - // NOTE: we still "just" assume that native floating point is IEEE. - // - - if (sizeof (CORBA_Short) != 2 - || sizeof (CORBA_Long) != 4 - || sizeof (CORBA_LongLong) != 8 - || sizeof (CORBA_Float) != 4 - || sizeof (CORBA_Double) != 8 - || sizeof (CORBA_LongDouble) != 16 - || sizeof (CORBA_WChar) < 2 - || sizeof (void *) != SIZEOF_VOID_P - ) - { - env.exception (new CORBA_INITIALIZE (COMPLETED_NO)); - return 0; - } - - // - // ignoring argc, argv for now -- no arguments we care about - // - // XXX should remove any of the "-ORB*" arguments that we know - // about ... and report errors for the rest. - // + // + // ignoring argc, argv for now -- no arguments we care about + // + // XXX should remove any of the "-ORB*" arguments that we know + // about ... and report errors for the rest. + // #ifdef DEBUG - // - // Make it a little easier to debug programs using this code. - // - { - char *value = ACE_OS::getenv ("ORB_DEBUG"); - - if (value != 0) { - debug_level = ACE_OS::atoi (value); - if (debug_level <= 0) - debug_level = 1; - dmsg1 ("debug_level == %d", debug_level); - } + // + // Make it a little easier to debug programs using this code. + // + { + char *value = ACE_OS::getenv ("ORB_DEBUG"); + + if (value != 0) { + debug_level = ACE_OS::atoi (value); + if (debug_level <= 0) + debug_level = 1; + dmsg1 ("debug_level == %d", debug_level); } + } #endif // DEBUG - // - // On Win32, we should be collecting information from the Registry - // such as what ORBs are configured, specific configuration details - // like whether they generate IOR or URL style stringified objrefs - // and which addresses they listen to (e.g. allowing multihomed - // hosts to implement firewalls), user-meaningful orb names (they - // will normally indicate domains), and more. - // - // On UNIX, we should collect that from some private config file. - // - // Instead, this just treats the "internet" ORB name specially and - // makes it always use URL-style stringified objrefs, where the - // hostname and TCP port number are explicit (and the whole objref - // is readable by mortals). - // - CORBA_Boolean use_ior; - - if (orb_name != 0 && ACE_OS::strcmp (orb_name, "internet") == 0) - use_ior = CORBA_B_FALSE; - else - use_ior = CORBA_B_TRUE; + // + // On Win32, we should be collecting information from the Registry + // such as what ORBs are configured, specific configuration details + // like whether they generate IOR or URL style stringified objrefs + // and which addresses they listen to (e.g. allowing multihomed + // hosts to implement firewalls), user-meaningful orb names (they + // will normally indicate domains), and more. + // + // On UNIX, we should collect that from some private config file. + // + // Instead, this just treats the "internet" ORB name specially and + // makes it always use URL-style stringified objrefs, where the + // hostname and TCP port number are explicit (and the whole objref + // is readable by mortals). + // + CORBA_Boolean use_ior; + + if (orb_name != 0 && ACE_OS::strcmp (orb_name, "internet") == 0) + use_ior = CORBA_B_FALSE; + else + use_ior = CORBA_B_TRUE; #ifdef SIGPIPE - // - // Impractical to have each call to the ORB protect against the - // implementation artifact of potential writes to dead connections, - // as it'd be way expensive. Do it here; who cares about SIGPIPE - // in these kinds of applications, anyway? - // - (void) ACE_OS::signal (SIGPIPE, SIG_IGN); + // + // Impractical to have each call to the ORB protect against the + // implementation artifact of potential writes to dead connections, + // as it'd be way expensive. Do it here; who cares about SIGPIPE + // in these kinds of applications, anyway? + // + (void) ACE_OS::signal (SIGPIPE, SIG_IGN); #endif // SIGPIPE #if defined(ACE_INVALID_HANDLE) - ACE_OS::socket_init(ACE_WSOCK_VERSION); + ACE_OS::socket_init(ACE_WSOCK_VERSION); #elif defined (_WINSOCKAPI_) - // - // winsock needs explicit initialization, and applications must manage - // versioning problems directly. - // - WSADATA wsadata; - - if (WSAStartup (MAKEWORD (1, 1), &wsadata) != 0) { - dsockerr ("WSAStartup"); - env.exception (new CORBA_INITIALIZE (COMPLETED_NO)); - return 0; + // + // winsock needs explicit initialization, and applications must manage + // versioning problems directly. + // + WSADATA wsadata; + + if (WSAStartup (MAKEWORD (1, 1), &wsadata) != 0) + { + dsockerr ("WSAStartup"); + env.exception (new CORBA_INITIALIZE (COMPLETED_NO)); + return 0; } - if (LOBYTE (wsadata.wVersion) != 1 || HIBYTE (wsadata.wVersion != 1)) { - dmsg2 ("bad winsock version %d.%d", - HIBYTE (wsadata.wVersion), LOBYTE (wsadata.wVersion)); - env.exception (new CORBA_INITIALIZE (COMPLETED_NO)); - return 0; + if (LOBYTE (wsadata.wVersion) != 1 || HIBYTE (wsadata.wVersion != 1)) + { + dmsg2 ("bad winsock version %d.%d", + HIBYTE (wsadata.wVersion), LOBYTE (wsadata.wVersion)); + env.exception (new CORBA_INITIALIZE (COMPLETED_NO)); + return 0; } #endif // _WINSOCKAPI_ - // - // Call various internal initialization routines. - // - __TC_init_table (); - __TC_init_standard_exceptions (env); - if (env.exception () != 0) - return 0; + // + // Call various internal initialization routines. + // + __TC_init_table (); + __TC_init_standard_exceptions (env); + if (env.exception () != 0) + return 0; - // - // Inititalize the "ORB" pseudo-object now. - // - the_orb = new IIOP_ORB (use_ior); + // + // Inititalize the "ORB" pseudo-object now. + // + the_orb = new IIOP_ORB (use_ior); - return the_orb; + return the_orb; } void diff --git a/TAO/IIOP/lib/orbobj.hh b/TAO/IIOP/lib/orbobj.hh index 960fcac5b8e..c9cb138cc82 100644 --- a/TAO/IIOP/lib/orbobj.hh +++ b/TAO/IIOP/lib/orbobj.hh @@ -5,6 +5,10 @@ // create object references from strings. It's also used to // create strings from object references. // + +#if !defined(ACE_ROA_ORBOBJ_H) +# define ACE_ROA_ORBOBJ_H + typedef class CORBA_ORB *CORBA_ORB_ptr; void CORBA_release (CORBA_ORB_ptr orb); CORBA_Boolean CORBA_is_nil (CORBA_ORB_ptr orb); @@ -27,46 +31,49 @@ CORBA_ORB_init ( // class _EXPCLASS CORBA_ORB : public IUnknown { - public: - static CORBA_ORB_ptr _duplicate (CORBA_ORB_ptr orb); - static CORBA_ORB_ptr _nil (); +public: + static CORBA_ORB_ptr _duplicate (CORBA_ORB_ptr orb); + static CORBA_ORB_ptr _nil (); - virtual CORBA_Object_ptr string_to_object ( - CORBA_String str, - CORBA_Environment &env - ) = 0; - virtual CORBA_String object_to_string ( - CORBA_Object_ptr obj, - CORBA_Environment &env - ) = 0; + virtual CORBA_Object_ptr string_to_object ( + CORBA_String str, + CORBA_Environment &env + ) = 0; + virtual CORBA_String object_to_string ( + CORBA_Object_ptr obj, + CORBA_Environment &env + ) = 0; - // similar for TypeCodes and Anys ... to/from octet sequences + // similar for TypeCodes and Anys ... to/from octet sequences - void create_list ( - CORBA_Long count, - CORBA_NVList_ptr &retval - ); + void create_list ( + CORBA_Long count, + CORBA_NVList_ptr &retval + ); - // - // Stuff required for COM IUnknown support ... this class is intended - // to be inherited by others, which will provide some more of the - // CORBA/COM support. Implementations of this "CORBA_ORB" class must - // know how to create stringify/destringify their objrefs, as well as - // how to marshal and unmarshal them ... as well as provide their - // own QueryInterface. - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); + // + // Stuff required for COM IUnknown support ... this class is intended + // to be inherited by others, which will provide some more of the + // CORBA/COM support. Implementations of this "CORBA_ORB" class must + // know how to create stringify/destringify their objrefs, as well as + // how to marshal and unmarshal them ... as well as provide their + // own QueryInterface. + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); - protected: - CORBA_ORB (); - virtual ~CORBA_ORB (); +protected: + CORBA_ORB (); + virtual ~CORBA_ORB (); - private: - unsigned _refcount; +private: + ACE_Thread_Mutex lock_; + unsigned _refcount; - // these are not provided - CORBA_ORB (const CORBA_ORB &); - CORBA_ORB &operator = (const CORBA_ORB &); + // these are not provided + CORBA_ORB (const CORBA_ORB &); + CORBA_ORB &operator = (const CORBA_ORB &); }; +#endif + diff --git a/TAO/IIOP/lib/params.i b/TAO/IIOP/lib/params.i index b498fcc58ca..3d6f092b6f4 100644 --- a/TAO/IIOP/lib/params.i +++ b/TAO/IIOP/lib/params.i @@ -71,12 +71,6 @@ ROA_Parameters::thread_flags(u_int f) } ACE_INLINE -ROA_Factory::ROA_Factory() - : concurrency_strategy_(0) -{ -} - -ACE_INLINE ROA_Factory::CREATION_STRATEGY* ROA_Factory::creation_strategy() { diff --git a/TAO/IIOP/lib/principa.cpp b/TAO/IIOP/lib/principa.cpp index 213baa96b6c..f391d08281f 100644 --- a/TAO/IIOP/lib/principa.cpp +++ b/TAO/IIOP/lib/principa.cpp @@ -12,15 +12,6 @@ #include <initguid.h> -#include "thread.hh" - - -#ifdef _POSIX_THREADS -// -// If POSIX threads are available, set up lock covering refcounts. -// -static pthread_mutex_t principal_lock = PTHREAD_MUTEX_INITIALIZER; -#endif // _POSIX_THREADS void @@ -61,30 +52,24 @@ ULONG __stdcall CORBA_Principal::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&principal_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, principal_lock_, 0); - return ++_refcount; + return ++_refcount; } ULONG __stdcall CORBA_Principal::Release () { -#ifdef _POSIX_THREADS - Critical region (&principal_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, principal_lock_, 0); - if (--_refcount != 0) - return _refcount; + if (--_refcount != 0) + return _refcount; -#ifdef _POSIX_THREADS - region.leave (); -#endif + guard.release(); - delete this; - return 0; + delete this; + return 0; } HRESULT diff --git a/TAO/IIOP/lib/principa.hh b/TAO/IIOP/lib/principa.hh index 3cb5b0a8880..55909e5ae4b 100644 --- a/TAO/IIOP/lib/principa.hh +++ b/TAO/IIOP/lib/principa.hh @@ -5,6 +5,11 @@ // administration framework. Identities are used to control acccess // (authorization) as well as in audit trails (accountability). // +#if !defined(ACE_ROA_PRINCIPAL_H) +# define ACE_ROA_PRINCIPAL_H + +# include <ace/Synch.h> + typedef class CORBA_Principal *CORBA_Principal_ptr; void CORBA_release (CORBA_Principal_ptr principal); @@ -14,39 +19,41 @@ extern const IID IID_CORBA_Principal; class _EXPCLASS CORBA_Principal : public IUnknown { - public: - // - // To applications, the identifier is an opaque ID. - // - CORBA_SEQUENCE <CORBA_Octet> id; - - // XXX add "==", "<", ">" operators - - // - // Stuff required for COM IUnknown support - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); - HRESULT __stdcall QueryInterface ( - REFIID riid, - void **ppv - ); - - CORBA_Principal (); - private: - unsigned _refcount; - - virtual ~CORBA_Principal (); - - // these are not provided - CORBA_Principal &operator = (const CORBA_Principal_ptr &); - CORBA_Principal (const CORBA_Principal_ptr &); +public: + // + // To applications, the identifier is an opaque ID. + // + CORBA_SEQUENCE <CORBA_Octet> id; + + // XXX add "==", "<", ">" operators + + // + // Stuff required for COM IUnknown support + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); + HRESULT __stdcall QueryInterface ( + REFIID riid, + void **ppv + ); + + CORBA_Principal (); +private: + ACE_Thread_Mutex principal_lock_; + unsigned _refcount; + + virtual ~CORBA_Principal (); + + // these are not provided + CORBA_Principal &operator = (const CORBA_Principal_ptr &); + CORBA_Principal (const CORBA_Principal_ptr &); #if defined (__GNUG__) - // - // G++ (even 2.6.3) stupidly thinks instances can't be - // created. This de-warns. - // - friend class everyone_needs_a_friend; + // + // G++ (even 2.6.3) stupidly thinks instances can't be + // created. This de-warns. + // + friend class everyone_needs_a_friend; #endif }; +#endif diff --git a/TAO/IIOP/lib/request.cpp b/TAO/IIOP/lib/request.cpp index 0ea1aa2a008..26011a047c2 100644 --- a/TAO/IIOP/lib/request.cpp +++ b/TAO/IIOP/lib/request.cpp @@ -18,37 +18,30 @@ DEFINE_GUID (IID_CORBA_Request, 0x77420085, 0xf276, 0x11ce, 0x95, 0x98, 0x0, 0x0, 0xc0, 0x7c, 0xa8, 0x98); -#ifdef _POSIX_THREADS -static pthread_mutex_t refcnt_lock = PTHREAD_MUTEX_INITIALIZER; -#endif // _POSIX_THREADS - - ULONG __stdcall CORBA_Request::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&refcnt_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - return _refcount++; + return _refcount++; } ULONG __stdcall CORBA_Request::Release () { -#ifdef _POSIX_THREADS - Critical region (&refcnt_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - assert (this != 0); + assert (this != 0); - if (--_refcount != 0) - return _refcount; + if (--_refcount != 0) + return _refcount; + + guard.release(); - delete this; - return 0; + delete this; + return 0; } HRESULT diff --git a/TAO/IIOP/lib/request.hh b/TAO/IIOP/lib/request.hh index 74e6e31afba..40991dcb800 100644 --- a/TAO/IIOP/lib/request.hh +++ b/TAO/IIOP/lib/request.hh @@ -4,6 +4,8 @@ // Header file for Win32 C/C++/COM interface to CORBA's Dynamic // Invocation Interface "Request" type. // +#if !defined(ACE_ROA_REQUEST_H) +# define ACE_ROA_REQUEST_H void CORBA_release (CORBA_Request_ptr req); CORBA_Boolean CORBA_is_nil (CORBA_Request_ptr req); @@ -15,55 +17,57 @@ extern const IID IID_CORBA_Request; class _EXPCLASS CORBA_Request : public IUnknown { - public: - // - // XXX these should not be inlined - // - CORBA_Object_ptr target () const { return _target; } - const CORBA_Char *operation () const { return _opname; } - CORBA_NVList_ptr arguments () { return _args; } - CORBA_NamedValue_ptr result () { return _result; } - CORBA_ExceptionList_ptr exceptions () { return &_exceptions; } - CORBA_Environment *env () { return &_env; } +public: + // + // XXX these should not be inlined + // + CORBA_Object_ptr target () const { return _target; } + const CORBA_Char *operation () const { return _opname; } + CORBA_NVList_ptr arguments () { return _args; } + CORBA_NamedValue_ptr result () { return _result; } + CORBA_ExceptionList_ptr exceptions () { return &_exceptions; } + CORBA_Environment *env () { return &_env; } - void invoke (); - void send_oneway (); + void invoke (); + void send_oneway (); - // - // Stuff required for COM IUnknown support - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); - HRESULT __stdcall QueryInterface ( - REFIID riid, - void **ppv - ); + // + // Stuff required for COM IUnknown support + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); + HRESULT __stdcall QueryInterface ( + REFIID riid, + void **ppv + ); - private: - friend class CORBA_Object; +private: + friend class CORBA_Object; - CORBA_Request ( - CORBA_Object_ptr obj, - const CORBA_Char *op, - CORBA_NVList_ptr args, - CORBA_NamedValue_ptr result, - CORBA_Flags flags - ); + CORBA_Request ( + CORBA_Object_ptr obj, + const CORBA_Char *op, + CORBA_NVList_ptr args, + CORBA_NamedValue_ptr result, + CORBA_Flags flags + ); - CORBA_Request ( - CORBA_Object_ptr obj, - const CORBA_Char *op - ); + CORBA_Request ( + CORBA_Object_ptr obj, + const CORBA_Char *op + ); - virtual ~CORBA_Request (); + virtual ~CORBA_Request (); - CORBA_Object_ptr _target; - const CORBA_Char *_opname; - CORBA_NVList_ptr _args; - CORBA_NamedValue_ptr _result; - CORBA_Flags _flags; - CORBA_Environment _env; - CORBA_ExceptionList _exceptions; + CORBA_Object_ptr _target; + const CORBA_Char *_opname; + CORBA_NVList_ptr _args; + CORBA_NamedValue_ptr _result; + CORBA_Flags _flags; + CORBA_Environment _env; + CORBA_ExceptionList _exceptions; - unsigned _refcount; + ACE_Thread_Mutex lock_; + unsigned _refcount; }; +#endif diff --git a/TAO/IIOP/lib/roa.cpp b/TAO/IIOP/lib/roa.cpp index f3cd4cd4f39..73e69c8f4f2 100644 --- a/TAO/IIOP/lib/roa.cpp +++ b/TAO/IIOP/lib/roa.cpp @@ -48,30 +48,6 @@ ROA::init (CORBA_ORB_ptr parent, (void) ACE_Thread::keycreate(&req_key_); #endif - // Don't know if this is right for what was originally being done. Looks like - // what was set in thread_attr were flags given to pthread_create(). However, - // thread creation (when necessary) is now performed by the Svc_Handler::create(). - //(void) p->thread_flags(ROA_DEFAULT_THREADFLAGS); -#if 0 - - // - // Initialize POSIX thread stuff: TSD key for request data, and - // attributes for threads that can be dynamically created. - // - // XXX this stuff should be guarded by "pthread_once", it's not - // at all OA-specific. - // - (void) pthread_key_create (&request_key, 0); - - (void) pthread_attr_init (&thread_attr); - (void) pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED); - -#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING - (void) pthread_attr_setscope (&thread_attr, PTHREAD_SCOPE_PROCESS); -#endif // _POSIX_THREAD_PRIORITY_SCHEDULING - -#endif // _POSIX_THREADS - ROA_ptr rp; ACE_NEW_RETURN (rp, ROA(parent, rendezvous, env), 0); p->oa(rp); @@ -289,6 +265,7 @@ ROA::register_dir (BOA::dsi_handler handler, void* ctx, CORBA_Environment& env) env.clear (); } +// OBSOLETE!!! But for now I'm afraid to take it out. void ROA::get_request(CORBA_Boolean use_threads, struct timeval *tvp, @@ -312,9 +289,7 @@ ROA::get_request(CORBA_Boolean use_threads, get_request (skeleton, 0, use_threads, context, tvp, env); } -// NOTE! The only reason this method exists is because the method -// above calls it. Neither method is defined by the standard, so it's -// possible that they'll BOTH go away. +// OBSOLETE!!! But stays in b/c the one above calls it. void ROA::get_request ( BOA::dsi_handler handler, diff --git a/TAO/IIOP/lib/svrrqst.cpp b/TAO/IIOP/lib/svrrqst.cpp index c08bced9dc7..770cc940fdc 100644 --- a/TAO/IIOP/lib/svrrqst.cpp +++ b/TAO/IIOP/lib/svrrqst.cpp @@ -25,20 +25,15 @@ DEFINE_GUID(IID_CORBA_ServerRequest, -#ifdef _POSIX_THREADS -static pthread_mutex_t svrqst_lock = PTHREAD_MUTEX_INITIALIZER; -#endif // _POSIX_THREADS - - IIOP_ServerRequest::~IIOP_ServerRequest () { - assert (_refcount == 0); - if (_params) - CORBA_release (_params); - if (_retval) - delete _retval; - if (_exception) - delete _exception; + assert (_refcount == 0); + if (_params) + CORBA_release (_params); + if (_retval) + delete _retval; + if (_exception) + delete _exception; } @@ -46,30 +41,28 @@ ULONG __stdcall IIOP_ServerRequest::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&svrqst_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - assert (_refcount > 0); - return _refcount++; + assert (_refcount > 0); + return _refcount++; } ULONG __stdcall IIOP_ServerRequest::Release () { -#ifdef _POSIX_THREADS - Critical region (&svrqst_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - assert (this != 0); - assert (_refcount > 0); + assert (this != 0); + assert (_refcount > 0); - if (--_refcount != 0) - return _refcount; + if (--_refcount != 0) + return _refcount; - delete this; - return 0; + guard.release(); + + delete this; + return 0; } HRESULT diff --git a/TAO/IIOP/lib/svrrqst.hh b/TAO/IIOP/lib/svrrqst.hh index e00190c7f78..781e60c77cd 100644 --- a/TAO/IIOP/lib/svrrqst.hh +++ b/TAO/IIOP/lib/svrrqst.hh @@ -81,80 +81,81 @@ extern const IID IID_IIOP_ServerRequest; class _EXPCLASS IIOP_ServerRequest : public CORBA_ServerRequest { - public: - // - // Constructor, destructor - // - IIOP_ServerRequest ( - CDR *msg, - CORBA_ORB_ptr the_orb, - BOA_ptr the_boa - ) - : _incoming (msg), _params (0), _retval (0), - _exception (0), - _ex_type (NO_EXCEPTION), - _refcount (1), - _orb (the_orb), - _boa (the_boa) - { } - - virtual ~IIOP_ServerRequest (); - - // - // General ServerRequest operations - // - void __stdcall params ( - CORBA_NVList_ptr list, - CORBA_Environment &env - ); - - void __stdcall result ( - CORBA_Any_ptr value, - CORBA_Environment &env - ); - - void __stdcall exception ( - CORBA_ExceptionType type, - CORBA_Any_ptr value, - CORBA_Environment &env - ); - - // - // Request attributes - // - CORBA_String __stdcall op_name (); - CORBA_Principal_ptr __stdcall caller (); - CORBA_Object_ptr __stdcall target (); - CORBA_ORB_ptr __stdcall orb (); - BOA_ptr __stdcall oa (); - - // - // Stuff required for COM IUnknown support - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); - HRESULT __stdcall QueryInterface ( - REFIID riid, - void **ppv - ); +public: + // + // Constructor, destructor + // + IIOP_ServerRequest ( + CDR *msg, + CORBA_ORB_ptr the_orb, + BOA_ptr the_boa + ) + : _incoming (msg), _params (0), _retval (0), + _exception (0), + _ex_type (NO_EXCEPTION), + _refcount (1), + _orb (the_orb), + _boa (the_boa) + { } + + virtual ~IIOP_ServerRequest (); + + // + // General ServerRequest operations + // + void __stdcall params ( + CORBA_NVList_ptr list, + CORBA_Environment &env + ); + + void __stdcall result ( + CORBA_Any_ptr value, + CORBA_Environment &env + ); + + void __stdcall exception ( + CORBA_ExceptionType type, + CORBA_Any_ptr value, + CORBA_Environment &env + ); + + // + // Request attributes + // + CORBA_String __stdcall op_name (); + CORBA_Principal_ptr __stdcall caller (); + CORBA_Object_ptr __stdcall target (); + CORBA_ORB_ptr __stdcall orb (); + BOA_ptr __stdcall oa (); + + // + // Stuff required for COM IUnknown support + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); + HRESULT __stdcall QueryInterface ( + REFIID riid, + void **ppv + ); // private: - CORBA_String _opname; - CDR *_incoming; - CORBA_NVList_ptr _params; - CORBA_Any_ptr _retval; - CORBA_Any_ptr _exception; - CORBA_ExceptionType _ex_type; - - // - // Just drop the refcount, don't destroy the object; most - // of these are stack-allocated. - // - void release () { _refcount--; } - - private: - unsigned _refcount; - CORBA_ORB_ptr _orb; - BOA_ptr _boa; + CORBA_String _opname; + CDR *_incoming; + CORBA_NVList_ptr _params; + CORBA_Any_ptr _retval; + CORBA_Any_ptr _exception; + CORBA_ExceptionType _ex_type; + + // + // Just drop the refcount, don't destroy the object; most + // of these are stack-allocated. + // + void release () { _refcount--; } + +private: + unsigned _refcount; + ACE_Thread_Mutex lock_; + CORBA_ORB_ptr _orb; + BOA_ptr _boa; }; #endif diff --git a/TAO/IIOP/lib/typecode.cpp b/TAO/IIOP/lib/typecode.cpp index 537c1949bd2..60feb7a6ca9 100644 --- a/TAO/IIOP/lib/typecode.cpp +++ b/TAO/IIOP/lib/typecode.cpp @@ -33,14 +33,6 @@ #include <initguid.h> -#ifdef _POSIX_THREADS -// -// If POSIX threads are available, set up lock covering refcounts. -// -static pthread_mutex_t refcnt_lock = PTHREAD_MUTEX_INITIALIZER; -#endif // _POSIX_THREADS - - void CORBA_release (CORBA_TypeCode_ptr tc) { @@ -145,28 +137,24 @@ ULONG __stdcall CORBA_TypeCode::AddRef () { -#ifdef _POSIX_THREADS - Critical region (&refcnt_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - return _refcount++; + return _refcount++; } ULONG __stdcall CORBA_TypeCode::Release () { -#ifdef _POSIX_THREADS - Critical region (&refcnt_lock); -#endif + ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0); - assert (this != 0); + assert (this != 0); - if (--_refcount != 0) - return _refcount; - if (_orb_owns) - delete this; - return 0; + if (--_refcount != 0) + return _refcount; + if (_orb_owns) + delete this; + return 0; } HRESULT diff --git a/TAO/IIOP/lib/typecode.hh b/TAO/IIOP/lib/typecode.hh index 17c4bb72cc5..bab4bb131d3 100644 --- a/TAO/IIOP/lib/typecode.hh +++ b/TAO/IIOP/lib/typecode.hh @@ -9,6 +9,9 @@ // tables. The values are also part of the Common Data Representation, // and hence are part of IIOP and other ORB protocols. // +#if !defined(ACE_ROA_TYPECODE_H) +# define ACE_ROA_TYPECODE_H + enum CORBA_TCKind { tk_null = 0, tk_void = 1, @@ -87,182 +90,183 @@ extern const IID IID_CORBA_TypeCode; class _EXPCLASS CORBA_TypeCode : public IUnknown { - public: - // - // For all TypeCode kinds - // - CORBA_TCKind kind (CORBA_Environment &) const; - - // - // Deprecated, CORBA 1.2, not fully usable - // - CORBA_ULong param_count (CORBA_Environment &) const; - - // - // For tk_{objref,struct,union,enum,alias,except} - // - CORBA_String id (CORBA_Environment &) const; - - // - // Other CORBA 2.0 IFR updates -- not yet implemented/needed - // - // String name () raises (BadKind); - // ULong member_count () raises (BadKind); - // String member_name (...) raises (BadKind, Bounds); - // TypeCode_ptr member_type (...) raises (BadKind, Bounds); - - CORBA_Any_ptr member_label (CORBA_ULong n, CORBA_Environment&) const; - - // TypeCode_ptr discriminator_type () raises (BadKind); - // Long default_index () raises (BadKind); - - // Long length () raises (BadKind); - // TypeCode_ptr content_type () raises (BadKind); - - // - // Internal utilities, pending CORBA 2.0 IFR APIs; just enough - // to make array and sequence typecode interpretation cheap - // - CORBA_ULong ulong_param (CORBA_ULong n, CORBA_Environment &) const; - CORBA_TypeCode_ptr typecode_param (CORBA_ULong n, - CORBA_Environment &) const; - - // - // Creation/refcounting ... these aren't really public APIs, - // but an IDL compiler will need to be able to create TypeCodes - // as part of creating stubs. - // - // - // This constructor is used only for built-in - // TypeCode constants, with no parameters. - // - CORBA_TypeCode ( - CORBA_TCKind kind // EMPTY paramlists! - ); - - // - // This constructor is used both for typecode - // constants and for heap-allocated TypeCodes. - // The two are distinguished by the orb_owns_tc - // flag passed in by the creator. - // - // For simple param lists with a single - // numeric parameter, only 'length' matters. - // - // For complex param lists, or simple param - // lists for which the parameter is a string - // or typecode, length _and_ buffer matter. - // - CORBA_TypeCode ( - CORBA_TCKind kind, - CORBA_ULong length, - CORBA_Octet *buffer, - CORBA_Boolean orb_owns_tc - ); - void *operator new (size_t, void *p) - { return p; } - void *operator new (size_t s) - { return ::operator new(s); } - - virtual ~CORBA_TypeCode (); - - // - // "orb owns" is always set, except for TypeCode constants. - // - - // - // This routine calls visit() on each component of one (or two) - // structurally equivalent data values. "Components" are either - // primitive (long, string, ...) or constructed (struct, ...) - // data elements. - // - // It will NOT descend into those nodes if they're constructed; - // it's the job of the visit() routine to do that as needed. - // - // "Context" can be used to hold state used by the visit() routine. - // To terminate traversal "early", visit() returns TRAVERSE_STOP. - // - // The "value1" and "value2" parameters are pointers to data - // values of the structure described by the TypeCode. Using - // the normal size, alignment, and padding rules used by the - // compilers on a given platform, the visit() routine is called - // with pointers to subsidiary elements. - // - // As all this routine does is appropriate pointer adjustments, - // it any value at all can be passed in as "value1" or "value2". - // You could ignore one value and examine a data structure; copy - // from one to the other; compare one to the other; and more. - // - // Normal usage is to have application code call its visit() - // routine directly, and have that decide whether to use the - // typecode interpereter's knowledge of data structure layout - // through mutual recursion. - // - enum traverse_status { TRAVERSE_STOP, TRAVERSE_CONTINUE }; - - typedef traverse_status (_FAR * VisitRoutine) ( - CORBA_TypeCode_ptr tc, - const void *value1, - const void *value2, - void *context, - CORBA_Environment &env - ); - - traverse_status traverse ( - const void *value1, - const void *value2, - VisitRoutine visit, - void *context, - CORBA_Environment &env - ); +public: + // + // For all TypeCode kinds + // + CORBA_TCKind kind (CORBA_Environment &) const; + + // + // Deprecated, CORBA 1.2, not fully usable + // + CORBA_ULong param_count (CORBA_Environment &) const; + + // + // For tk_{objref,struct,union,enum,alias,except} + // + CORBA_String id (CORBA_Environment &) const; + + // + // Other CORBA 2.0 IFR updates -- not yet implemented/needed + // + // String name () raises (BadKind); + // ULong member_count () raises (BadKind); + // String member_name (...) raises (BadKind, Bounds); + // TypeCode_ptr member_type (...) raises (BadKind, Bounds); + + CORBA_Any_ptr member_label (CORBA_ULong n, CORBA_Environment&) const; + + // TypeCode_ptr discriminator_type () raises (BadKind); + // Long default_index () raises (BadKind); + + // Long length () raises (BadKind); + // TypeCode_ptr content_type () raises (BadKind); + + // + // Internal utilities, pending CORBA 2.0 IFR APIs; just enough + // to make array and sequence typecode interpretation cheap + // + CORBA_ULong ulong_param (CORBA_ULong n, CORBA_Environment &) const; + CORBA_TypeCode_ptr typecode_param (CORBA_ULong n, + CORBA_Environment &) const; + + // + // Creation/refcounting ... these aren't really public APIs, + // but an IDL compiler will need to be able to create TypeCodes + // as part of creating stubs. + // + // + // This constructor is used only for built-in + // TypeCode constants, with no parameters. + // + CORBA_TypeCode ( + CORBA_TCKind kind // EMPTY paramlists! + ); + + // + // This constructor is used both for typecode + // constants and for heap-allocated TypeCodes. + // The two are distinguished by the orb_owns_tc + // flag passed in by the creator. + // + // For simple param lists with a single + // numeric parameter, only 'length' matters. + // + // For complex param lists, or simple param + // lists for which the parameter is a string + // or typecode, length _and_ buffer matter. + // + CORBA_TypeCode ( + CORBA_TCKind kind, + CORBA_ULong length, + CORBA_Octet *buffer, + CORBA_Boolean orb_owns_tc + ); + void *operator new (size_t, void *p) + { return p; } + void *operator new (size_t s) + { return ::operator new(s); } + + virtual ~CORBA_TypeCode (); + + // + // "orb owns" is always set, except for TypeCode constants. + // + + // + // This routine calls visit() on each component of one (or two) + // structurally equivalent data values. "Components" are either + // primitive (long, string, ...) or constructed (struct, ...) + // data elements. + // + // It will NOT descend into those nodes if they're constructed; + // it's the job of the visit() routine to do that as needed. + // + // "Context" can be used to hold state used by the visit() routine. + // To terminate traversal "early", visit() returns TRAVERSE_STOP. + // + // The "value1" and "value2" parameters are pointers to data + // values of the structure described by the TypeCode. Using + // the normal size, alignment, and padding rules used by the + // compilers on a given platform, the visit() routine is called + // with pointers to subsidiary elements. + // + // As all this routine does is appropriate pointer adjustments, + // it any value at all can be passed in as "value1" or "value2". + // You could ignore one value and examine a data structure; copy + // from one to the other; compare one to the other; and more. + // + // Normal usage is to have application code call its visit() + // routine directly, and have that decide whether to use the + // typecode interpereter's knowledge of data structure layout + // through mutual recursion. + // + enum traverse_status { TRAVERSE_STOP, TRAVERSE_CONTINUE }; + + typedef traverse_status (_FAR * VisitRoutine) ( + CORBA_TypeCode_ptr tc, + const void *value1, + const void *value2, + void *context, + CORBA_Environment &env + ); + + traverse_status traverse ( + const void *value1, + const void *value2, + VisitRoutine visit, + void *context, + CORBA_Environment &env + ); - size_t size (CORBA_Environment &env); - size_t alignment (CORBA_Environment &env); - - static CORBA_TypeCode_ptr _nil (); - - // - // Stuff required for COM IUnknown support - // - ULONG __stdcall AddRef (); - ULONG __stdcall Release (); - HRESULT __stdcall QueryInterface ( - REFIID riid, - void **ppv - ); + size_t size (CORBA_Environment &env); + size_t alignment (CORBA_Environment &env); + + static CORBA_TypeCode_ptr _nil (); + + // + // Stuff required for COM IUnknown support + // + ULONG __stdcall AddRef (); + ULONG __stdcall Release (); + HRESULT __stdcall QueryInterface ( + REFIID riid, + void **ppv + ); // private: - // - // the guts of the typecode implementation class: a counted - // set of bytes, in marshaled CDR format. - // - CORBA_ULong _length; - CORBA_Octet *_buffer; - CORBA_TCKind _kind; - - // - // Indirected typecodes share "buffer" with a parent, and - // hold a reference to that parent to ensure its memory is - // not freed inappropriately. - // - CORBA_TypeCode_ptr _parent; - - private: - unsigned _refcount; - - // - // If "orb_owns" is false, the value is a constant typecode with - // both the typecode and the buffer statically allocated; the - // typecode is never freed. Otherwise the typecode and the - // buffer are freed when the refcount goes to zero. - // - CORBA_Boolean _orb_owns; - - // - // No copy constructor or assignment operator supported; - // use TypeCode_ptr values, duplicate(), release(). - // - CORBA_TypeCode (const CORBA_TypeCode &src); - CORBA_TypeCode &operator = (const CORBA_TypeCode &src); + // + // the guts of the typecode implementation class: a counted + // set of bytes, in marshaled CDR format. + // + CORBA_ULong _length; + CORBA_Octet *_buffer; + CORBA_TCKind _kind; + + // + // Indirected typecodes share "buffer" with a parent, and + // hold a reference to that parent to ensure its memory is + // not freed inappropriately. + // + CORBA_TypeCode_ptr _parent; + +private: + ACE_Thread_Mutex lock_; + unsigned _refcount; + + // + // If "orb_owns" is false, the value is a constant typecode with + // both the typecode and the buffer statically allocated; the + // typecode is never freed. Otherwise the typecode and the + // buffer are freed when the refcount goes to zero. + // + CORBA_Boolean _orb_owns; + + // + // No copy constructor or assignment operator supported; + // use TypeCode_ptr values, duplicate(), release(). + // + CORBA_TypeCode (const CORBA_TypeCode &src); + CORBA_TypeCode &operator = (const CORBA_TypeCode &src); }; // @@ -297,3 +301,4 @@ extern const CORBA_TypeCode_ptr _tc_CORBA_Object; +#endif |