~ubuntu-branches/ubuntu/saucy/libpthread-workqueue/saucy

« back to all changes in this revision

Viewing changes to src/private.h

  • Committer: Bazaar Package Importer
  • Author(s): Mark Heily
  • Date: 2011-06-13 21:38:33 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110613213833-9x35wmobwumwjvje
Tags: 0.7-1
* New upstream version.
    - Prevent deadlocks by implementing the overcommit attribute

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include "pthread_workqueue.h"
47
47
#include "debug.h"
48
48
 
 
49
/* The maximum number of workqueues that can be created.
 
50
   This is based on libdispatch only needing 6 workqueues.
 
51
   */
 
52
#define PTHREAD_WORKQUEUE_MAX 31
 
53
 
49
54
/* The total number of priority levels. */
50
55
#define WORKQ_NUM_PRIOQUEUE 3
51
56
 
67
72
 
68
73
#define CACHELINE_SIZE  64
69
74
#define ROUND_UP_TO_CACHELINE_SIZE(x)   (((x) + (CACHELINE_SIZE - 1)) & ~(CACHELINE_SIZE - 1))
70
 
#define WITEM_CACHE_DISABLE 1
 
75
 
 
76
/*
 
77
 * The work item cache, has three different optional implementations:
 
78
 * 1. No cache, just normal malloc/free using the standard malloc library in use
 
79
 * 2. Libumem based object cache, requires linkage with libumem - for non-Solaris see http://labs.omniti.com/labs/portableumem
 
80
 *    this is the most balanced cache supporting migration across threads of allocated/freed witems
 
81
 * 3. TSD based cache, modelled on libdispatch continuation implementation, can lead to imbalance with assymetric 
 
82
 *    producer/consumer threads as allocated memory is cached by the thread freeing it
 
83
 */
 
84
 
 
85
#define WITEM_CACHE_TYPE 1 // Set to 1, 2 or 3 to specify witem cache implementation to use
71
86
 
72
87
struct work {
73
88
    STAILQ_ENTRY(work)   item_entry; 
75
90
    void                *func_arg;
76
91
    unsigned int         flags;
77
92
    unsigned int         gencount;
 
93
#if (WITEM_CACHE_TYPE == 3)
78
94
        struct work *volatile wi_next;
 
95
#endif
79
96
};
80
97
 
81
98
struct worker {
93
110
    unsigned int         flags;
94
111
    int                  queueprio;
95
112
    int                  overcommit;
96
 
    LIST_ENTRY(_pthread_workqueue) wqlist_entry;
 
113
    unsigned int         wqlist_index;
97
114
    STAILQ_HEAD(,work)   item_listhead;
98
115
    pthread_spinlock_t   mtx;
99
116
#ifdef WORKQUEUE_PLATFORM_SPECIFIC
101
118
#endif
102
119
};
103
120
 
 
121
/* manager.c */
104
122
int manager_init(void);
105
123
void manager_workqueue_create(struct _pthread_workqueue *);
106
124
void manager_workqueue_additem(struct _pthread_workqueue *, struct work *);
107
125
 
108
 
struct work *witem_alloc_from_heap(void);
109
 
struct work *witem_alloc_cacheonly();
 
126
struct work *witem_alloc(void (*func)(void *), void *func_arg); // returns a properly initialized witem
110
127
void witem_free(struct work *wi);
111
128
int witem_cache_init(void);
112
129
void witem_cache_cleanup(void *value);