1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2001,2008 Oracle.  All rights reserved.
5 *
6 * $Id: os_pid.c,v 12.27 2008/01/08 20:58:43 bostic Exp $
7 */
8
9#include "db_config.h"
10
11#include "db_int.h"
12
13#ifdef HAVE_MUTEX_SUPPORT
14#include "dbinc/mutex_int.h"		/* Required to load appropriate
15					   header files for thread functions. */
16#endif
17
18/*
19 * __os_id --
20 *	Return the current process ID.
21 *
22 * PUBLIC: void __os_id __P((DB_ENV *, pid_t *, db_threadid_t*));
23 */
24void
25__os_id(dbenv, pidp, tidp)
26	DB_ENV *dbenv;
27	pid_t *pidp;
28	db_threadid_t *tidp;
29{
30	/*
31	 * We can't depend on dbenv not being NULL, this routine is called
32	 * from places where there's no DB_ENV handle.
33	 *
34	 * We cache the pid in the ENV handle, getting the process ID is a
35	 * fairly slow call on lots of systems.
36	 */
37	if (pidp != NULL) {
38		if (dbenv == NULL) {
39#if defined(HAVE_VXWORKS)
40			*pidp = taskIdSelf();
41#else
42			*pidp = getpid();
43#endif
44		} else
45			*pidp = dbenv->env->pid_cache;
46	}
47
48	if (tidp != NULL) {
49#if defined(DB_WIN32)
50		*tidp = GetCurrentThreadId();
51#elif defined(HAVE_MUTEX_UI_THREADS)
52		*tidp = thr_self();
53#elif defined(HAVE_MUTEX_SOLARIS_LWP) || \
54	defined(HAVE_MUTEX_PTHREADS) || defined(HAVE_PTHREAD_API)
55		*tidp = pthread_self();
56#else
57		/*
58		 * Default to just getpid.
59		 */
60		*tidp = 0;
61#endif
62	}
63}
64