checkin of static-buffer-vs-talloc-snprintf
Context: https://gerrit.osmocom.org/c/osmo-hnbgw/+/33169
This commit is contained in:
commit
879625286b
|
@ -0,0 +1,58 @@
|
|||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/select.h>
|
||||
#include <osmocom/core/timer.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
|
||||
|
||||
/* context: https://gerrit.osmocom.org/c/osmo-hnbgw/+/33169 */
|
||||
|
||||
#define USE_SELECT
|
||||
|
||||
static struct osmo_timer_list exit_timer;
|
||||
static unsigned int print_count;
|
||||
|
||||
const char *print_static(void)
|
||||
{
|
||||
static __thread char buf[40];
|
||||
snprintf(buf, sizeof(buf), "%u-%u-L%u-R%u-S%u", 901, 70, 23, 40, 1);
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *print_talloc(void)
|
||||
{
|
||||
return talloc_asprintf(OTC_SELECT, "%u-%u-L%u-R%u-S%u", 901, 70, 23, 40, 1);
|
||||
}
|
||||
|
||||
static void do_prints(unsigned int count)
|
||||
{
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
#ifdef USE_SELECT
|
||||
print_talloc();
|
||||
#else
|
||||
print_static();
|
||||
#endif
|
||||
print_count++;
|
||||
}
|
||||
}
|
||||
|
||||
static void timer_cb(void *data)
|
||||
{
|
||||
printf("printed %u iterations\n", print_count);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
osmo_timer_setup(&exit_timer, timer_cb, NULL);
|
||||
osmo_timer_schedule(&exit_timer, 1, 0);
|
||||
|
||||
while (true) {
|
||||
do_prints(5);
|
||||
#ifdef USE_SELECT
|
||||
osmo_select_main_ctx(true);
|
||||
#else
|
||||
osmo_select_main(true);
|
||||
#endif
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue