Tuesday, November 30, 2010

CMPI's memory management and implementation of Open Pegasus

CMPI_ThreadContext data structure each CMPI_ThreadContext objects are bound to a thread and thread internal all shared by CMPI object.

Therefore CMPI_ThreadContext actually is a thread private data (ThreadSpecificData, TSD). Based on the pthread thread library provides support, CMPI_ThreadContext class contains a static variable of type pthread_key_t. Called by pthread_setspecific CMPI_ThreadContext address of itself and the key bindings. While other threads CMPI object, you can call to get the pthread_getspecific thread CMPI_ThreadContext address. Based on this kind of mechanism, different thread CMPI objects are individually. Pegasus uses specialized classes to encapsulate each CIM objects, such as CIMInstance, CIMDateTime etc, then these objects encapsulate as CMPI_Object again. The main Member CMPI_Object is a pointer to a pointer to the wrapped object hdl and a table with their corresponding functions. The other is used to construct a CMPI_Object two-way queue pointer prev and next. CMPI_ThreadContext maintains links to in the head and tail of a queue CMPI_Object two-way CIMfirst and CIMlast pointer. In the thread created all the CMPI objects are documented in the queue. In order to be able to automatically release all the messages in the queue, the object of CMPI CMPI_ThreadContext in destructor (see Listing 1), then call the queue object in the release method. CMPI_ThreadContext::~CMPI_ThreadContext(){for(CMPI_Object*nxt,*cur=CIMfirst;cur;cur=nxt){nxt=cur->next;(reinterpret_cast(cur))->ft->release(reinterpret_cast(cur));} TSDKeyTypek=getContextKey();TSDKey::set_thread_specific(k,prev);} Code Listing 1: CMPI_ThreadContext destructor in the above code, all objects are converted into CMPI_Object CMPIInstance object, then call a member method of release. Typically, this is wrong, because these CMPI object and cannot ensure that all CMPIInstance object. The above code is able to do so, because the release method always all CMPI object function table of the first member function. You can convert an object into any CMPI a CMPI object and call its methods and promise not to release any problems. So how does one CMPI_Object object automatically joined to the bi-directional queue? CMPI_Object for each CIM object defines the corresponding version of the constructor. In each constructor, are first received and CMPI_Object current thread associated CMPI_ThreadContext object, and then will own this pointer to join their CMPI_Object two-way queue. When explicitly called a CMPI_Object object release method, the object points to the actual CIM object is first deleted, and then release method of the this pointer from CMPI_Object belongs to two-way queue and remove.

No comments:

Post a Comment