1 /* Pushdown stacks for integers, pointers, and characters.
2  *
3  * nstack - SRE 1 March 2000. [Seattle]
4  * mstack - SRE, Fri Oct 10 10:18:16 2003 [St. Louis]
5  * cstack - SRE, Mon Oct 13 12:57:56 2003 [St. Louis]
6  * Incorp into easel - SRE, Sun Dec 26 07:39:02 2004 [Zaragoza]
7  */
8 #ifndef eslSTACK_INCLUDED
9 #define eslSTACK_INCLUDED
10 #include "esl_config.h"
11 
12 #define ESL_STACK_INITALLOC 128	/* initial allocation; realloc by doubling  */
13 
14 #ifdef HAVE_PTHREAD
15 #include <pthread.h>
16 #endif
17 
18 #include "esl_random.h"
19 
20 typedef struct esl_stack_s {
21   int   *idata;			/* integer data stack                       */
22   void **pdata;			/* pointer data stack                       */
23   char  *cdata;			/* character data stack                     */
24 
25   int  n;			/* current (topmost) elem in data           */
26   int  nalloc;			/* # of elems allocated right now           */
27 
28 #ifdef HAVE_PTHREAD
29   int              do_mutex;	/* TRUE if we need to mutex-protect this stack */
30   int              do_cond;	/* TRUE if pushers want to notify poppers      */
31   pthread_mutex_t *mutex;	/* protect while operating on stacks           */
32   pthread_cond_t  *cond;	/* for pushers to notify poppers               */
33 #endif
34 } ESL_STACK;
35 
36 extern ESL_STACK *esl_stack_ICreate(void);
37 extern ESL_STACK *esl_stack_CCreate(void);
38 extern ESL_STACK *esl_stack_PCreate(void);
39 
40 extern int        esl_stack_Reuse(ESL_STACK *s);
41 extern void       esl_stack_Destroy(ESL_STACK *s);
42 
43 extern int esl_stack_IPush(ESL_STACK *ns, int x);
44 extern int esl_stack_CPush(ESL_STACK *cs, char c);
45 extern int esl_stack_PPush(ESL_STACK *ps, void *p);
46 
47 extern int esl_stack_IPop(ESL_STACK *ns, int   *ret_x);
48 extern int esl_stack_CPop(ESL_STACK *cs, char  *ret_c);
49 extern int esl_stack_PPop(ESL_STACK *ps, void **ret_p);
50 
51 extern int esl_stack_ObjectCount(ESL_STACK *s);
52 
53 extern char *esl_stack_Convert2String(ESL_STACK *cs);
54 extern int   esl_stack_DiscardTopN(ESL_STACK *s, int n);
55 extern int   esl_stack_DiscardSelected(ESL_STACK *s, int (*discard_func)(void *, void *), void *param);
56 
57 extern int esl_stack_Shuffle(ESL_RANDOMNESS *r, ESL_STACK *s);
58 
59 #ifdef HAVE_PTHREAD
60 extern int esl_stack_UseMutex   (ESL_STACK *s);
61 extern int esl_stack_UseCond    (ESL_STACK *s);
62 extern int esl_stack_ReleaseCond(ESL_STACK *s);
63 #endif
64 #endif /*eslSTACK_INCLUDED*/
65