Bug 1885489 - Part 9: Add SnapshotIterator::readObject(). r=iain
[gecko.git] / docs / nspr / reference / pr_setthreadprivate.rst
blob0f24c5b3869461165fd389d094c077fb4651b100
1 PR_SetThreadPrivate
2 ===================
4 Sets per-thread private data.
7 Syntax
8 ------
10 .. code::
12    #include <prthread.h>
14    PRStatus PR_SetThreadPrivate(PRUintn index, void *priv);
17 Parameters
18 ~~~~~~~~~~
20 :ref:`PR_SetThreadPrivate` has the following parameters:
22 ``index``
23    An index into the per-thread private data table.
24 ``priv``
25    The per-thread private data, or more likely, a pointer to the data.
28 Returns
29 ~~~~~~~
31 The function returns one of the following values:
33 -  If successful, ``PR_SUCCESS``.
34 -  If the index is invalid, ``PR_FAILURE``.
37 Description
38 -----------
40 If the thread already has non-``NULL`` private data associated with it,
41 and if the destructor function for the index is known (not ``NULL``),
42 NSPR calls the destructor function associated with the index before
43 setting the new data value. The pointer at the index is swapped with
44 ``NULL``. If the swapped out value is not ``NULL``, the destructor
45 function is called. On return, the private data associated with the
46 index is reassigned the new private data's value, even if it is
47 ``NULL``. The runtime provides no protection for the private data. The
48 destructor is called with the runtime holding no locks. Synchronization
49 is the client's responsibility.
51 The only way to eliminate thread private data at an index prior to the
52 thread's termination is to call :ref:`PR_SetThreadPrivate` with a ``NULL``
53 argument. This causes the index's destructor function to be called, and
54 afterwards assigns a ``NULL`` in the table. A client must not delete the
55 referent object of a non-``NULL`` private data without first eliminating
56 it from the table.