michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include michael@0: #include "primpl.h" michael@0: michael@0: /* Lock used to lock the environment */ michael@0: #if defined(_PR_NO_PREEMPT) michael@0: #define _PR_NEW_LOCK_ENV() michael@0: #define _PR_DELETE_LOCK_ENV() michael@0: #define _PR_LOCK_ENV() michael@0: #define _PR_UNLOCK_ENV() michael@0: #elif defined(_PR_LOCAL_THREADS_ONLY) michael@0: extern _PRCPU * _pr_primordialCPU; michael@0: static PRIntn _is; michael@0: #define _PR_NEW_LOCK_ENV() michael@0: #define _PR_DELETE_LOCK_ENV() michael@0: #define _PR_LOCK_ENV() if (_pr_primordialCPU) _PR_INTSOFF(_is); michael@0: #define _PR_UNLOCK_ENV() if (_pr_primordialCPU) _PR_INTSON(_is); michael@0: #else michael@0: static PRLock *_pr_envLock = NULL; michael@0: #define _PR_NEW_LOCK_ENV() {_pr_envLock = PR_NewLock();} michael@0: #define _PR_DELETE_LOCK_ENV() \ michael@0: { if (_pr_envLock) { PR_DestroyLock(_pr_envLock); _pr_envLock = NULL; } } michael@0: #define _PR_LOCK_ENV() { if (_pr_envLock) PR_Lock(_pr_envLock); } michael@0: #define _PR_UNLOCK_ENV() { if (_pr_envLock) PR_Unlock(_pr_envLock); } michael@0: #endif michael@0: michael@0: /************************************************************************/ michael@0: michael@0: void _PR_InitEnv(void) michael@0: { michael@0: _PR_NEW_LOCK_ENV(); michael@0: } michael@0: michael@0: void _PR_CleanupEnv(void) michael@0: { michael@0: _PR_DELETE_LOCK_ENV(); michael@0: } michael@0: michael@0: PR_IMPLEMENT(char*) PR_GetEnv(const char *var) michael@0: { michael@0: char *ev; michael@0: michael@0: if (!_pr_initialized) _PR_ImplicitInitialization(); michael@0: michael@0: _PR_LOCK_ENV(); michael@0: ev = _PR_MD_GET_ENV(var); michael@0: _PR_UNLOCK_ENV(); michael@0: return ev; michael@0: } michael@0: michael@0: PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string) michael@0: { michael@0: PRIntn result; michael@0: michael@0: if (!_pr_initialized) _PR_ImplicitInitialization(); michael@0: michael@0: if ( !strchr(string, '=')) return(PR_FAILURE); michael@0: michael@0: _PR_LOCK_ENV(); michael@0: result = _PR_MD_PUT_ENV(string); michael@0: _PR_UNLOCK_ENV(); michael@0: return (result)? PR_FAILURE : PR_SUCCESS; michael@0: }