Changeset 615:8abafd66a617 in freeDiameter
- Timestamp:
- Dec 3, 2010, 1:31:41 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
freeDiameter/tests/testfifo.c
r494 r615 35 35 36 36 #include "tests.h" 37 #include <unistd.h> 37 38 38 39 /* Structure for testing threshold function */ … … 203 204 int count; 204 205 int i; 206 int nbr_threads; 207 208 nbr_threads = sysconf(_SC_THREAD_THREADS_MAX); 209 if ((nbr_threads <= 0) || (nbr_threads > NBR_THREADS / 2)) { 210 nbr_threads = NBR_THREADS; 211 } else { 212 /* The local limit is bellow NBR_THREADS */ 213 nbr_threads = (nbr_threads / 2) - 1; 214 /* Ensure we create at least a few threads! */ 215 CHECK( 1, nbr_threads >= 10 ? 1 : 0 ); 216 } 205 217 206 218 /* Create the queue */ … … 208 220 209 221 /* Create the barrier */ 210 CHECK( 0, pthread_barrier_init(&bar, NULL, NBR_THREADS* 2 + 1) );222 CHECK( 0, pthread_barrier_init(&bar, NULL, nbr_threads * 2 + 1) ); 211 223 212 224 /* Initialize the ts */ … … 216 228 /* Create the messages */ 217 229 CHECK( 0, fd_dict_search ( fd_g_config->cnf_dict, DICT_COMMAND, CMD_BY_NAME, "Device-Watchdog-Request", &dwr_model, ENOENT ) ); 218 for (i = 0; i < NBR_MSG * NBR_THREADS* 2; i++) {230 for (i = 0; i < NBR_MSG * nbr_threads * 2; i++) { 219 231 CHECK( 0, fd_msg_new ( dwr_model, 0, &msgs[i] ) ); 220 232 } … … 231 243 232 244 /* Create the threads */ 233 for (i=0; i < NBR_THREADS* 2; i++) {245 for (i=0; i < nbr_threads * 2; i++) { 234 246 CHECK( 0, pthread_create( &thr[i], NULL, test_fct, (i & 1) ? &td_1 : &td_2 ) ); 235 247 } … … 246 258 247 259 /* Now post all the messages */ 248 for (i=0; i < NBR_MSG * NBR_THREADS* 2; i++) {260 for (i=0; i < NBR_MSG * nbr_threads * 2; i++) { 249 261 msg = msgs[i]; 250 262 CHECK( 0, fd_fifo_post(queue, &msg) ); … … 252 264 253 265 /* Join all threads. This blocks if messages are lost... */ 254 for (i=0; i < NBR_THREADS* 2; i++) {266 for (i=0; i < nbr_threads * 2; i++) { 255 267 CHECK( 0, pthread_join( thr[i], NULL ) ); 256 268 } … … 262 274 /* Destroy this queue and the messages */ 263 275 CHECK( 0, fd_fifo_del(&queue) ); 264 for (i=0; i < NBR_MSG * NBR_THREADS* 2; i++) {276 for (i=0; i < NBR_MSG * nbr_threads * 2; i++) { 265 277 CHECK( 0, fd_msg_free( msgs[i] ) ); 266 278 }
Note: See TracChangeset
for help on using the changeset viewer.