[Xcb] [PATCH Xcb] Added more error states and removed global error_connection
Uli Schlachter
psychon at znc.in
Tue Nov 8 00:58:59 PST 2011
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
On 04.11.2011 14:36, Arvind Umrao wrote:
> I have added more xcb connection errorstates at xcb.h header.
> Also I have removed global error_connection variable and added
> an interface that returns connection error state.
>
> As Uli Schlachter suggested, I have added seperate static variable for
> every possible error at _xcb_conn_ret_error() to make thread safe.
>
> TBD:
> I will segregate errors states in a separate header file and try to
> provide more precise error states, in future. Also I will give patch
> for libX11, in that patch xcb_connection_t::has_error will be passed
> to default io handler of libX11, This value can then be used for
> displaying error messages.
>
> Signed-off-by: Arvind Umrao <arvind.umrao at oracle.com>
> ---
[...]
> +/* Return connection error state.
> + * To make thread-safe, I need a seperate static
> + * variable for every possible error.
> + */
> +xcb_connection_t *_xcb_conn_ret_error(int err)
> +{
> +
> + switch(err)
> + {
> + case XCB_CONN_CLOSED_MEM_INSUFFICIENT:
> + {
> + static int error_mem;
> + error_mem = err;
> + return (xcb_connection_t *) &error_mem;
> + }
> + case XCB_CONN_CLOSED_PARSE_ERR:
> + {
> + static int error_parser;
> + error_parser = err;
> + return (xcb_connection_t *) &error_parser;
> + }
> + case XCB_CONN_ERROR:
> + default:
> + {
> + static int error_connection;
> + error_connection = XCB_CONN_ERROR;
> + return (xcb_connection_t *) &error_connection;
> + }
> + }
> }
[...]
I just noticed that this assumes that writing to an int is atomic (=reading it
at the same time will either return the old or the new value, but never
garbage). I don't know which arches don't have atomic stores, but I know that I
saw "#ifdef"s in other projects for that.
Can't this be turned into:
static int error_mem = XCB_CONN_CLOSED_MEM_INSUFFICIENT;
(And perhaps be moved out of this function into global context, but I know that
this isn't going to happen due to some broken compiler on solaris(?)...)
Anyone could enlighten me if there are actually arches on which this code would
break?
Uli
- --
"Do you know that books smell like nutmeg or some spice from a foreign land?"
-- Faber in Fahrenheit 451
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iQEcBAEBCAAGBQJOuO9QAAoJECLkKOvLj8sGNKMH/1mHYTnICRi2XxAgBQMufVFO
PB+y0kJtvLRD2xn6v+IP9MWvyWI4AVGipyAY0UQM/HIIrLOt6Y4vp5+rHrbsW7CU
iMzY0uYZStf2smr4UTp5HUHe6T6ypNCnUrVpqMbNQOzfyyoX7x4rIjUN0r7n54xJ
gpefjc2xWJV+1Ncjh/OR4wHUmWsvQb3yVfsqKKI5zCw+q2/7lfNzOL7JjMfDIynT
LQg7HjjuOF0HSTD4w1K/zSV1TGpPTFep2D/Gvr6U9IBzwa2hdjpVZO3HHnDMRNAq
TBSxB0SEIHekedYZ2XwMMFqzqyxjMbR5EjCWAsCeWO1pfw/DDklWWGAArC4OgZY=
=Nwwr
-----END PGP SIGNATURE-----
More information about the Xcb
mailing list