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 #define AST_SCHED_DEL_ACCESSOR(sched, obj, getter, setter) \
00060 ({ \
00061 int _count = 0; \
00062 int _sched_res = -1; \
00063 while (getter(obj) > -1 && (_sched_res = ast_sched_del(sched, getter(obj))) && ++_count < 10) \
00064 usleep(1); \
00065 if (_count == 10) { \
00066 ast_debug(3, "Unable to cancel schedule ID %d.\n", getter(obj)); \
00067 } \
00068 setter(obj, -1); \
00069 (_sched_res); \
00070 })
00071
00072
00073
00074
00075
00076
00077 #define AST_SCHED_DEL_UNREF(sched, id, refcall) \
00078 do { \
00079 int _count = 0; \
00080 while (id > -1 && ast_sched_del(sched, id) && ++_count < 10) { \
00081 usleep(1); \
00082 } \
00083 if (_count == 10) \
00084 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__); \
00085 if (id > -1) \
00086 refcall; \
00087 id = -1; \
00088 } while (0);
00089
00090
00091
00092
00093
00094 #define AST_SCHED_DEL_SPINLOCK(sched, id, lock) \
00095 ({ \
00096 int _count = 0; \
00097 int _sched_res = -1; \
00098 while (id > -1 && (_sched_res = ast_sched_del(sched, id)) && ++_count < 10) { \
00099 ast_mutex_unlock(lock); \
00100 usleep(1); \
00101 ast_mutex_lock(lock); \
00102 } \
00103 if (_count == 10) { \
00104 ast_debug(3, "Unable to cancel schedule ID %d.\n", id); \
00105 } \
00106 id = -1; \
00107 (_sched_res); \
00108 })
00109
00110 #define AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, variable) \
00111 do { \
00112 int _count = 0; \
00113 while (id > -1 && ast_sched_del(sched, id) && ++_count < 10) { \
00114 usleep(1); \
00115 } \
00116 if (_count == 10) \
00117 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__); \
00118 id = ast_sched_add_variable(sched, when, callback, data, variable); \
00119 } while (0);
00120
00121 #define AST_SCHED_REPLACE(id, sched, when, callback, data) \
00122 AST_SCHED_REPLACE_VARIABLE(id, sched, when, callback, data, 0)
00123
00124
00125
00126
00127
00128 #define AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, variable, unrefcall, addfailcall, refcall) \
00129 do { \
00130 int _count = 0, _res=1; \
00131 void *_data = (void *)ast_sched_find_data(sched, id); \
00132 while (id > -1 && (_res = ast_sched_del(sched, id) && _count++ < 10)) { \
00133 usleep(1); \
00134 } \
00135 if (!_res && _data) \
00136 unrefcall; \
00137 if (_count == 10) \
00138 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__); \
00139 refcall; \
00140 id = ast_sched_add_variable(sched, when, callback, data, variable); \
00141 if (id == -1) \
00142 addfailcall; \
00143 } while (0);
00144
00145 #define AST_SCHED_REPLACE_UNREF(id, sched, when, callback, data, unrefcall, addfailcall, refcall) \
00146 AST_SCHED_REPLACE_VARIABLE_UNREF(id, sched, when, callback, data, 0, unrefcall, addfailcall, refcall)
00147
00148
00149
00150
00151
00152
00153 struct ast_sched_context *ast_sched_context_create(void);
00154
00155
00156
00157
00158
00159
00160 void ast_sched_context_destroy(struct ast_sched_context *c);
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170 typedef int (*ast_sched_cb)(const void *data);
00171 #define AST_SCHED_CB(a) ((ast_sched_cb)(a))
00172
00173 struct ast_cb_names {
00174 int numassocs;
00175 char *list[10];
00176 ast_sched_cb cblist[10];
00177 };
00178
00179
00180
00181
00182
00183
00184
00185
00186 void ast_sched_report(struct ast_sched_context *con, struct ast_str **buf, struct ast_cb_names *cbnames);
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204 int ast_sched_add(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 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;
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 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;
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250 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;
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261 const void *ast_sched_find_data(struct ast_sched_context *con, int id);
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 #ifndef AST_DEVMODE
00277 int ast_sched_del(struct ast_sched_context *con, int id) attribute_warn_unused_result;
00278 #else
00279 int _ast_sched_del(struct ast_sched_context *con, int id, const char *file, int line, const char *function) attribute_warn_unused_result;
00280 #define ast_sched_del(a, b) _ast_sched_del(a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
00281 #endif
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296 int ast_sched_wait(struct ast_sched_context *con) attribute_warn_unused_result;
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309 int ast_sched_runq(struct ast_sched_context *con);
00310
00311
00312
00313
00314
00315
00316
00317
00318 void ast_sched_dump(struct ast_sched_context *con);
00319
00320
00321
00322
00323
00324
00325
00326 long ast_sched_when(struct ast_sched_context *con,int id);
00327
00328
00329
00330
00331
00332 #define ast_sched_add_object(obj,con,when,callback) ast_sched_add((con),(when),(callback), ASTOBJ_REF((obj)))
00333
00334
00335
00336
00337
00338 #define ast_sched_del_object(obj,destructor,con,id) do { \
00339 if ((id) > -1) { \
00340 ast_sched_del((con),(id)); \
00341 (id) = -1; \
00342 ASTOBJ_UNREF((obj),(destructor)); \
00343 } \
00344 } while(0)
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 int ast_sched_start_thread(struct ast_sched_context *con);
00355
00356 #if defined(__cplusplus) || defined(c_plusplus)
00357 }
00358 #endif
00359
00360 #endif