vfs: check userland buffers before reading them.
[haiku.git] / src / servers / media_addon / SystemTimeSource.cpp
blobbac891a54f2a879dd7a70f21853bead7840632f5
1 /*
2 * Copyright (c) 2003-2004, Marcus Overhagen <marcus@overhagen.de>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #include "debug.h"
26 #include "SystemTimeSource.h"
29 SystemTimeSource::SystemTimeSource()
30 : BMediaNode("System clock"),
31 BTimeSource(),
32 fControlThread(-1)
34 TRACE("SystemTimeSource::SystemTimeSource\n");
37 SystemTimeSource::~SystemTimeSource()
39 TRACE("SystemTimeSource::~SystemTimeSource enter\n");
41 close_port(ControlPort());
42 if (fControlThread != -1) {
43 status_t err;
44 wait_for_thread(fControlThread, &err);
46 TRACE("SystemTimeSource::~SystemTimeSource exit\n");
49 BMediaAddOn*
50 SystemTimeSource::AddOn(int32 * internal_id) const
52 return NULL;
55 status_t
56 SystemTimeSource::TimeSourceOp(const time_source_op_info & op, void * _reserved)
58 TRACE("######## SystemTimeSource::TimeSourceOp\n");
59 bigtime_t real = RealTime();
60 PublishTime(real, real, 1.0);
61 return B_OK;
65 /* virtual */ void
66 SystemTimeSource::NodeRegistered()
68 ASSERT(fControlThread == -1);
69 fControlThread = spawn_thread(_ControlThreadStart, "System clock control", 12, this);
70 resume_thread(fControlThread);
73 int32
74 SystemTimeSource::_ControlThreadStart(void *arg)
76 reinterpret_cast<SystemTimeSource *>(arg)->ControlThread();
77 return 0;
80 void
81 SystemTimeSource::ControlThread()
83 TRACE("SystemTimeSource::ControlThread() enter\n");
84 status_t err;
85 do {
86 err = WaitForMessage(B_INFINITE_TIMEOUT);
87 } while (err == B_OK || err == B_ERROR);
88 TRACE("SystemTimeSource::ControlThread() exit\n");