summaryrefslogtreecommitdiff
path: root/src/os/os_pid.c
blob: b1b94d6016a20d9b1fe5d40121f535f2bfa745b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2001, 2012 Oracle and/or its affiliates.  All rights reserved.
 *
 * $Id$
 */

#include "db_config.h"

#include "db_int.h"

/*
 * __os_id --
 *	Return the current process ID.
 *
 * PUBLIC: void __os_id __P((DB_ENV *, pid_t *, db_threadid_t*));
 */
void
__os_id(dbenv, pidp, tidp)
	DB_ENV *dbenv;
	pid_t *pidp;
	db_threadid_t *tidp;
{
	/*
	 * We can't depend on dbenv not being NULL, this routine is called
	 * from places where there's no DB_ENV handle.
	 *
	 * We cache the pid in the ENV handle, getting the process ID is a
	 * fairly slow call on lots of systems.
	 */
	if (pidp != NULL) {
		if (dbenv == NULL) {
#if defined(HAVE_VXWORKS)
			*pidp = taskIdSelf();
#else
			*pidp = getpid();
#endif
		} else
			*pidp = dbenv->env->pid_cache;
	}

/* 
 * When building on MinGW, we define both HAVE_PTHREAD_SELF and DB_WIN32,
 * and we are using pthreads instead of Windows threads implementation.
 * So here, we need to check the thread implementations before checking
 * the platform.
 */
	if (tidp != NULL) {
#if defined(HAVE_PTHREAD_SELF)
		*tidp = pthread_self();
#elif defined(HAVE_MUTEX_UI_THREADS)
		*tidp = thr_self();
#elif defined(DB_WIN32)
		*tidp = GetCurrentThreadId();
#else
		/*
		 * Default to just getpid.
		 */
		DB_THREADID_INIT(*tidp);
#endif
	}
}