Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

monthread.h

Go to the documentation of this file.
00001 
00002 
00003 /*
00004 ** Copyright (C) 2005 Russell Leighton
00005 **
00006 ** This program is free software; you can redistribute it and/or modify
00007 ** it under the terms of the GNU General Public License as published by
00008 ** the Free Software Foundation; either version 2 of the License, or
00009 ** (at your option) any later version.
00010 **
00011 ** This program is distributed in the hope that it will be useful,
00012 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 ** GNU General Public License for more details.
00015 **
00016 ** You should have received a copy of the GNU General Public License
00017 ** along with this program; if not, write to the Free Software
00018 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef __AWMONTHREAD__
00022 #define __AWMONTHREAD__
00023 
00024 #include "sysnet.h"
00025 #include "util.h"
00026 #include "monsignals.h"
00027 
00034 /* how we do locking */
00035 typedef sem_t aw_plock_t;
00036 #define AW_MONTHREAD_INITLOCK(lock) sem_init( &(lock), 0, 1)
00037 #define AW_MONTHREAD_DESTROYLOCK(lock) sem_destroy( &(lock) )
00038 #define AW_MONTHREAD_DOLOCK(lock) { while (unlikely(sem_wait(lock))) { perror(__FUNCTION__); } }
00039 #define AW_MONTHREAD_UNLOCK(lock) { while (unlikely(sem_post(lock))) { perror(__FUNCTION__); } } 
00040 
00041 /* struct to hold thread for monitor */
00042 typedef struct {
00043 
00044   int32_t
00045    pid;
00046 
00047   /* function and arg to run w/clone() */
00048   int32_t (*f)(void *);
00049   void *arg;
00050 
00051   /* holds ptr to mmap()d data */
00052   int32_t
00053    stacksize;
00054   void
00055    *stack; /* this is the top of thread stack , but also includes the signal stack */
00056   int32_t
00057    ts_size; /* size of portion of stack allocated to thread */
00058 
00059   /* signal stack for sigaltstack(), points to segment in above mmap()d stack */
00060   stack_t
00061    signal_stack;
00062 
00063   /* non-zero to notify */
00064   int32_t
00065    notify;
00066 
00067 } aw_monthread_t;
00068 
00069 
00075 aw_monthread_t *aw_create_monthread(int32_t stacksize, int32_t (*f)(void *arg), void *arg);
00076 
00083 inline int32_t aw_in_monthread(aw_monthread_t *t);
00084 
00091 inline void *aw_globalptr_monthread(aw_monthread_t *t);
00092 
00099 inline int32_t aw_test_wait_monthread(aw_monthread_t *t);
00100 
00106 void aw_wait_monthread(aw_monthread_t *t);
00107 
00113 void aw_notify_monthread(aw_monthread_t *t);
00114 
00120 void aw_clear_notify_monthread(aw_monthread_t *t);
00121 
00127 void aw_destroy_monthread(aw_monthread_t *t);
00128 
00135 void aw_wait_destroy_monthread(aw_monthread_t *t, time_t seconds);
00136 
00137 #endif
Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)