@@ -17,13 +17,18 @@ namespace acto {
17
17
18
18
class actor ;
19
19
20
- // / Use dedicated thread for an actor.
21
- static constexpr uint32_t aoExclusive =0x01 ;
20
+ enum class actor_thread {
21
+ // / Use shared pool of threads for the actor.
22
+ shared,
22
23
23
- // / Привязать актера к текущему системному потоку.
24
- // / Не имеет эффекта, если используется в контексте потока,
25
- // / созданного самой библиотекой.
26
- static constexpr uint32_t aoBindToThread =0x02 ;
24
+ // / Use dedicated thread for the actor.
25
+ exclusive,
26
+
27
+ // / Bind actor to the current thread.
28
+ // / The option will be ignored if used inside the thread created by the
29
+ // / library.
30
+ bind,
31
+ };
27
32
28
33
namespace core {
29
34
@@ -64,7 +69,7 @@ struct object_t : public generics::intrusive_t<object_t> {
64
69
uint32_t unimpl :1 ;
65
70
66
71
public:
67
- object_t (const uint32_t options , std::unique_ptr<actor> body);
72
+ object_t (const actor_thread thread_opt , std::unique_ptr<actor> body);
68
73
69
74
// / Pushes a message into the mailbox.
70
75
void enqueue (std::unique_ptr<msg_t > msg)noexcept ;
@@ -171,10 +176,6 @@ inline void sleep(const D duration) {
171
176
std::this_thread::sleep_for (duration);
172
177
}
173
178
174
- inline void yield () {
175
- std::this_thread::yield ();
176
- }
177
-
178
179
}// namespace core
179
180
180
181
/* *
@@ -410,76 +411,74 @@ class actor {
410
411
bool terminating_{false };
411
412
};
412
413
413
- /* * Destroys the given object.*/
414
- ACTO_APIvoid destroy (actor_ref& object);
415
-
416
- //
417
- ACTO_APIvoid finalize_thread ();
418
-
419
- // Включить в текущем потоке возможность взаимодействия
420
- // с ядром библиотеки acto
421
- ACTO_APIvoid initialize_thread ();
414
+ /* *
415
+ * Destroys the given object.
416
+ */
417
+ void destroy (actor_ref& object);
422
418
423
- /* * Waits until the actor will finish.*/
424
- ACTO_APIvoid join (actor_ref& obj);
419
+ /* *
420
+ * Waits until the actor will finish.
421
+ */
422
+ void join (actor_ref& obj);
425
423
426
424
/* *
427
425
* Processes all messages for objects
428
426
* binded to the current thread (with aoBindToThread option).
429
427
*/
430
- ACTO_APIvoid process_messages ();
431
-
432
- /* * Library shutdown.*/
433
- ACTO_APIvoid shutdown ();
428
+ void process_messages ();
434
429
435
- /* * Library initialization.*/
436
- ACTO_APIvoid startup ();
430
+ /* *
431
+ * Stops all actors.
432
+ */
433
+ void shutdown ();
437
434
438
435
namespace core {
439
436
440
- object_t *make_instance (
441
- actor_ref context,const uint32_t options, std::unique_ptr<actor> body);
437
+ object_t *make_instance (actor_ref context,
438
+ const actor_thread thread_opt,
439
+ std::unique_ptr<actor> body);
442
440
443
441
}// namespace core
444
442
445
443
namespace detail {
446
444
447
445
template <typename Impl>
448
- inline core::object_t *make_instance (
449
- actor_ref context,const uint32_t options, std::unique_ptr<Impl> impl) {
446
+ inline core::object_t *make_instance (actor_ref context,
447
+ const actor_thread thread_opt,
448
+ std::unique_ptr<Impl> impl) {
450
449
static_assert (std::is_base_of<::acto::actor, Impl>::value,
451
450
" implementation should be derived from the acto::actor class" );
452
451
453
- return core::make_instance (std::move (context),options ,std::move (impl));
452
+ return core::make_instance (std::move (context),thread_opt ,std::move (impl));
454
453
}
455
454
456
455
}// namespace detail
457
456
458
457
template <typename T,typename ... P>
459
458
inline actor_refspawn (P&&... p) {
460
- return actor_ref (detail::make_instance<T>(actor_ref (),0 ,
459
+ return actor_ref (detail::make_instance<T>(actor_ref (),actor_thread::shared ,
461
460
std::make_unique<T>(std::forward<P>(p)...)),
462
461
false );
463
462
}
464
463
465
464
template <typename T>
466
465
inline actor_refspawn (actor_ref context) {
467
- return actor_ref (
468
- detail::make_instance<T>( std::move (context), 0 , std::make_unique<T>()),
466
+ return actor_ref (detail::make_instance<T>( std::move (context),
467
+ actor_thread::shared , std::make_unique<T>()),
469
468
false );
470
469
}
471
470
472
471
template <typename T>
473
- inline actor_refspawn (const uint32_t options ) {
472
+ inline actor_refspawn (const actor_thread thread_opt ) {
474
473
return actor_ref (
475
- detail::make_instance<T>(actor_ref (),options , std::make_unique<T>()),
474
+ detail::make_instance<T>(actor_ref (),thread_opt , std::make_unique<T>()),
476
475
false );
477
476
}
478
477
479
478
template <typename T>
480
- inline actor_refspawn (actor_ref context,const uint32_t options ) {
479
+ inline actor_refspawn (actor_ref context,const actor_thread thread_opt ) {
481
480
return actor_ref (detail::make_instance<T>(
482
- std::move (context),options , std::make_unique<T>()),
481
+ std::move (context),thread_opt , std::make_unique<T>()),
483
482
false );
484
483
}
485
484