common.h
author Tero Marttila <terom@fixme.fi>
Wed, 27 Aug 2008 21:30:32 +0300
changeset 41 540737bf6bac
parent 26 6d615203d963
permissions -rw-r--r--
sending requests, and partial support for receiving -- incomplete, not tested
8
4d38ccbeb93e * fix Makefile to build in a (more) sensible way (still not really perfect)
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
     1
4d38ccbeb93e * fix Makefile to build in a (more) sensible way (still not really perfect)
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
     2
/*
4d38ccbeb93e * fix Makefile to build in a (more) sensible way (still not really perfect)
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
     3
 * error handling
4d38ccbeb93e * fix Makefile to build in a (more) sensible way (still not really perfect)
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
     4
 */
4d38ccbeb93e * fix Makefile to build in a (more) sensible way (still not really perfect)
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
     5
23
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
     6
void _generic_err ( /*int level, */ int use_stderr, const char *func, int perr, const char *fmt, ...)
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
     7
        __attribute__ ((format (printf, 4, 5)));
19
d18606bb6f20 a working threaded sliced render, plus modifications to other modules to use this in web_main
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
     8
d18606bb6f20 a working threaded sliced render, plus modifications to other modules to use this in web_main
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
     9
// needs to be defined as its own function for the noreturn attribute
23
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    10
void _generic_err_exit ( /* int level, */ int used_stderr, const char *func, int perr, const char *fmt, ...)
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    11
        __attribute__ ((format (printf, 4, 5)))
19
d18606bb6f20 a working threaded sliced render, plus modifications to other modules to use this in web_main
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
    12
        __attribute__ ((noreturn));
d18606bb6f20 a working threaded sliced render, plus modifications to other modules to use this in web_main
Tero Marttila <terom@fixme.fi>
parents: 15
diff changeset
    13
20
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    14
enum _debug_level {
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    15
    DEBUG_FATAL,
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    16
    DEBUG_ERROR,
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    17
    DEBUG_WARNING,
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    18
    DEBUG_INFO,
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    19
    DEBUG_DEBUG,
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    20
};
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    21
23
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    22
// not currently used
20
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    23
extern enum _debug_level _cur_debug_level;
8
4d38ccbeb93e * fix Makefile to build in a (more) sensible way (still not really perfect)
Tero Marttila <terom@fixme.fi>
parents: 2
diff changeset
    24
12
43297144f196 * rename files, render_file -> file_main, render_node -> node_main, mandelbrot -> render_mandelbrot
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    25
// various kinds of ways to handle an error, 2**3 of them, *g*
23
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    26
#define info(...)                   _generic_err(       0,  NULL,   0,  __VA_ARGS__ )
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    27
#define error(...)                  _generic_err(       1,  NULL,   0,  __VA_ARGS__ )
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    28
#define err_exit(...)               _generic_err_exit(  1,  NULL,   0,  __VA_ARGS__ )
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    29
#define perr(...)                   _generic_err(       1,  NULL,   1,  __VA_ARGS__ )
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    30
#define perr_exit(...)              _generic_err_exit(  1,  NULL,   1,  __VA_ARGS__ )
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    31
#define err_func(func, ...)         _generic_err(       1,  func,   0,  __VA_ARGS__ )
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    32
#define err_func_exit(func, ...)    _generic_err_exit(  1,  func,   0,  __VA_ARGS__ )
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    33
#define perr_func(func, ...)        _generic_err(       1,  func,   1,  __VA_ARGS__ )
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    34
#define perr_func_exit(func, ...)   _generic_err_exit(  1,  func,   1,  __VA_ARGS__ )
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    35
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    36
// error(func + colon + msg, ...) + goto error
12
43297144f196 * rename files, render_file -> file_main, render_node -> node_main, mandelbrot -> render_mandelbrot
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    37
#define ERROR(...) do { err_func(__func__, __VA_ARGS__); goto error; } while (0)
43297144f196 * rename files, render_file -> file_main, render_node -> node_main, mandelbrot -> render_mandelbrot
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    38
#define PERROR(...) do { perr_func(__func__, __VA_ARGS__); goto error; } while (0)
43297144f196 * rename files, render_file -> file_main, render_node -> node_main, mandelbrot -> render_mandelbrot
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    39
#define FATAL(...) err_func_exit(__func__, __VA_ARGS__)
43297144f196 * rename files, render_file -> file_main, render_node -> node_main, mandelbrot -> render_mandelbrot
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    40
#define PFATAL(...) perr_func_exit(__func__, __VA_ARGS__)
43297144f196 * rename files, render_file -> file_main, render_node -> node_main, mandelbrot -> render_mandelbrot
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    41
#define WARNING(...) err_func(__func__, __VA_ARGS__)
43297144f196 * rename files, render_file -> file_main, render_node -> node_main, mandelbrot -> render_mandelbrot
Tero Marttila <terom@fixme.fi>
parents: 11
diff changeset
    42
#define PWARNING(...) perr_func(__func__, __VA_ARGS__)
11
082bfaf38cf0 * massive structural rewrite. Split off code into several new modules (render, render_png, render_local) and updated new modules to use them.
Tero Marttila <terom@fixme.fi>
parents: 8
diff changeset
    43
20
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    44
#ifdef DEBUG_ENABLED
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    45
#define DEBUG(...) err_func(__func__, __VA_ARGS__)
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    46
#else
24
8307d28329ae render_thread works now
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    47
#define DEBUG(...) (void) (0)
20
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    48
#endif
7512207c9041 write a DEBUG macro and change the render_threads stuff to use it. Shuffle the mutexes in render_threads around again to fix yet another bug... seems to work, but meh
Tero Marttila <terom@fixme.fi>
parents: 19
diff changeset
    49
23
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    50
// default is to enable INFO
25
a1e271de54c2 replace printf -> INFO
Tero Marttila <terom@fixme.fi>
parents: 24
diff changeset
    51
#ifdef INFO_DISABLED
a1e271de54c2 replace printf -> INFO
Tero Marttila <terom@fixme.fi>
parents: 24
diff changeset
    52
    #define INFO_ENABLED 0
a1e271de54c2 replace printf -> INFO
Tero Marttila <terom@fixme.fi>
parents: 24
diff changeset
    53
#else
a1e271de54c2 replace printf -> INFO
Tero Marttila <terom@fixme.fi>
parents: 24
diff changeset
    54
    #ifndef INFO_ENABLED
a1e271de54c2 replace printf -> INFO
Tero Marttila <terom@fixme.fi>
parents: 24
diff changeset
    55
        #define INFO_ENABLED 1
a1e271de54c2 replace printf -> INFO
Tero Marttila <terom@fixme.fi>
parents: 24
diff changeset
    56
    #endif
23
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    57
#endif
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    58
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    59
#if INFO_ENABLED
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    60
#define INFO(...) info(__VA_ARGS__)
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    61
#else
24
8307d28329ae render_thread works now
Tero Marttila <terom@fixme.fi>
parents: 23
diff changeset
    62
#define INFO(...) (void) (0)
23
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    63
#endif
31307efd7e78 new render_threads module, make node_main use it, compiles, not yet tested
Tero Marttila <terom@fixme.fi>
parents: 20
diff changeset
    64