+/*
+ Allows for configuration of a ring after it has been allocated.
+ Options are RING_* options that allow for things like setting/clearing
+ read locking. Returns 0 for failure 1 on success.
+
+ Options can be ORd together and all made effective at the same time, but
+ it will be impossible to determine a specific failure if invoked this
+ way. Control is returned on the first error, and no provision is made
+ to "undo" previously set options if an error occurs.
+*/
+static int uta_ring_config( void* vr, int options ) {
+ ring_t* r;
+
+ if( (r = (ring_t*) vr) == NULL ) {
+ errno = EINVAL;
+ return 0;
+ }
+
+ if( options & RING_WLOCK ) {
+ if( r->wgate == NULL ) { // don't realloc
+ r->wgate = (pthread_mutex_t *) malloc( sizeof( *r->wgate ) );
+ if( r->wgate == NULL ) {
+ return 0;
+ }
+
+ pthread_mutex_init( r->wgate, NULL );
+ }
+ }
+
+ if( options & RING_RLOCK ) {
+ if( r->rgate == NULL ) { // don't realloc
+ r->rgate = (pthread_mutex_t *) malloc( sizeof( *r->rgate ) );
+ if( r->rgate == NULL ) {
+ return 0;
+ }
+
+ pthread_mutex_init( r->rgate, NULL );
+ }
+ }
+
+ return 1;
+}
+