1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 3DCommit implementation */ 18 19 #include "sles_allinclusive.h" 20 21 22 static SLresult I3DCommit_Commit(SL3DCommitItf self) 23 { 24 SL_ENTER_INTERFACE 25 26 I3DCommit *thiz = (I3DCommit *) self; 27 IObject *thisObject = InterfaceToIObject(thiz); 28 object_lock_exclusive(thisObject); 29 if (thiz->mDeferred) { 30 SLuint32 myGeneration = thiz->mGeneration; 31 do { 32 ++thiz->mWaiting; 33 object_cond_wait(thisObject); 34 } while (thiz->mGeneration == myGeneration); 35 } 36 object_unlock_exclusive(thisObject); 37 result = SL_RESULT_SUCCESS; 38 39 SL_LEAVE_INTERFACE 40 } 41 42 43 static SLresult I3DCommit_SetDeferred(SL3DCommitItf self, SLboolean deferred) 44 { 45 SL_ENTER_INTERFACE 46 47 I3DCommit *thiz = (I3DCommit *) self; 48 IObject *thisObject = InterfaceToIObject(thiz); 49 object_lock_exclusive(thisObject); 50 thiz->mDeferred = SL_BOOLEAN_FALSE != deferred; // normalize 51 object_unlock_exclusive(thisObject); 52 result = SL_RESULT_SUCCESS; 53 54 SL_LEAVE_INTERFACE 55 } 56 57 58 static const struct SL3DCommitItf_ I3DCommit_Itf = { 59 I3DCommit_Commit, 60 I3DCommit_SetDeferred 61 }; 62 63 void I3DCommit_init(void *self) 64 { 65 I3DCommit *thiz = (I3DCommit *) self; 66 thiz->mItf = &I3DCommit_Itf; 67 thiz->mDeferred = SL_BOOLEAN_FALSE; 68 thiz->mGeneration = 0; 69 thiz->mWaiting = 0; 70 } 71