summary refs log tree commit diff
path: root/src/rt/rust_port.h
blob: 3bbc3cfaa32c98535337c9897510bbf52fc15a18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#ifndef RUST_PORT_H
#define RUST_PORT_H

#include "rust_globals.h"
#include "circular_buffer.h"

class port_detach_cond : public rust_cond { };

class rust_port : public kernel_owned<rust_port>, public rust_cond {
private:
    // Protects ref_count and detach_cond
    lock_and_signal ref_lock;
    intptr_t ref_count;
    port_detach_cond detach_cond;

public:
    void ref();
    void deref();

public:
    rust_port_id id;

    rust_kernel *kernel;
    rust_task *task;
    size_t unit_sz;
    circular_buffer buffer;

    lock_and_signal lock;

public:
    rust_port(rust_task *task, size_t unit_sz);
    ~rust_port();

    void log_state();
    void send(void *sptr);
    void receive(void *dptr, uintptr_t *yield);
    size_t size();

    void begin_detach(uintptr_t *yield);
    void end_detach();
};

//
// Local Variables:
// mode: C++
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:
//

#endif /* RUST_PORT_H */