12248Sraf /* 22248Sraf * CDDL HEADER START 32248Sraf * 42248Sraf * The contents of this file are subject to the terms of the 52248Sraf * Common Development and Distribution License (the "License"). 62248Sraf * You may not use this file except in compliance with the License. 72248Sraf * 82248Sraf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 92248Sraf * or http://www.opensolaris.org/os/licensing. 102248Sraf * See the License for the specific language governing permissions 112248Sraf * and limitations under the License. 122248Sraf * 132248Sraf * When distributing Covered Code, include this CDDL HEADER in each 142248Sraf * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 152248Sraf * If applicable, add the following below this CDDL HEADER, with the 162248Sraf * fields enclosed by brackets "[]" replaced with your own identifying 172248Sraf * information: Portions Copyright [yyyy] [name of copyright owner] 182248Sraf * 192248Sraf * CDDL HEADER END 202248Sraf */ 212248Sraf 222248Sraf /* 23*6812Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 242248Sraf * Use is subject to license terms. 252248Sraf */ 262248Sraf 272248Sraf #ifndef _SIGEV_THREAD_H 282248Sraf #define _SIGEV_THREAD_H 292248Sraf 302248Sraf #pragma ident "%Z%%M% %I% %E% SMI" 312248Sraf 322248Sraf #ifdef __cplusplus 332248Sraf extern "C" { 342248Sraf #endif 352248Sraf 362248Sraf #include <signal.h> 372248Sraf #include <port.h> 382248Sraf #include <mqueue.h> 392248Sraf #include <time.h> 402248Sraf #include <limits.h> 412248Sraf #include <semaphore.h> 422248Sraf #include <thread_pool.h> 432248Sraf 442248Sraf #define SIGEV_THREAD_TERM 1 452248Sraf 462248Sraf typedef enum {TIMER = 1, MQ, AIO} subsystem_t; /* Calling sub-system */ 472248Sraf 482248Sraf typedef struct { 492248Sraf void (*std_func)(union sigval); /* User-defined notification function */ 502248Sraf union sigval std_arg; /* Parameter of user-defined notification fct */ 512248Sraf } sigev_thread_data_t; 522248Sraf 532248Sraf typedef struct thread_communication_data { 542248Sraf struct thread_communication_data *tcd_next; 552248Sraf struct sigevent tcd_notif; /* encapsulates usr fct and usr vals */ 562248Sraf pthread_attr_t tcd_user_attr; /* copy of caller's attributes */ 572248Sraf pthread_attr_t *tcd_attrp; /* NULL if caller passed NULL */ 582248Sraf int tcd_port; /* port this spawner is controlling */ 592248Sraf thread_t tcd_server_id; /* thread id of server thread */ 602248Sraf subsystem_t tcd_subsystem; /* event generating subsystem */ 612248Sraf tpool_t *tcd_poolp; /* worker thread pool */ 622248Sraf /* for creation/termination synchronization protocol */ 632248Sraf mutex_t tcd_lock; 642248Sraf cond_t tcd_cv; 652248Sraf /* subsystem-specific data */ 662248Sraf union { 672248Sraf struct { 682248Sraf int overruns; /* number of overruns */ 692248Sraf } timer; 702248Sraf struct { 712248Sraf int msg_enabled; /* notification enabled */ 722248Sraf int msg_closing; /* mq_close() is waiting */ 732248Sraf sem_t *msg_avail; /* wait for message available */ 742248Sraf void *msg_object; /* mqd_t */ 752248Sraf void *msg_userval; /* notification user value */ 762248Sraf } mqueue; 772248Sraf } tcd_object; 782248Sraf } thread_communication_data_t; 792248Sraf 802248Sraf #define tcd_overruns tcd_object.timer.overruns 812248Sraf 822248Sraf #define tcd_msg_enabled tcd_object.mqueue.msg_enabled 832248Sraf #define tcd_msg_closing tcd_object.mqueue.msg_closing 842248Sraf #define tcd_msg_avail tcd_object.mqueue.msg_avail 852248Sraf #define tcd_msg_object tcd_object.mqueue.msg_object 862248Sraf #define tcd_msg_userval tcd_object.mqueue.msg_userval 872248Sraf 882248Sraf /* Generic functions common to all entities */ 892248Sraf extern thread_communication_data_t *setup_sigev_handler( 902248Sraf const struct sigevent *, subsystem_t); 912248Sraf extern void free_sigev_handler(thread_communication_data_t *); 922248Sraf extern int launch_spawner(thread_communication_data_t *); 932248Sraf extern void tcd_teardown(thread_communication_data_t *); 942248Sraf 952248Sraf /* Additional functions for different entities */ 962248Sraf extern void *timer_spawner(void *); 972248Sraf extern int del_sigev_timer(timer_t); 982248Sraf extern int sigev_timer_getoverrun(timer_t); 992248Sraf extern void *mqueue_spawner(void *); 1002248Sraf extern void del_sigev_mq(thread_communication_data_t *); 1012248Sraf extern void *aio_spawner(void *); 1022248Sraf 1032248Sraf /* Private interfaces elsewhere in libc */ 104*6812Sraf extern int pthread_attr_clone(pthread_attr_t *, const pthread_attr_t *); 105*6812Sraf extern int pthread_attr_equal(const pthread_attr_t *, const pthread_attr_t *); 1062248Sraf extern int _port_dispatch(int, int, int, int, uintptr_t, void *); 1072248Sraf 1082248Sraf extern thread_communication_data_t *sigev_aio_tcd; 1092248Sraf 1102248Sraf extern int timer_max; 1112248Sraf extern thread_communication_data_t **timer_tcd; 1122248Sraf 1132248Sraf #ifdef __cplusplus 1142248Sraf } 1152248Sraf #endif 1162248Sraf 1172248Sraf #endif /* _SIGEV_THREAD_H */ 118