00001 #ifndef __STUB_PROBE
00002 #pragma once
00003 #ifndef _SEAP_DESCRIPTOR_H
00004 #define _SEAP_DESCRIPTOR_H
00005
00006 #include <pthread.h>
00007 #include <stdint.h>
00008 #include "generic/bitmap.h"
00009 #include "generic/pqueue.h"
00010 #include "_sexp-types.h"
00011 #include "_sexp-parse.h"
00012 #include "_sexp-output.h"
00013 #include "_seap-command.h"
00014 #include "public/seap-scheme.h"
00015 #include "public/seap-message.h"
00016 #include "public/seap-command.h"
00017 #include "public/seap-error.h"
00018
00019
00020
00021
00022 typedef struct {
00023 SEAP_msgid_t next_id;
00024 SEXP_t *sexpbuf;
00025 SEXP_ostate_t *ostate;
00026 SEXP_pstate_t *pstate;
00027 SEAP_scheme_t scheme;
00028 void *scheme_data;
00029
00030
00031 SEXP_t *msg_queue;
00032 SEXP_t *err_queue;
00033 SEXP_t *cmd_queue;
00034
00035 pqueue_t *pck_queue;
00036
00037
00038
00039 pthread_mutex_t w_lock;
00040 pthread_mutex_t r_lock;
00041
00042 SEAP_cmdid_t next_cid;
00043 SEAP_cmdtbl_t *cmd_c_table;
00044 SEAP_cmdtbl_t *cmd_w_table;
00045 } SEAP_desc_t;
00046
00047 #define SEAP_DESC_FDIN 0x00000001
00048 #define SEAP_DESC_FDOUT 0x00000002
00049 #define SEAP_DESC_SELF -1
00050
00051 typedef struct {
00052 SEAP_desc_t *sd;
00053 uint16_t sdsize;
00054 bitmap_t bitmap;
00055 } SEAP_desctable_t;
00056
00057 #define SEAP_DESCTBL_INITIALIZER { NULL, 0, BITMAP_INITIALIZER }
00058
00059 #define SEAP_BUFFER_SIZE 4096
00060 #define SEAP_MAX_OPENDESC 128
00061 #define SDTABLE_REALLOC_ADD 4
00062
00063 int SEAP_desc_add (SEAP_desctable_t *sd_table, SEXP_pstate_t *pstate, SEAP_scheme_t scheme, void *scheme_data);
00064 int SEAP_desc_del (SEAP_desctable_t *sd_table, int sd);
00065 SEAP_desc_t *SEAP_desc_get (SEAP_desctable_t *sd_table, int sd);
00066
00067 #include <errno.h>
00068
00069 static inline int SEAP_desc_trylock (pthread_mutex_t *m)
00070 {
00071 switch (pthread_mutex_trylock (m)) {
00072 case 0:
00073 return (1);
00074 case EBUSY:
00075 return (0);
00076 case EINVAL:
00077 errno = EINVAL;
00078 default:
00079 return (-1);
00080 }
00081 }
00082
00083 static inline int SEAP_desc_lock (pthread_mutex_t *m)
00084 {
00085 switch (pthread_mutex_lock (m)) {
00086 case 0:
00087 return (1);
00088 default:
00089 return (-1);
00090 }
00091 }
00092
00093 static inline int SEAP_desc_unlock (pthread_mutex_t *m)
00094 {
00095 switch (pthread_mutex_unlock (m)) {
00096 case 0:
00097 return (1);
00098 default:
00099 return (-1);
00100 }
00101 }
00102
00103 #define DESC_TRYRLOCK(d) SEAP_desc_trylock (&((d)->r_lock))
00104 #define DESC_RLOCK(d) SEAP_desc_lock (&((d)->r_lock))
00105 #define DESC_RUNLOCK(d) SEAP_desc_unlock (&((d)->r_lock))
00106
00107 #define DESC_TRYWLOCK(d) SEAP_desc_trylock (&((d)->w_lock))
00108 #define DESC_WLOCK(d) SEAP_desc_lock (&((d)->w_lock))
00109 #define DESC_WUNLOCK(d) SEAP_desc_unlock (&((d)->w_lock))
00110
00111 SEAP_msgid_t SEAP_desc_genmsgid (SEAP_desctable_t *sd_table, int sd);
00112 SEAP_cmdid_t SEAP_desc_gencmdid (SEAP_desctable_t *sd_table, int sd);
00113
00114 #endif
00115 #endif