nsprpub/pr/src/misc/prenv.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include <string.h>
     7 #include "primpl.h"
     9 /* Lock used to lock the environment */
    10 #if defined(_PR_NO_PREEMPT)
    11 #define _PR_NEW_LOCK_ENV()
    12 #define _PR_DELETE_LOCK_ENV()
    13 #define _PR_LOCK_ENV()
    14 #define _PR_UNLOCK_ENV()
    15 #elif defined(_PR_LOCAL_THREADS_ONLY)
    16 extern _PRCPU * _pr_primordialCPU;
    17 static PRIntn _is;
    18 #define _PR_NEW_LOCK_ENV()
    19 #define _PR_DELETE_LOCK_ENV()
    20 #define _PR_LOCK_ENV() if (_pr_primordialCPU) _PR_INTSOFF(_is);
    21 #define _PR_UNLOCK_ENV() if (_pr_primordialCPU) _PR_INTSON(_is);
    22 #else
    23 static PRLock *_pr_envLock = NULL;
    24 #define _PR_NEW_LOCK_ENV() {_pr_envLock = PR_NewLock();}
    25 #define _PR_DELETE_LOCK_ENV() \
    26     { if (_pr_envLock) { PR_DestroyLock(_pr_envLock); _pr_envLock = NULL; } }
    27 #define _PR_LOCK_ENV() { if (_pr_envLock) PR_Lock(_pr_envLock); }
    28 #define _PR_UNLOCK_ENV() { if (_pr_envLock) PR_Unlock(_pr_envLock); }
    29 #endif
    31 /************************************************************************/
    33 void _PR_InitEnv(void)
    34 {
    35 	_PR_NEW_LOCK_ENV();
    36 }
    38 void _PR_CleanupEnv(void)
    39 {
    40     _PR_DELETE_LOCK_ENV();
    41 }
    43 PR_IMPLEMENT(char*) PR_GetEnv(const char *var)
    44 {
    45     char *ev;
    47     if (!_pr_initialized) _PR_ImplicitInitialization();
    49     _PR_LOCK_ENV();
    50     ev = _PR_MD_GET_ENV(var);
    51     _PR_UNLOCK_ENV();
    52     return ev;
    53 }
    55 PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string)
    56 {
    57     PRIntn result;
    59     if (!_pr_initialized) _PR_ImplicitInitialization();
    61     if ( !strchr(string, '=')) return(PR_FAILURE);
    63     _PR_LOCK_ENV();
    64     result = _PR_MD_PUT_ENV(string);
    65     _PR_UNLOCK_ENV();
    66     return (result)? PR_FAILURE : PR_SUCCESS;
    67 }

mercurial