week 10 bug fix submission (SF PDK version): Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.
<?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 <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;
}
</codeblock></section>
</conbody></concept>