* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: callback.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
#pragma ident "@(#)callback.c 1.2 06/09/27 SMI"
typedef LIST_DEF(cb_list_t
, cb_entry_t
);
static cb_list_t cb_list
;
static pthread_mutex_t cb_lock
;
callback_fire(callback_type_t type
)
/* can't grab cb_lock as funcs call callback_delete()... */
for (i
= 0; i
< cb_list
.count
; i
++) {
p
= LIST_ENTRY(cb_list
, i
);
(*p
->cb_func
)(p
->cb_arg
);
callback_register(callback_type_t type
, cb_func_t func
, void *arg
)
pthread_mutex_lock(&cb_lock
);
for (i
= 0, p
= NULL
; i
< cb_list
.count
; i
++) {
p1
= LIST_ENTRY(cb_list
, i
);
if (p1
->type
== CB_None
) {
/* Allocate a new one? */
p
= LIST_ADD(cb_list
, cb_entry_t
);
pthread_mutex_unlock(&cb_lock
);
callback_delete(cb_func_t func
)
pthread_mutex_lock(&cb_lock
);
for (i
= 0; i
< cb_list
.count
; i
++) {
p
= LIST_ENTRY(cb_list
, i
);
p
->type
= CB_None
; /* Onto "free list". */
pthread_mutex_unlock(&cb_lock
);
pthread_mutex_init(&cb_lock
, NULL
);