2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH TD_SYNC_GET_INFO 3C_DB "Jun 5, 2007"
8 td_sync_get_info, td_ta_sync_tracking_enable, td_sync_get_stats,
9 td_sync_setstate, td_sync_waiters \- operations on a synchronization object in
14 cc [ \fIflag\fR... ] \fIfile\fR... -lc_db [ \fIlibrary\fR... ]
15 #include <proc_service.h>
16 #include <thread_db.h>
18 \fBtd_err_e\fR \fBtd_sync_get_info\fR(\fBconst td_synchandle_t *\fR\fIsh_p\fR, \fBtd_syncinfo_t *\fR\fIsi_p\fR);
23 \fBtd_err_e\fR \fBtd_ta_sync_tracking_enable\fR(\fBconst td_thragent_t *\fR\fIta_p\fR, \fBint\fR \fIon_off\fR);
28 \fBtd_err_e\fR \fBtd_sync_get_stats\fR(\fBconst td_synchandle_t *\fR\fIsh_p\fR, \fBtd_syncstats_t *\fR\fIss_p\fR);
33 \fBtd_err_e\fR \fBtd_sync_setstate\fR(\fBconst td_synchandle_t *\fR\fIsh_p\fR);
38 \fBtypedef int\fR \fBtd_thr_iter_f\fR(\fBconst td_thrhandle_t *\fR\fIth_p\fR, \fBvoid *\fR\fIcb_data_p\fR);
43 \fBtd_err_e\fR \fBtd_sync_waiters\fR(\fBconst td_synchandle_t *\fR\fIsh_p\fR, \fBtd_thr_iter_f *\fR\fIcb\fR,
44 \fBvoid *\fR\fIcb_data_p\fR);
50 Synchronization objects include mutexes, condition variables, semaphores, and
51 reader-writer locks. In the same way that thread operations use a thread handle
52 of type \fBtd_thrhandle_t\fR, operations on synchronization objects use a
53 synchronization object handle of type \fBtd_synchandle_t\fR.
56 The controlling process obtains synchronization object handles either by
57 calling the function \fBtd_ta_sync_iter()\fR to obtain handles for all
58 synchronization objects of the target process that are known to the
59 \fBlibc_db\fR library of interfaces, or by mapping the address of a
60 synchronization object in the address space of the target process to a handle
61 by calling \fBtd_ta_map_addr2sync\fR(3C_DB).
64 Not all synchronization objects that a process uses can be known to the
65 \fBlibc_db\fR library and returned by \fBtd_ta_sync_iter\fR(3C_DB). A
66 synchronization object is known to \fBlibc_db\fR only if it has been the target
67 of a synchronization primitive in the process (such as \fBmutex_lock()\fR,
68 described on the \fBmutex_init\fR(3C) manual page) after \fBtd_ta_new\fR(3C_DB)
69 has been called to attach to the process and \fBtd_ta_sync_tracking_enable()\fR
70 has been called to enable synchronization object tracking.
73 The \fBtd_ta_sync_tracking_enable()\fR function turns synchronization object
74 tracking on or off for the process identified by \fIta_p\fR, depending on
75 whether \fIon_off\fR is 0 (off) or non-zero (on).
78 The \fBtd_sync_get_info()\fR function fills in the \fBtd_syncinfo_t\fR
79 structure \fB*\fR\fIsi_p\fR with values for the synchronization object
80 identified by \fBsh_p\fR. The \fBtd_syncinfo_t\fR structure contains the
85 \fB\fBtd_thragent_t *\fR\fIsi_ta_p\fR\fR
88 The internal process handle identifying the target process through which this
89 synchronization object handle was obtained. Synchronization objects may be
90 process-private or process-shared. In the latter case, the same synchronization
91 object may have multiple handles, one for each target process's "view" of the
92 synchronization object.
98 \fB\fBpsaddr_t\fR \fIsi_sv_addr\fR\fR
101 The address of the synchronization object in this target process's address
108 \fB\fBtd_sync_type_e\fR \fIsi_type\fR\fR
111 The type of the synchronization variable: mutex, condition variable, semaphore,
112 or readers-writer lock.
118 \fB\fBint\fR \fIsi_shared_type\fR\fR
121 If \fIsi_shared_type\fR is non-zero, this synchronization object is
122 process-shared, otherwise it is process-private.
128 \fB\fBtd_sync_flags_t\fR \fIsi_flags\fR\fR
131 Flags dependent on the type of the synchronization object.
137 \fB\fBint\fR \fIsi_state.sema_count\fR\fR
140 Semaphores only. The current value of the semaphore
146 \fB\fBint\fR \fIsi_state.nreaders\fR\fR
149 Readers-writer locks only. The number of readers currently holding the lock, or
150 \fB-1\fR, if a writer is currently holding the lock.
156 \fB\fBint\fR \fIsi_state.mutex_locked\fR\fR
159 For mutexes only. Non-zero if and only if the mutex is currently locked.
165 \fB\fBint\fR \fIsi_size\fR\fR
168 The size of the synchronization object.
174 \fB\fBuint8_t\fR \fIsi_has_waiters\fR\fR
177 Non-zero if and only if at least one thread is blocked on this synchronization
184 \fB\fBuint8_t\fR \fIsi_is_wlocked\fR\fR
187 For reader-writer locks only. The value is non-zero if and only if this lock is
194 \fB\fBuint8_t\fR \fIsi_rcount\fR\fR
197 \fBPTHREAD_MUTEX_RECURSIVE\fR mutexes only. If the mutex is held, the recursion
204 \fB\fBuint8_t\fR \fIsi_prioceiling\fR\fR
207 \fBPTHREAD_PRIO_PROTECT\fR protocol mutexes only. The priority ceiling.
213 \fB\fBtd_thrhandle_t\fR \fIsi_owner\fR\fR
216 Mutexes and readers-writer locks only. This is the thread holding the mutex, or
217 the write lock, if this is a reader-writer lock. The value is \fINULL\fR if
218 no one holds the mutex or write-lock.
224 \fB\fBpid_t\fR \fIsi_ownerpid\fR\fR
227 Mutexes only. For a locked process-shared mutex, this is the process-ID of the
228 process containing the owning thread.
233 The \fBtd_sync_get_stats()\fR function fills in the \fBtd_syncstats_t\fR
234 structure *\fIss_p\fR with values for the synchronization object identified by
235 \fIsh_p\fR. The \fBtd_syncstats_t\fR structure contains an embedded
236 \fBtd_syncinfo_t\fR structure that is filled in as described above for
237 \fBtd_sync_get_info()\fR. In addition, usage statistics gathered since
238 \fBtd_ta_sync_tracking_enable()\fR was called to enable synchronization object
239 tracking are returned in the \fBss_un.mutex\fR, \fBss_un.cond\fR,
240 \fBss_un.rwlock\fR, or \fBss_un.sema\fR members of the \fBtd_syncstats_t\fR
241 structure, depending on the type of the synchronization object.
244 The \fBtd_sync_setstate\fR function modifies the state of synchronization
245 object \fIsi_p\fR, depending on the synchronization object type. For mutexes,
246 \fBtd_sync_setstate\fR is unlocked if the value is \fB0\fR. Otherwise it is
247 locked. For semaphores, the semaphore's count is set to the value. For
248 reader-writer locks, the reader count set to the value if value is \fB>0\fR.
249 The count is set to write-locked if value is \fB-1\fR\&. It is set to unlocked
250 if the value is \fB0\fR. Setting the state of a synchronization object from a
251 \fBlibc_db\fR interface may cause the synchronization object's semantics to be
252 violated from the point of view of the threads in the target process. For
253 example, if a thread holds a mutex, and \fBtd_sync_setstate\fR is used to set
254 the mutex to unlocked, then a different thread will also be able to
255 subsequently acquire the same mutex.
258 The \fBtd_sync_waiters\fR function iterates over the set of thread handles of
259 threads blocked on \fIsh_p\fR. The callback function \fIcb\fR is called once
260 for each such thread handle, and is passed the thread handle and
261 \fIcb_data_p\fR. If the callback function returns a non-zero value, iteration
262 is terminated early. See \fBtd_ta_thr_iter\fR(3C_DB).
270 The call returned successfully.
276 \fB\fBTD_BADTH\fR \fR
279 An invalid thread handle was passed in.
285 \fB\fBTD_DBERR\fR \fR
288 A call to one of the imported interface routines failed.
297 A libc_db-internal error occurred.
303 See \fBattributes\fR(5) for descriptions of the following attributes:
311 ATTRIBUTE TYPE ATTRIBUTE VALUE
319 \fBlibc_db\fR(3LIB), \fBmutex_init\fR(3C), \fBtd_ta_map_addr2sync\fR(3C_DB),
320 \fBtd_ta_sync_iter\fR(3C_DB), \fBtd_ta_thr_iter\fR(3C_DB), \fBattributes\fR(5)