00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _ASTERISK_SCHED_H
00025 #define _ASTERISK_SCHED_H
00026
00027 #if defined(__cplusplus) || defined(c_plusplus)
00028 extern "C" {
00029 #endif
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #define AST_SCHED_DEL(sched, id) \
00047 ({ \
00048 int _count = 0; \
00049 int _sched_res = -1; \
00050 while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) \
00051 usleep(1); \
00052 if (_count == 10) { \
00053 ast_debug(3, "Unable to cancel schedule ID %d.\n", id); \
00054 } \
00055 id = -1; \
00056 (_sched_res); \
00057 })
00058
00059
00060
00061
00062
00063
00064 #define AST_SCHED_DEL_UNREF(sched, id, refcall) \
00065 do { \
00066 int _count = 0; \
00067 while (id > -1 && ast_sched_del(sched, id) && ++_count < 10) { \
00068 usleep(1); \
00069 } \
00070 if (_count == 10) \
00071 ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
00072 if (id > -1) \
00073 refcall; \
00074 id = -1; \
00075 } while (0);
00076
00077
00078
00079
00080
00081 #define AST_SCHED_DEL_SPINLOCK(sched, id, lock) \
00082 ({ \
00083 int _count = 0; \
00084 int _sched_res = -1; \
00085 while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) { \
00086 ast_mutex_unlock(lock); \
00087 usleep(1); \
00088 ast_mutex_lock(lock); \
00089 } \
00090 if (_count == 10) { \
00091 ast_debug(3, "Unable to cancel schedule ID %d.\n", id); \
00092 } \
00093 id = -1; \
00094 (_sched_res); \
00095 })
00096
00097 #define AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, variable) \
00098 do { \
00099 int _count = 0; \
00100 while (id > -1 && ast_sched_del(sched, id) && ++_count < 10) { \
00101 usleep(1); \
00102 } \
00103 if (_count == 10) \
00104 ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
00105 id = ast_sched_add_variable(sched, when, callback, data, variable); \
00106 } while (0);
00107
00108 #define AST_SCHED_REPLACE(id, sched, when, callback, data) \
00109 AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0)
00110
00111
00112
00113
00114
00115 #define AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, variable, unrefcall, addfailcall, refcall) \
00116 do { \
00117 int _count = 0, _res=1; \
00118 void *_data = (void *)ast_sched_find_data(sched, id); \
00119 while (id > -1 && (_res = ast_sched_del(sched, id) && _count++ < 10)) { \
00120 usleep(1); \
00121 } \
00122 if (!_res && _data) \
00123 unrefcall; \
00124 if (_count == 10) \
00125 ast_log(LOG_WARNING, "Unable to cancel schedule ID %d. This is probably a bug (%s: %s, line %d).\n", id, __FILE__, __PRETTY_FUNCTION__, __LINE__); \
00126 refcall; \
00127 id = ast_sched_add_variable(sched, when, callback, data, variable); \
00128 if (id == -1) \
00129 addfailcall; \
00130 } while (0);
00131
00132 #define AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall) \
00133 AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, 0, unrefcall, addfailcall, refcall)
00134
00135
00136
00137
00138
00139
00140 struct ast_sched_context *ast_sched_context_create(void);
00141
00142
00143
00144
00145
00146
00147 void ast_sched_context_destroy(struct ast_sched_context *c);
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 typedef int (*ast_sched_cb)(const void *data);
00158 #define AST_SCHED_CB(a) ((ast_sched_cb)(a))
00159
00160 struct ast_cb_names {
00161 int numassocs;
00162 char *list[10];
00163 ast_sched_cb cblist[10];
00164 };
00165
00166
00167
00168
00169
00170
00171
00172
00173 void ast_sched_report(struct ast_sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames);
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result;
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 int ast_sched_replace(int old_id, struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result;
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224 int ast_sched_add_variable(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result;
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 int ast_sched_replace_variable(int old_id, struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result;
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 const void *ast_sched_find_data(struct ast_sched_context *con, int id);
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 #ifndef AST_DEVMODE
00264 int ast_sched_del(struct ast_sched_context *con, int id) attribute_warn_unused_result;
00265 #else
00266 int _ast_sched_del(struct ast_sched_context *con, int id, const char *file, int line, const char *function) attribute_warn_unused_result;
00267 #define ast_sched_del(a, b) _ast_sched_del(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00268 #endif
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result;
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 int ast_sched_runq(struct ast_sched_context *con);
00297
00298
00299
00300
00301
00302
00303
00304
00305 void ast_sched_dump(struct ast_sched_context *con);
00306
00307
00308
00309
00310
00311
00312
00313 long ast_sched_when(struct ast_sched_context *con,int id);
00314
00315
00316
00317
00318
00319 #define ast_sched_add_object(obj,con,when,callback) ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj)))
00320
00321
00322
00323
00324
00325 #define ast_sched_del_object(obj,destructor,con,id) do { \
00326 if ((id) > -1) { \
00327 ast_sched_del((con),(id)); \
00328 (id) = -1; \
00329 ASTOBJ_UNREF((obj),(destructor)); \
00330 } \
00331 } while(0)
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 int ast_sched_start_thread(struct ast_sched_context *con);
00342
00343 #if defined(__cplusplus) || defined(c_plusplus)
00344 }
00345 #endif
00346
00347 #endif