1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is the Netscape Portable Runtime (NSPR).
15
* The Initial Developer of the Original Code is Netscape
16
* Communications Corporation. Portions created by Netscape are
17
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
22
* Alternatively, the contents of this file may be used under the
23
* terms of the GNU General Public License Version 2 or later (the
24
* "GPL"), in which case the provisions of the GPL are applicable
25
* instead of those above. If you wish to allow use of your
26
* version of this file only under the terms of the GPL and not to
27
* allow others to use your version of this file under the MPL,
28
* indicate your decision by deleting the provisions above and
29
* replace them with the notice and other provisions required by
30
* the GPL. If you do not delete the provisions above, a recipient
31
* may use your version of this file under either the MPL or the
41
#include <sys/types.h>
42
#include <sys/socket.h>
44
#include <sys/ioctl.h>
48
* Make sure _PRSockLen_t is 32-bit, because we will cast a PRUint32* or
49
* PRInt32* pointer to a _PRSockLen_t* pointer.
51
#define _PRSockLen_t int
54
** Global lock variable used to bracket calls into rusty libraries that
55
** aren't thread safe (like libc, libX, etc).
57
static PRLock *_pr_rename_lock = NULL;
58
static PRMonitor *_pr_Xfe_mon = NULL;
61
* Variables used by the GC code, initialized in _MD_InitSegs().
62
* _pr_zero_fd should be a static variable. Unfortunately, there is
63
* still some Unix-specific code left in function PR_GrowSegment()
64
* in file memory/prseg.c that references it, so it needs
65
* to be a global variable for now.
67
PRInt32 _pr_zero_fd = -1;
68
static PRLock *_pr_md_lock = NULL;
74
struct sigaction sigact;
77
sigemptyset(&timer_set);
79
sigact.sa_handler = SIG_IGN;
80
sigemptyset(&sigact.sa_mask);
82
rv = sigaction(SIGPIPE, &sigact, 0);
85
_pr_rename_lock = PR_NewLock();
86
PR_ASSERT(NULL != _pr_rename_lock);
87
_pr_Xfe_mon = PR_NewMonitor();
88
PR_ASSERT(NULL != _pr_Xfe_mon);
92
*-----------------------------------------------------------------------
96
* Returns the current time in microseconds since the epoch.
97
* The epoch is midnight January 1, 1970 GMT.
98
* The implementation is machine dependent. This is the Unix
100
* Cf. time_t time(time_t *tp)
102
*-----------------------------------------------------------------------
112
LL_I2L(s2us, PR_USEC_PER_SEC);
113
LL_I2L(s, tv.tv_sec);
114
LL_I2L(us, tv.tv_usec);
121
_PR_UNIX_GetInterval()
124
PRIntervalTime ticks;
126
(void)GETTIMEOFDAY(&time); /* fallicy of course */
127
ticks = (PRUint32)time.tv_sec * PR_MSEC_PER_SEC; /* that's in milliseconds */
128
ticks += (PRUint32)time.tv_usec / PR_USEC_PER_MSEC; /* so's that */
130
} /* _PR_SUNOS_GetInterval */
132
PRIntervalTime _PR_UNIX_TicksPerSecond()
134
return 1000; /* this needs some work :) */
137
/************************************************************************/
140
** Special hacks for xlib. Xlib/Xt/Xm is not re-entrant nor is it thread
141
** safe. Unfortunately, neither is mozilla. To make these programs work
142
** in a pre-emptive threaded environment, we need to use a lock.
147
PR_EnterMonitor(_pr_Xfe_mon);
152
PR_ExitMonitor(_pr_Xfe_mon);
155
PRBool PR_XIsLocked()
157
return (PR_InMonitor(_pr_Xfe_mon)) ? PR_TRUE : PR_FALSE;
160
void PR_XWait(int ms)
162
PR_Wait(_pr_Xfe_mon, PR_MillisecondsToInterval(ms));
165
void PR_XNotify(void)
167
PR_Notify(_pr_Xfe_mon);
170
void PR_XNotifyAll(void)
172
PR_NotifyAll(_pr_Xfe_mon);
176
#ifdef HAVE_BSD_FLOCK
178
#include <sys/file.h>
180
PR_IMPLEMENT(PRStatus)
181
_MD_LOCKFILE (PRInt32 f)
184
rv = flock(f, LOCK_EX);
187
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
191
PR_IMPLEMENT(PRStatus)
192
_MD_TLOCKFILE (PRInt32 f)
195
rv = flock(f, LOCK_EX|LOCK_NB);
198
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
202
PR_IMPLEMENT(PRStatus)
203
_MD_UNLOCKFILE (PRInt32 f)
206
rv = flock(f, LOCK_UN);
209
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
214
PR_IMPLEMENT(PRStatus)
215
_MD_LOCKFILE (PRInt32 f)
218
rv = lockf(f, F_LOCK, 0);
221
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
225
PR_IMPLEMENT(PRStatus)
226
_MD_TLOCKFILE (PRInt32 f)
229
rv = lockf(f, F_TLOCK, 0);
232
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
236
PR_IMPLEMENT(PRStatus)
237
_MD_UNLOCKFILE (PRInt32 f)
240
rv = lockf(f, F_ULOCK, 0);
243
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
248
PR_IMPLEMENT(PRStatus)
249
_MD_GETHOSTNAME (char *name, PRUint32 namelen)
253
rv = gethostname(name, namelen);
257
_PR_MD_MAP_GETHOSTNAME_ERROR(_MD_ERRNO());