aboutsummaryrefslogtreecommitdiff
path: root/src/linda.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linda.cpp')
-rw-r--r--src/linda.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/linda.cpp b/src/linda.cpp
index 10ee08b..ff3d543 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -53,7 +53,7 @@ struct s_Linda
53 SIGNAL_T write_happened; 53 SIGNAL_T write_happened;
54 Universe* U; // the universe this linda belongs to 54 Universe* U; // the universe this linda belongs to
55 ptrdiff_t group; // a group to control keeper allocation between lindas 55 ptrdiff_t group; // a group to control keeper allocation between lindas
56 enum e_cancel_request simulate_cancel; 56 CancelRequest simulate_cancel;
57 char name[1]; 57 char name[1];
58}; 58};
59#define LINDA_KEEPER_HASHSEED( linda) (linda->group ? linda->group : (ptrdiff_t)linda) 59#define LINDA_KEEPER_HASHSEED( linda) (linda->group ? linda->group : (ptrdiff_t)linda)
@@ -122,7 +122,7 @@ LUAG_FUNC( linda_send)
122{ 122{
123 struct s_Linda* linda = lua_toLinda( L, 1); 123 struct s_Linda* linda = lua_toLinda( L, 1);
124 bool ret{ false }; 124 bool ret{ false };
125 enum e_cancel_request cancel = CANCEL_NONE; 125 CancelRequest cancel{ CancelRequest::None };
126 int pushed; 126 int pushed;
127 time_d timeout = -1.0; 127 time_d timeout = -1.0;
128 int key_i = 2; // index of first key, if timeout not there 128 int key_i = 2; // index of first key, if timeout not there
@@ -178,9 +178,9 @@ LUAG_FUNC( linda_send)
178 { 178 {
179 cancel = s->cancel_request; 179 cancel = s->cancel_request;
180 } 180 }
181 cancel = (cancel != CANCEL_NONE) ? cancel : linda->simulate_cancel; 181 cancel = (cancel != CancelRequest::None) ? cancel : linda->simulate_cancel;
182 // if user wants to cancel, or looped because of a timeout, the call returns without sending anything 182 // if user wants to cancel, or looped because of a timeout, the call returns without sending anything
183 if( !try_again || cancel != CANCEL_NONE) 183 if (!try_again || cancel != CancelRequest::None)
184 { 184 {
185 pushed = 0; 185 pushed = 0;
186 break; 186 break;
@@ -241,12 +241,12 @@ LUAG_FUNC( linda_send)
241 241
242 switch( cancel) 242 switch( cancel)
243 { 243 {
244 case CANCEL_SOFT: 244 case CancelRequest::Soft:
245 // if user wants to soft-cancel, the call returns lanes.cancel_error 245 // if user wants to soft-cancel, the call returns lanes.cancel_error
246 CANCEL_ERROR.push(L); 246 CANCEL_ERROR.push(L);
247 return 1; 247 return 1;
248 248
249 case CANCEL_HARD: 249 case CancelRequest::Hard:
250 // raise an error interrupting execution only in case of hard cancel 250 // raise an error interrupting execution only in case of hard cancel
251 return cancel_error( L); // raises an error and doesn't return 251 return cancel_error( L); // raises an error and doesn't return
252 252
@@ -273,7 +273,7 @@ LUAG_FUNC( linda_receive)
273{ 273{
274 struct s_Linda* linda = lua_toLinda( L, 1); 274 struct s_Linda* linda = lua_toLinda( L, 1);
275 int pushed, expected_pushed_min, expected_pushed_max; 275 int pushed, expected_pushed_min, expected_pushed_max;
276 enum e_cancel_request cancel = CANCEL_NONE; 276 CancelRequest cancel{ CancelRequest::None };
277 keeper_api_t keeper_receive; 277 keeper_api_t keeper_receive;
278 278
279 time_d timeout = -1.0; 279 time_d timeout = -1.0;
@@ -335,9 +335,9 @@ LUAG_FUNC( linda_receive)
335 { 335 {
336 cancel = s->cancel_request; 336 cancel = s->cancel_request;
337 } 337 }
338 cancel = (cancel != CANCEL_NONE) ? cancel : linda->simulate_cancel; 338 cancel = (cancel != CancelRequest::None) ? cancel : linda->simulate_cancel;
339 // if user wants to cancel, or looped because of a timeout, the call returns without sending anything 339 // if user wants to cancel, or looped because of a timeout, the call returns without sending anything
340 if( !try_again || cancel != CANCEL_NONE) 340 if (!try_again || cancel != CancelRequest::None)
341 { 341 {
342 pushed = 0; 342 pushed = 0;
343 break; 343 break;
@@ -395,12 +395,12 @@ LUAG_FUNC( linda_receive)
395 395
396 switch( cancel) 396 switch( cancel)
397 { 397 {
398 case CANCEL_SOFT: 398 case CancelRequest::Soft:
399 // if user wants to soft-cancel, the call returns CANCEL_ERROR 399 // if user wants to soft-cancel, the call returns CANCEL_ERROR
400 CANCEL_ERROR.push(L); 400 CANCEL_ERROR.push(L);
401 return 1; 401 return 1;
402 402
403 case CANCEL_HARD: 403 case CancelRequest::Hard:
404 // raise an error interrupting execution only in case of hard cancel 404 // raise an error interrupting execution only in case of hard cancel
405 return cancel_error( L); // raises an error and doesn't return 405 return cancel_error( L); // raises an error and doesn't return
406 406
@@ -430,7 +430,7 @@ LUAG_FUNC( linda_set)
430 { 430 {
431 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); 431 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda));
432 432
433 if( linda->simulate_cancel == CANCEL_NONE) 433 if (linda->simulate_cancel == CancelRequest::None)
434 { 434 {
435 if( has_value) 435 if( has_value)
436 { 436 {
@@ -511,7 +511,7 @@ LUAG_FUNC( linda_get)
511 { 511 {
512 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); 512 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda));
513 513
514 if( linda->simulate_cancel == CANCEL_NONE) 514 if (linda->simulate_cancel == CancelRequest::None)
515 { 515 {
516 pushed = keeper_call( linda->U, K->L, KEEPER_API( get), L, linda, 2); 516 pushed = keeper_call( linda->U, K->L, KEEPER_API( get), L, linda, 2);
517 if( pushed > 0) 517 if( pushed > 0)
@@ -557,7 +557,7 @@ LUAG_FUNC( linda_limit)
557 { 557 {
558 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda)); 558 Keeper* K = which_keeper( linda->U->keepers, LINDA_KEEPER_HASHSEED( linda));
559 559
560 if( linda->simulate_cancel == CANCEL_NONE) 560 if (linda->simulate_cancel == CancelRequest::None)
561 { 561 {
562 pushed = keeper_call( linda->U, K->L, KEEPER_API( limit), L, linda, 2); 562 pushed = keeper_call( linda->U, K->L, KEEPER_API( limit), L, linda, 2);
563 ASSERT_L( pushed == 0 || pushed == 1); // no error, optional boolean value saying if we should wake blocked writer threads 563 ASSERT_L( pushed == 0 || pushed == 1); // no error, optional boolean value saying if we should wake blocked writer threads
@@ -592,7 +592,7 @@ LUAG_FUNC( linda_cancel)
592 // make sure we got 3 arguments: the linda, a key and a limit 592 // make sure we got 3 arguments: the linda, a key and a limit
593 luaL_argcheck( L, lua_gettop( L) <= 2, 2, "wrong number of arguments"); 593 luaL_argcheck( L, lua_gettop( L) <= 2, 2, "wrong number of arguments");
594 594
595 linda->simulate_cancel = CANCEL_SOFT; 595 linda->simulate_cancel = CancelRequest::Soft;
596 if( strcmp( who, "both") == 0) // tell everyone writers to wake up 596 if( strcmp( who, "both") == 0) // tell everyone writers to wake up
597 { 597 {
598 SIGNAL_ALL( &linda->write_happened); 598 SIGNAL_ALL( &linda->write_happened);
@@ -600,7 +600,7 @@ LUAG_FUNC( linda_cancel)
600 } 600 }
601 else if( strcmp( who, "none") == 0) // reset flag 601 else if( strcmp( who, "none") == 0) // reset flag
602 { 602 {
603 linda->simulate_cancel = CANCEL_NONE; 603 linda->simulate_cancel = CancelRequest::None;
604 } 604 }
605 else if( strcmp( who, "read") == 0) // tell blocked readers to wake up 605 else if( strcmp( who, "read") == 0) // tell blocked readers to wake up
606 { 606 {
@@ -802,7 +802,7 @@ static void* linda_id( lua_State* L, DeepOp op_)
802 SIGNAL_INIT( &s->read_happened); 802 SIGNAL_INIT( &s->read_happened);
803 SIGNAL_INIT( &s->write_happened); 803 SIGNAL_INIT( &s->write_happened);
804 s->U = universe_get( L); 804 s->U = universe_get( L);
805 s->simulate_cancel = CANCEL_NONE; 805 s->simulate_cancel = CancelRequest::None;
806 s->group = linda_group << KEEPER_MAGIC_SHIFT; 806 s->group = linda_group << KEEPER_MAGIC_SHIFT;
807 s->name[0] = 0; 807 s->name[0] = 0;
808 memcpy( s->name, linda_name, name_len ? name_len + 1 : 0); 808 memcpy( s->name, linda_name, name_len ? name_len + 1 : 0);