diff -r ebc84c812384 -r 46218c8b8afa Symbian3/PDK/Source/GUID-E7C41361-C0B9-5341-A864-B59770FB7C9B.dita --- a/Symbian3/PDK/Source/GUID-E7C41361-C0B9-5341-A864-B59770FB7C9B.dita Thu Mar 11 15:24:26 2010 +0000 +++ b/Symbian3/PDK/Source/GUID-E7C41361-C0B9-5341-A864-B59770FB7C9B.dita Thu Mar 11 18:02:22 2010 +0000 @@ -1,96 +1,96 @@ - - - - - -Supporting -Writable Static Data in DLLs -
Introduction

Many UNIX programs rely -on Writable Static Data (WSD) for data storage. Native Symbian platform applications -have been developed without any support for WSD on an Emulator for dynamic -link libraries. P.I.P.S. supports WSD and a complete implementation is available -for target phones. The implementation of WSD on an Emulator, however, poses -certain restrictions for dynamic link libraries.

A Symbian project's -MMP file can specify the EPOCALLOWDLLDATA directive to enforce -a rule that WSD should not be shared between processes. The P.I.P.S. STDEXEy -target type sets this directive automatically. The rule imposes the restriction -that only one process can load a DLL with WSD. P.I.P.S. provides a mechanism -to avoid these restrictions.

-
A UNIX DLL with WSDint refCount = 0; -int IncRefCount() -{ - //Increment the reference count - return ++refCount; -} - -int DecRefCount() -{ - //Decrement the reference count - return --refCount; -} -

-
A Symbian DLL with WSD

The UNIX code above will -provide indeterminate results on a Symbian emulator. If the DLL had EPOCALLOWDLLDATA in -its MMP file, then only one process would be able to use the reference counting -functions. Without EPOCALLOWDLLDATA, the reference count -would be global and not process specific.

The following code demonstrates -the use of the Pls() function (Process Local Storage), -which is the P.I.P.S. WSD solution to the problem.

#include <pls.h> - -#ifdef __WINSCW__ -//The next code will run only on the emulator - -//Put the global count into a structure -struct DLLData -{ - int refCount; -}; - -//Define a way to access the structure -//On the first call to this function, memory will be allocated with the specified -//UID as an identifier and the Initialization function will be called -//Subsequent calls to this function return the allocated memory -struct DLLData* GetGlobals() -{ - return Pls<DLLData>(KDLLUid3, InitializeGlobals); -} - -//Initialization function -TInt InitializeGlobals(DLLData* aData) -{ - aData->refCount = 0; - return KErrNone; -} - -//Access the refCount variable -int& get_refCount() -{ - return GetClobals()->refCount; -} - -//Macro to replace the variable with our new method -#define refCount get_refCount() - -#else -//Target device code -int refCount; - -#endif - -int IncRefCount() -{ - return ++refCount; -} - -int DecRefCount() -{ - return --refCount; -} -
+ + + + + +Supporting +Writable Static Data in DLLs +
Introduction

Many UNIX programs rely +on Writable Static Data (WSD) for data storage. Native Symbian platform applications +have been developed without any support for WSD on an Emulator for dynamic +link libraries. P.I.P.S. supports WSD and a complete implementation is available +for target phones. The implementation of WSD on an Emulator, however, poses +certain restrictions for dynamic link libraries.

A Symbian project's +MMP file can specify the EPOCALLOWDLLDATA directive to enforce +a rule that WSD should not be shared between processes. The P.I.P.S. STDEXEy +target type sets this directive automatically. The rule imposes the restriction +that only one process can load a DLL with WSD. P.I.P.S. provides a mechanism +to avoid these restrictions.

+
A UNIX DLL with WSDint refCount = 0; +int IncRefCount() +{ + //Increment the reference count + return ++refCount; +} + +int DecRefCount() +{ + //Decrement the reference count + return --refCount; +} +

+
A Symbian DLL with WSD

The UNIX code above will +provide indeterminate results on a Symbian emulator. If the DLL had EPOCALLOWDLLDATA in +its MMP file, then only one process would be able to use the reference counting +functions. Without EPOCALLOWDLLDATA, the reference count +would be global and not process specific.

The following code demonstrates +the use of the Pls() function (Process Local Storage), +which is the P.I.P.S. WSD solution to the problem.

#include <pls.h> + +#ifdef __WINSCW__ +//The next code will run only on the emulator + +//Put the global count into a structure +struct DLLData +{ + int refCount; +}; + +//Define a way to access the structure +//On the first call to this function, memory will be allocated with the specified +//UID as an identifier and the Initialization function will be called +//Subsequent calls to this function return the allocated memory +struct DLLData* GetGlobals() +{ + return Pls<DLLData>(KDLLUid3, InitializeGlobals); +} + +//Initialization function +TInt InitializeGlobals(DLLData* aData) +{ + aData->refCount = 0; + return KErrNone; +} + +//Access the refCount variable +int& get_refCount() +{ + return GetClobals()->refCount; +} + +//Macro to replace the variable with our new method +#define refCount get_refCount() + +#else +//Target device code +int refCount; + +#endif + +int IncRefCount() +{ + return ++refCount; +} + +int DecRefCount() +{ + return --refCount; +} +
\ No newline at end of file