jdk/src/solaris/hpi/native_threads/include/monitor_md.h
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1994, 1998, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Monitor interface    10/25/94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * Private data structures and interfaces used in the monitor code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * This file is used to share declarations and such between the different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * files implementing monitors.  It does not contain exported API.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#ifndef _JAVASOFT_SOLARIS_MONITOR_MD_H_
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#define _JAVASOFT_SOLARIS_MONITOR_MD_H_
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include <mutex_md.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include <condvar_md.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include <threads_md.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Type definitions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
typedef struct monitor_waiter monitor_waiter_t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
typedef struct monitor_wait_queue monitor_wait_queue_t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
/* Element of the MonitorWaitQ - representing thread doing a monitor wait */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The only reason we do the queueing is for sysMonitorDumpInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * The counting, though, is used to avoid extraneous calls to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * condvarBroadcast and condvarSignal, for instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
struct monitor_waiter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    monitor_waiter_t   *next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    monitor_waiter_t  **prev;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    sys_thread_t       *waiting_thread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
struct monitor_wait_queue {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    monitor_waiter_t   *head;           /* linked list of waiting threads */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    short               count;          /* number of waiters on the list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#define ANY_WAITING(mwq) ((mwq).count > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define INIT_MONITOR_WAIT_QUEUE(mwq) { (mwq).head = NULL; (mwq).count = 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/* The system-level monitor data structure */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
struct sys_mon {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    mutex_t             mutex;          /* The monitor's mutex */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    condvar_t           cv_monitor;     /* Notify those doing monitorWait on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                                           the monitor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Threads waiting on either of the above condvars put themselves
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * on one of these lists.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    monitor_wait_queue_t mwait_queue;   /* Head of MonitorWaitQ */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /* Thread currently executing in this monitor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    sys_thread_t        *monitor_owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    long                entry_count;    /* Recursion depth */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    int                 contention_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
void initializeContentionCountMutex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
typedef enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        ASYNC_REGISTER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        ASYNC_UNREGISTER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
} async_action_t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * Macros
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#define SYS_MID_NULL ((sys_mon_t *) 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
typedef enum {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        SYS_ASYNC_MON_ALARM = 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        SYS_ASYNC_MON_IO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        SYS_ASYNC_MON_EVENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        SYS_ASYNC_MON_CHILD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        SYS_ASYNC_MON_MAX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
} async_mon_key_t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#define SYS_ASYNC_MON_INPUT SYS_ASYNC_MON_IO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
#define SYS_ASYNC_MON_OUTPUT SYS_ASYNC_MON_IO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
sys_mon_t *asyncMon(async_mon_key_t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
#endif /* !_JAVASOFT_SOLARIS_MONITOR_MD_H_ */