Symbian3/SDK/Source/GUID-E7C41361-C0B9-5341-A864-B59770FB7C9B.dita
changeset 0 89d6a7a84779
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Symbian3/SDK/Source/GUID-E7C41361-C0B9-5341-A864-B59770FB7C9B.dita	Thu Jan 21 18:18:20 2010 +0000
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
+<!-- This component and the accompanying materials are made available under the terms of the License 
+"Eclipse Public License v1.0" which accompanies this distribution, 
+and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
+<!-- Initial Contributors:
+    Nokia Corporation - initial contribution.
+Contributors: 
+-->
+<!DOCTYPE concept
+  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
+<concept id="GUID-E7C41361-C0B9-5341-A864-B59770FB7C9B" xml:lang="en"><title>Supporting
+Writable Static Data in DLLs </title><prolog><metadata><keywords/></metadata></prolog><conbody>
+<section><title>Introduction</title> <p>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. </p><p>A Symbian project's
+MMP file can specify the <codeph>EPOCALLOWDLLDATA</codeph> directive to enforce
+a rule that WSD should not be shared between processes. The P.I.P.S. <codeph>STDEXE</codeph>y
+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. </p> </section>
+<section><title>A UNIX DLL with WSD</title><codeblock xml:space="preserve">int refCount = 0;
+int IncRefCount()
+{
+  //Increment the reference count
+  return ++refCount;
+}
+
+int DecRefCount()
+{
+  //Decrement the reference count
+  return --refCount;
+}
+</codeblock><p/></section>
+<section><title>A Symbian DLL with WSD</title><p>The UNIX code above will
+provide indeterminate results on a Symbian emulator. If the DLL had <codeph>EPOCALLOWDLLDATA</codeph> in
+its MMP file, then only one process would be able to use the reference counting
+functions. Without <codeph>EPOCALLOWDLLDATA</codeph>, the reference count
+would be global and not process specific. </p><p>The following code demonstrates
+the use of the <xref href="GUID-807C676B-5C46-328C-879C-A4FCB638A5B6.dita"><apiname>Pls()</apiname></xref> function (Process Local Storage),
+which is the P.I.P.S. WSD solution to the problem. </p><codeblock xml:space="preserve">#include &lt;pls.h&gt;
+
+#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&lt;DLLData&gt;(KDLLUid3, InitializeGlobals);
+}
+
+//Initialization function
+TInt InitializeGlobals(DLLData* aData)
+{
+   aData-&gt;refCount = 0;
+   return KErrNone;
+}
+
+//Access the refCount variable
+int&amp; get_refCount()
+{
+   return GetClobals()-&gt;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;
+}
+</codeblock></section>
+</conbody></concept>
\ No newline at end of file